Пример #1
0
        public void OnClientMessage_MessageSendGameRoomTextMessageRequest(int clientID, MessageSendGameRoomTextMessageRequest message, GameRoomManager gameRoomManager, GameClientManager gameClientManager)
        {
            var roomID = gameRoomManager.GetClientRoomID(clientID);

            SendDataToClientsInRoom(roomID, gameRoomManager, gameClientManager, new MessageSendGameRoomTextMessageResponse(clientID, message.TheMessage));
        }
Пример #2
0
        public void OnClientMessage_MessageGetGameRoomsRequest(int clientID, MessageGetGameRoomsRequest message, GameRoomManager gameRoomManager, GameClientManager gameClientManager)
        {
            var gameClient = gameClientManager.GetGameClientFromClientID(clientID);
            var gameRooms  = gameRoomManager.GetGameRooms();

            var lightGameRooms = new List <TCPIPGame.Messages.GameRoom>();

            for (int i = 0; i < gameRooms.Count; i++)
            {
                var roomID   = gameRooms[i].ID;
                var roomName = gameRooms[i].Name;
                lightGameRooms.Add(new TCPIPGame.Messages.GameRoom(roomID, roomName));
            }

            SendDataToClient(gameClient, new MessageGetGameRoomsResponse(lightGameRooms));
        }
Пример #3
0
        public void OnClientMessage_MessageGetGameRoomPlayersRequest(int clientID, MessageGetGameRoomPlayersRequest message, GameRoomManager gameRoomManager, GameClientManager gameClientManager)
        {
            var roomID           = message.RoomID;
            var roomHostClientID = gameRoomManager.GetGameRoomHostClientIDFromGameRoomID(message.RoomID);

            var players       = new List <ANetworkPlayer>();
            var playerManager = new PlayerManager();

            players.Add(playerManager.GeneratePlayerFromClientID(roomHostClientID, message.RoomID, gameClientManager, gameRoomManager)); //the first clientID will be the host


            var clientIDs = gameRoomManager.GetGameClientsInRoom(roomID);

            for (int i = 0; i < clientIDs.Count; i++)
            {
                if (clientIDs[i] != roomHostClientID)
                {
                    players.Add(playerManager.GeneratePlayerFromClientID(clientIDs[i], message.RoomID, gameClientManager, gameRoomManager));
                }
            }

            var messageResponse = new MessageGetGameRoomPlayersResponse(players);
            var gameClient      = gameClientManager.GetGameClientFromClientID(clientID);

            SendDataToClient(gameClient, messageResponse);
        }
Пример #4
0
        public void OnClientMessage_MessageJoinGameRoomRequest(int clientID, MessageJoinGameRoomRequest message, GameRoomManager gameRoomManager, GameClientManager gameClientManager)
        {
            gameRoomManager.AddPlayerToGameRoom(clientID, message.RoomID, 1);

            var clientIDs        = gameRoomManager.GetGameClientsInRoom(message.RoomID);
            var playerThatJoined = new PlayerManager().GeneratePlayerFromClientID(clientID, message.RoomID, gameClientManager, gameRoomManager);
            var theGameClients   = gameClientManager.GetGameClientsFromClientIDs(clientIDs.ToList());

            SendDataToClients(theGameClients, new MessageJoinGameRoomResponse(playerThatJoined));
        }
Пример #5
0
        public void OnClientMessage_MessageGetGameRoomHostRequest(int clientID, MessageGetGameRoomHostRequest message, GameRoomManager gameRoomManager, GameClientManager gameClientManager)
        {
            var roomHostClientID = gameRoomManager.GetGameRoomHostClientIDFromGameRoomID(message.RoomID);
            var client           = gameClientManager.GetGameClientFromClientID(roomHostClientID);
            var gameRoomHost     = new NetworkPlayer(client.ID, client.Name, 0);
            var messageResponse  = new MessageGetGameRoomHostResponse(gameRoomHost);

            var gameClient = gameClientManager.GetGameClientFromClientID(clientID);

            SendDataToClient(gameClient, messageResponse);
        }
Пример #6
0
        public void OnClientMessage_MessageCreateRoomRequest(int clientID, MessageCreateRoomRequest message, GameRoomManager gameRoomManager, GameClientManager gameClientManager)
        {
            var gameClient   = gameClientManager.GetGameClientFromClientID(clientID);
            var gameRoomHost = new NetworkPlayer(gameClient.ID, gameClient.Name, 0);
            var roomID       = gameRoomManager.CreateRoom(2, message.RoomName, clientID);

            gameRoomManager.AddPlayerToGameRoom(clientID, roomID, 0, true);
            var messageResponse = new MessageCreateRoomResponse(message.RoomName, roomID, gameRoomHost);

            SendDataToClient(gameClient, messageResponse);
        }
Пример #7
0
        public void SendDataToClientsInRoom(int roomID, GameRoomManager gameRoomManager, GameClientManager gameClientManager, byte[] data)
        {
            var clientIDs      = gameRoomManager.GetGameClientsInRoom(roomID);
            var theGameClients = gameClientManager.GetGameClientsFromClientIDs(clientIDs.ToList());

            SendDataToClients(theGameClients, data);
        }
Пример #8
0
        public void OnClientMessage_MessageLowLevelMessageRequest(int clientID, byte[] message, GameRoomManager gameRoomManager, GameClientManager gameClientManager)
        {
            var roomID = gameRoomManager.GetClientRoomID(clientID);

            SendDataToClientsInRoom(roomID, gameRoomManager, gameClientManager, message);
        }
Пример #9
0
        public void OnClientMessage_MessageConnectToServerRequest(int clientID, MessageConnectToServerRequest message, GameRoomManager gameRoomManager, GameClientManager gameClientManager)
        {
            var gameClient = gameClientManager.GetGameClientFromClientID(clientID);

            gameClient.Name = message.Name;
            var messageResponseWithClientID = new MessageConnectToServerResponse(clientID, message.Name);

            SendDataToClient(gameClient, messageResponseWithClientID);
        }