Changeset 154 for binary-improvements/7dtd-server-fixes/src
- Timestamp:
- Sep 2, 2014, 9:32:25 PM (10 years ago)
- Location:
- binary-improvements/7dtd-server-fixes/src
- Files:
-
- 12 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/PathHandler.cs
r134 r154 6 6 public abstract class PathHandler 7 7 { 8 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user);8 public abstract void HandleRequest (HttpListenerRequest req, HttpListenerResponse resp, HttpListenerBasicIdentity user); 9 9 } 10 10 } -
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/StaticHandler.cs
r138 r154 34 34 if (!fileCache.ContainsKey (fn)) { 35 35 if (!File.Exists (datapath + "/" + fn)) { 36 resp.StatusCode = (int)HttpStatusCode.NotFound; 37 if (logMissingFiles) 38 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + fn + "\""); 39 return; 36 throw new FileNotFoundException (); 40 37 } 41 38 … … 49 46 } else { 50 47 if (!File.Exists (datapath + "/" + fn)) { 51 resp.StatusCode = (int)HttpStatusCode.NotFound; 52 if (logMissingFiles) 53 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + fn + "\""); 54 return; 48 throw new FileNotFoundException (); 55 49 } 56 50 … … 61 55 resp.ContentLength64 = content.Length; 62 56 resp.OutputStream.Write (content, 0, content.Length); 57 } catch (FileNotFoundException e) { 58 resp.StatusCode = (int)HttpStatusCode.NotFound; 59 if (logMissingFiles) 60 Log.Out ("Web:Static:FileNotFound: \"" + req.Url.AbsolutePath + "\" @ \"" + datapath + "/" + req.Url.AbsolutePath.Remove (0, staticPart.Length) + "\""); 61 return; 63 62 } catch (Exception e) { 64 63 Log.Out ("Error in StaticHandler.HandleRequest: " + e); -
binary-improvements/7dtd-server-fixes/src/NetConnections/Servers/Web/Web.cs
r151 r154 19 19 throw new NotSupportedException ("Needs Windows XP SP2, Server 2003 or later."); 20 20 21 handlers.Add ("/index. ", new SimpleRedirectHandler ("/static/index.html"));21 handlers.Add ("/index.htm", new SimpleRedirectHandler ("/static/index.html")); 22 22 handlers.Add ("/static/", new StaticHandler ("/static/", Application.dataPath + "/../webserver", false/*true*/, true)); // TODO: Enable cache 23 23 handlers.Add ("/map/", new StaticHandler ("/map/", StaticDirectories.GetSaveGameDir () + "/map", false, false)); 24 handlers.Add ("/api/", new ApiHandler ("/api/")); 24 25 25 26 _listener.Prefixes.Add (String.Format ("http://*:{0}/", port)); … … 53 54 ctx.Response.ProtocolVersion = new Version ("1.1"); 54 55 55 HttpListenerBasicIdentity user ;56 HttpListenerBasicIdentity user = Authorize (ctx); 56 57 57 if (Authorize (ctx, out user)) { 58 if (ctx.Request.Url.AbsolutePath.Length < 2) { 59 handlers ["/index."].HandleRequest (ctx.Request, ctx.Response, user); 60 return; 61 } else { 62 foreach (KeyValuePair<string, PathHandler> kvp in handlers) { 63 if (ctx.Request.Url.AbsolutePath.StartsWith (kvp.Key)) { 64 kvp.Value.HandleRequest (ctx.Request, ctx.Response, user); 65 return; 66 } 58 if (ctx.Request.Url.AbsolutePath.Length < 2) { 59 handlers ["/index.htm"].HandleRequest (ctx.Request, ctx.Response, user); 60 return; 61 } else { 62 foreach (KeyValuePair<string, PathHandler> kvp in handlers) { 63 if (ctx.Request.Url.AbsolutePath.StartsWith (kvp.Key)) { 64 kvp.Value.HandleRequest (ctx.Request, ctx.Response, user); 65 return; 67 66 } 68 67 } 68 } 69 69 70 Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + ctx.Request.Url.AbsolutePath + "\""); 71 ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; 72 } else { 73 ctx.Response.StatusCode = (int)HttpStatusCode.Unauthorized; 74 ctx.Response.AddHeader("WWW-Authenticate", "Basic realm=\"\""); 75 } 70 Log.Out ("Error in Web.HandleRequest(): No handler found for path \"" + ctx.Request.Url.AbsolutePath + "\""); 71 ctx.Response.StatusCode = (int)HttpStatusCode.NotFound; 76 72 77 73 // byte[] buf = Encoding.UTF8.GetBytes ("Hello World"); … … 87 83 } 88 84 89 private bool Authorize (HttpListenerContext ctx, out HttpListenerBasicIdentity user)85 private HttpListenerBasicIdentity Authorize (HttpListenerContext ctx) 90 86 { 91 user = null;92 return true;93 87 try { 94 user = (HttpListenerBasicIdentity)ctx.User.Identity; 95 return user.Name.Equals ("admin") && user.Password.Equals (GamePrefs.GetString (EnumGamePrefs.ControlPanelPassword)); 88 return (HttpListenerBasicIdentity)ctx.User.Identity; 96 89 } catch (NullReferenceException) { 97 user = null; 98 return false; 90 return null; 99 91 } 100 92 } -
binary-improvements/7dtd-server-fixes/src/PersistentData/Player.cs
r146 r154 17 17 lastOnline; 18 18 private Inventory inventory; 19 [OptionalField] 20 private int 21 lastPositionX, lastPositionY, lastPositionZ; 19 22 [NonSerialized] 20 23 private ClientInfo … … 82 85 } 83 86 87 public Vector3i LastPosition { 88 get { 89 if (IsOnline) 90 return new Vector3i (Entity.GetPosition ()); 91 else 92 return new Vector3i (lastPositionX, lastPositionY, lastPositionZ); 93 } 94 } 95 84 96 public void SetOffline () 85 97 { 86 98 Log.Out ("Player set to offline: " + steamId); 99 Vector3i lastPos = new Vector3i (Entity.GetPosition ()); 100 lastPositionX = lastPos.x; 101 lastPositionY = lastPos.y; 102 lastPositionZ = lastPos.z; 87 103 totalPlayTime += (long)(Time.timeSinceLevelLoad - Entity.CreationTimeSinceLevelLoad); 88 104 lastOnline = DateTime.Now;
Note:
See TracChangeset
for help on using the changeset viewer.