public override void Close() { if (!_open) { return; } _open = false; if (_socket != null) { try { _socket.Close(); } catch { } } base.Close(); }
/// <summary> /// Main listner loop. Keeps an open stream between the client and server while /// the client is logged in / playing /// </summary> private void OnDataReceived(TCPStream stream, string message) { if (stream != Stream) { return; } // Read client message, and parse it into key value pairs string[] recieved = message.TrimStart('\\').Split('\\'); switch (recieved[0]) { case "inviteto": AddProducts(PresenceServer.ConvertToKeyValue(recieved)); break; case "newuser": CreateNewUser(PresenceServer.ConvertToKeyValue(recieved)); break; case "login": ProcessLogin(PresenceServer.ConvertToKeyValue(recieved)); break; case "getprofile": SendProfile(PresenceServer.ConvertToKeyValue(recieved)); break; case "updatepro": UpdateUser(PresenceServer.ConvertToKeyValue(recieved)); break; case "logout": Disconnect(DisconnectReason.NormalLogout); break; case "status": UpdateStatus(PresenceServer.ConvertToKeyValue(recieved)); break; case "ka": SendKeepAlive(); break; default: LogWriter.Log.Write("Received unknown request " + recieved[0], LogLevel.Debug); PresenceServer.SendError(stream, 0, "An invalid request was sended."); stream.Close(); break; } }
/// <summary> /// This function sended the error to a stream and release it /// </summary> /// <param name="stream">The stream that will receive the error</param> /// <param name="code">The error code</param> /// <param name="error">A string containing the error</param> protected void SendErrorAndFreeStream(TCPStream stream, int code, string error) { SendError(stream, code, error); stream.Close(); Release(stream); }