public void SendEvent(string cmd, object data) { HFTMessageCmd msgCmd = new HFTMessageCmd(cmd, data); string json = Serializer.Serialize(msgCmd); Dictionary <string, object> dict = base.Deserializer.Deserialize <Dictionary <string, object> >(json); SendUnparsedEvent(dict); }
public void SendUnparsedEvent(object data) { if (!m_connected) { return; } // This is kind of round about. The issue is we queue message // if there are no handlers as that means no one has had time // to register any and those message will be lost. // // That's great but we can also call RemoveAllHanders. PlayerConnector // does this. Players that are waiting have all messages disconnected. // That means if they are waiting for 2-3 mins, with a poorly designed // controller there could be tons of messages queued up. // // So, only allow queuing messages once. After that they're never // queued. if (m_handlers.Count > 0) { m_haveHandlers = true; } // If there are no handlers registered then the object using this NetPlayer // has not been instantiated yet. The issue is the GameSever makes a NetPlayer. // It then has to queue an event to start that player so that it can be started // on another thread. But, before that event has triggered other messages might // come through. So, if there are no handlers then we add an event to run the // command later. It's the same queue that will birth the object that needs the // message. if (!m_haveHandlers) { m_server.QueueEvent(() => { SendUnparsedEvent(data); }); return; } try { HFTMessageCmd cmd = m_deserializer.Deserialize <HFTMessageCmd>(data); CmdEventHandler handler; if (!m_handlers.TryGetValue(cmd.cmd, out handler)) { if (!m_internalHandlers.TryGetValue(cmd.cmd, out handler)) { m_log.Error("unhandled NetPlayer cmd: " + cmd.cmd); return; } } handler(m_deserializer, m_server, cmd.data); } catch (Exception ex) { m_log.Error(ex); } }
private void UpdateGame(MessageToClient msg) { try { HFTMessageCmd cmd = m_deserializer.Deserialize <HFTMessageCmd>(msg.data); CmdEventHandler handler; if (!m_handlers.TryGetValue(cmd.cmd, out handler)) { m_log.Error("unhandled GameServer cmd: " + cmd.cmd); return; } handler(m_deserializer, this, cmd.data, msg.id); } catch (Exception ex) { m_log.Error(ex); } }
// Only NetPlayer should call this. public void SendCmd(string cmd, string name, object data, string id = "-1") { HFTMessageCmd msgCmd = new HFTMessageCmd(name, data); SendSysCmd(cmd, id, msgCmd); }