diff options
| author | Michael <[email protected]> | 2017-05-20 08:40:26 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-05-20 08:40:26 -0400 |
| commit | 038c819046ebbe64d6200bae2517407912642223 (patch) | |
| tree | 252a63421004bd95457567107dd0e67e1d96b937 | |
| parent | a1fa66f787a9298a67ab824303fd70f2b1bc5f79 (diff) | |
| download | shiftos_thereturn-038c819046ebbe64d6200bae2517407912642223.tar.gz shiftos_thereturn-038c819046ebbe64d6200bae2517407912642223.tar.bz2 shiftos_thereturn-038c819046ebbe64d6200bae2517407912642223.zip | |
document servermanager
| -rw-r--r-- | ShiftOS_TheReturn/ServerManager.cs | 80 |
1 files changed, 54 insertions, 26 deletions
diff --git a/ShiftOS_TheReturn/ServerManager.cs b/ShiftOS_TheReturn/ServerManager.cs index 371d8e7..95e86e9 100644 --- a/ShiftOS_TheReturn/ServerManager.cs +++ b/ShiftOS_TheReturn/ServerManager.cs @@ -39,28 +39,50 @@ using System.Diagnostics; namespace ShiftOS.Engine { + /// <summary> + /// Digital Society connection management class. + /// </summary> public static class ServerManager { + /// <summary> + /// Print connection diagnostic information. + /// </summary> public static void PrintDiagnostics() { Console.WriteLine($@"{{CLIENT_DIAGNOSTICS}} {{GUID}}: {thisGuid} +Ping: {ServerManager.DigitalSocietyPing} ms {{CLIENT_DATA}}: {JsonConvert.SerializeObject(client, Formatting.Indented)}"); } + /// <summary> + /// Gets the unique identifier for this Digital Society connection. This can be used for peer-to-peer communication between two clients. + /// </summary> public static Guid thisGuid { get; private set; } - private static NetObjectClient client { get; set; } + + /// <summary> + /// Gets the underlying NetSockets client for this connection. + /// </summary> + public static NetObjectClient client { get; private set; } + + private static bool UserDisconnect = false; + /// <summary> + /// Gets or sets the server response time for the last request made by this client. + /// </summary> public static long DigitalSocietyPing { get; private set; } + /// <summary> + /// Disconnect from the digital society intentionally. + /// </summary> public static void Disconnect() { UserDisconnect = true; @@ -72,36 +94,20 @@ namespace ShiftOS.Engine } + /// <summary> + /// Occurs when you are disconnected from the Digital Society. + /// </summary> public static event EmptyEventHandler Disconnected; - - public static void InitiateMUDHack() - { - MessageReceived += ServerManager_MessageReceived; - SendMessage("mudhack_init", ""); - } - public static event Action<string> ServerPasswordGenerated; - public static event EmptyEventHandler ServerAccessGranted; - public static event EmptyEventHandler ServerAccessDenied; + /// <summary> + /// Occurs when the unique ID for this client is sent by the server. + /// </summary> public static event Action<string> GUIDReceived; - public static event Action<List<OnlineUser>> UsersReceived; private static void ServerManager_MessageReceived(ServerMessage msg) { switch(msg.Name) { - case "mudhack_users": - UsersReceived?.Invoke(JsonConvert.DeserializeObject<List<OnlineUser>>(msg.Contents)); - break; - case "mudhack_init": - ServerPasswordGenerated?.Invoke(msg.Contents); - break; - case "mudhack_denied": - ServerAccessDenied?.Invoke(); - break; - case "mudhack_granted": - ServerAccessGranted?.Invoke(); - break; case "getguid_fromserver": if(SaveSystem.CurrentSave.Username == msg.Contents) { @@ -124,6 +130,11 @@ namespace ShiftOS.Engine MessageReceived -= new ServerMessageReceived(ServerManager_MessageReceived); } + /// <summary> + /// Initiate a new Digital Society connection. + /// </summary> + /// <param name="mud_address">The IP address or hostname of the target server</param> + /// <param name="port">The target port.</param> public static void Initiate(string mud_address, int port) { client = new NetObjectClient(); @@ -222,6 +233,11 @@ namespace ShiftOS.Engine private static Stopwatch PingTimer = new Stopwatch(); + /// <summary> + /// Send a message to the server. + /// </summary> + /// <param name="name">The message name</param> + /// <param name="contents">The message body</param> public static void SendMessage(string name, string contents) { var sMsg = new ServerMessage @@ -255,21 +271,33 @@ namespace ShiftOS.Engine } - + /// <summary> + /// Occurs when the server sends a message to this client. + /// </summary> public static event ServerMessageReceived MessageReceived; - public static void Forward(string targetGUID, string v, string message) + /// <summary> + /// Send a message to another client. + /// </summary> + /// <param name="targetGUID">The target client GUID.</param> + /// <param name="title">The message title</param> + /// <param name="message">The message contents</param> + public static void Forward(string targetGUID, string title, string message) { var smsg = new ServerMessage { GUID = targetGUID, - Name = v, + Name = title, Contents = message }; ServerManager.SendMessage("mud_forward", JsonConvert.SerializeObject(smsg)); } } + /// <summary> + /// Delegate for handling server messages + /// </summary> + /// <param name="msg">A server message containing the protocol message name, GUID of the sender, and the contents of the message.</param> public delegate void ServerMessageReceived(ServerMessage msg); public class MultiplayerOnlyAttribute : Attribute |
