示例#1
0
        private void StartGame(MessageToClient msg)
        {
            HFTMessageGameStart data = m_deserializer.Deserialize <HFTMessageGameStart>(msg.data);

            m_id = data.id;
            QueueEvent(() =>
            {
                var handler = OnConnect;
                if (handler != null)
                {
                    handler();
                }
            });
        }
示例#2
0
        public void AssignClient(HFTSocket client, HFTRuntimeOptions data)
        {
            if (client_ != null)
            {
                log_.Error("this game already has a client!");
                client_.OnMessageEvent -= OnMessage;
                client_.OnCloseEvent   -= OnDisconnect;
                client_.Close();
            }

            client_ = client;

            client.OnMessageEvent += OnMessage;
            client.OnCloseEvent   += OnDisconnect;

            RegisterCmdHandler <object>("client", SendMessageToPlayer);
            RegisterCmdHandler <object>("broadcast", Broadcast);
            RegisterCmdHandler <HFTMessageSwitchGame>("switchGame", SwitchGame);
            RegisterCmdHandler <object>("peer", SendMessageToGame);
            RegisterCmdHandler <object>("bcastToGames", BroadcastToGames);
            RegisterCmdHandler <HFTMessageAddFile>("addFile", AddFile);

            // Tell the game it's id
            var gs = new HFTMessageGameStart();

            gs.id     = id_;
            gs.gameId = ""; //FIX!
            client.Send(new HFTRelayToGameMessage("gamestart", "", gs));

            // start each player
            foreach (var player in players_.Values)
            {
                client.Send(new HFTRelayToGameMessage("start", player.id, null));
            }

            // Not sure why I even have a sendQueue
            // as the game should be running before anyone
            // joins but it seems to be useful for debugging
            // since contollers start and often immediately
            // send a name and color cmd.
            foreach (var pair in sendQueue_.ToArray())
            {
                client.Send(pair.Value);
            }
            sendQueue_.Clear();
        }