public void SendUnparsedEvent(Dictionary <string, object> data) { // 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_handlers.Count == 0) { m_server.QueueEvent(delegate() { SendUnparsedEvent(data); }); return; } try { MessageCmd cmd = m_deserializer.Deserialize <MessageCmd>(data); CmdEventHandler handler; if (!m_handlers.TryGetValue(cmd.cmd, out handler)) { Debug.LogError("unhandled NetPlayer cmd: " + cmd.cmd); return; } handler(m_server, cmd.data); } catch (Exception ex) { Debug.LogException(ex); } }
public void SendCmd(MessageCmdData data) // Make it Ob's name is the message. { string name = MessageCmdDataNameDB.GetCmdName(data.GetType()); MessageCmd msgCmd = new MessageCmd(name, data); m_server.SendCmd("client", m_id, msgCmd); }