Esempio n. 1
0
    public void listenForClientMsg(NetworkMessage msg)
    {
        ConnectedClient c = GameRoomClients.getMatchingClient(msg.conn);

        CommProtocol.AlbotHandler h = currentHandlers.Find(x => x.msgType == msg.msgType);

        //There should be someway to do this with generics and without reflection right?
        try{
            byte[] bytes  = msg.reader.ReadBytesAndSize();
            object objMsg = null;

            if (h.type == typeof(CommProtocol.StringMessage))
            {
                objMsg = Game.ClientController.Deserialize <CommProtocol.StringMessage> (bytes);
            }
            if (h.type == typeof(Soldiers.PlayerCommands))
            {
                objMsg = Game.ClientController.Deserialize <Soldiers.PlayerCommands> (bytes);
            }
            if (h.type == typeof(Bomberman.PlayerCommand))
            {
                objMsg = Game.ClientController.Deserialize <Bomberman.PlayerCommand> (bytes);
            }
            if (h.type == typeof(Snake.GameCommand))
            {
                objMsg = Game.ClientController.Deserialize <Snake.GameCommand> (bytes);
            }

            h.func(objMsg, c);
        }
        catch {}
    }
Esempio n. 2
0
    public void registerHandler(CommProtocol.AlbotHandler newHandler, int playerID)
    {
        ConnectedClient c = GameRoomClients.getMatchingClient(playerID);

        c.conn.RegisterHandler(newHandler.msgType, listenForClientMsg);
        currentHandlers.Add(newHandler);
    }