public static void FreeSafe(ClientToServerMessage msg) { safePool.Free(msg); }
/// <summary> /// Sends a message to the connected server. This message will be returned to the message pool after sending so the caller must not free the message. /// </summary> /// <param name="msg"></param> /// <returns></returns> public bool SendMessage(ClientToServerMessage msg) { if (!isConnected) return false; lock (sendingQ) { sendingQ.Enqueue(msg); newDataArrivedEvent.Set(); } return true; }
public void ProcessMessage(ClientToServerMessage msg) { Character character = context.Mpt.GetCharacterByCharacterId(msg.CharacterId); if (character != null) { try { ChatType type = (ChatType)Convert.ToInt32(msg.Data.Split('|')[0]); int dest = Convert.ToInt32(msg.Data.Split('|')[1]); string text = msg.GameData; ChatMessage message = new ChatMessage(character, type, dest, text); if (text.StartsWith("/")) HandleCommand(message); else HandleChat(message); } catch (Exception e) { // Client possibly tampered with chat protocol. Logger.Output(this, "Chat process error: {0}, {1}.", e.Message, e.StackTrace); } } else { // Invalid char ID should never get this far.. but log it anyway. Logger.Output(this, "Chat process found unknown character ID {0}.", msg.CharacterId); } }
/// <summary> /// Sends a ClientToServerMessage to the server. /// Note: the message is expected to be formatted properly and inclue necessary data. /// </summary> public void SendMessage(ClientToServerMessage pm) { if (connection.State != WorldConnection.WorldConnectionState.Disconnected) { Logger.Output(this, "Sending standalone message: {0}", pm.MessageType); connection.WorldClient.SendMessage(pm); } }
public bool AuthenticatePlayer(ClientToServerMessage msg) { try { // We only accept Authenticate if (msg.MessageType != MessageType.C2S_Authenticate) { Disconnect(msg.Sender, "Unexpected message", 5000); return false; } // Verify account / password if (msg.AccountId > 0) { // Find MPR entry MasterPlayerRecord mpr = GetByEndPoint(msg.Sender.RemoteEndpoint); if (mpr == null) { string message = String.Format("No MPR for endpoint: {0} exists!", msg.Sender.RemoteEndpoint); Disconnect(msg.Sender, message, 5000); } // Check authentication string otp = msg.Data; bool isAuthenticationOK = false; lock(otpLocker) { isAuthenticationOK = (oneTimePad.ContainsKey(otp) && otp.EndsWith(msg.AccountId.ToString()) && otp.StartsWith(msg.Sender.RemoteEndpoint.Address.ToString())) || (otp == "admin_testing"); if(isAuthenticationOK) oneTimePad.Remove(msg.Data); } if(isAuthenticationOK) Logger.Output(this, "Authenticate() Valid secret: '{0}' received from player: {1}, endpoint: {2}", otp, msg.AccountId, msg.Sender.RemoteEndpoint.Address); else { Logger.Output(this, "Authenticate() Invalid secret: '{0}' received from player: {1}, endpoint: {2}", otp, msg.AccountId, msg.Sender.RemoteEndpoint.Address); Disconnect(msg.Sender, "Not authorized", 5000); return false; } // Since authenticate is the very first message from a client store it's accountId mpr.State = ClientState.CharacterManagement; UpdateAccountId(msg.Sender.RemoteEndpoint, msg.AccountId); return true; } else { Logger.Output(this, "Authenticate() Invalid accountID: '{0}' received from endpoint: {1}", msg.AccountId, msg.Sender.RemoteEndpoint.Address); Disconnect(msg.Sender, "Not authorized, wrong account ID.", 5000); return false; } } catch(Exception ex) { Logger.Output(this, "Authenticate() Exception: {0}", ex.Message); } return false; }
private void btnQuit_Click(object sender, EventArgs e) { if (conn.State == WorldConnection.WorldConnectionState.InGame) { ClientToServerMessage pm = new ClientToServerMessage(); pm.MessageType = MessageType.C2S_PlayerLogoutRequest; pm.Action = (int)PlayerAction.None; pm.AccountId = conn.AccountId; pm.CharacterId = conn.CharacterId; pm.DeliveryMethod = NetDeliveryMethod.ReliableUnordered; conn.WorldClient.SendMessage(pm); } }