Beispiel #1
0
        /*
         *  The following method creates a game and sends the corresponding messages
         *  the serverclients.
         */
        public void createGame(ServerClient client1, ServerClient client2)
        {
            Game game = new Game(client1, client2);

            client1.Send(Server.inGameCode, "X" + this.IDandUsername[client2.getID()]);
            client2.Send(Server.inGameCode, "O" + this.IDandUsername[client1.getID()]);

            client1.setGame(game);
            client2.setGame(game);

            Thread.Sleep(500);

            client1.Send(Server.turnCode, "true");
            client2.Send(Server.turnCode, "false");
        }
Beispiel #2
0
        /*
         *  The following method sends a message to all clients but also makes sure
         *  the message is not sent to the serverclient it came from.
         */
        public void SendToAllClients(string message, ServerClient serverClient)
        {
            string key      = serverClient.getID();
            string username = IDandUsername[key];

            string messageToSend = "[" + username + "]: " + message;

            addChatlog(messageToSend);

            Console.WriteLine(messageToSend);

            foreach (ServerClient client in this.clients)
            {
                if (serverClient != client)
                {
                    client.Send(Server.chatmessageCode, messageToSend);
                }
            }
        }