Esempio n. 1
0
        public void SendMoveCommand(CellCoord moveCoord)
        {
            ServerCommand command = new ServerCommand(CommandType.MOVE)
            {
                MoveCoord = moveCoord
            };

            SendCommand(command);
        }
Esempio n. 2
0
        public void SendStartCommand(string opponentName)
        {
            ServerCommand command = new ServerCommand(CommandType.START)
            {
                IsX          = this.IsX,
                OpponentName = opponentName
            };

            SendCommand(command);
        }
Esempio n. 3
0
        public void SendLoseCommand(string opponentName)
        {
            ServerCommand command = new ServerCommand(CommandType.LOSE)
            {
                OpponentName = opponentName
            };


            SendCommand(command);
        }
Esempio n. 4
0
        private void ReadServerCommands()
        {
            Console.WriteLine("");
            DisplayHelpCommands();
            Console.Write("$> ");
            var line = Console.ReadLine();

            while (line != null && read)
            {
                ServerCommand.ExecuteCommand(line, Table, this);
                Console.Write("$> ");
                line = Console.ReadLine();
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Sends a ServerCommand to a client from connectClients.
        /// </summary>
        /// <param name="pID">ID of the client.</param>
        /// <param name="cmd">Command to send.</param>
        public async Task SendServerCommandAsync(int pID, ServerCommand cmd)
        {
            if (connectedClients.TryGetValue(pID, out ConnectedClient client))
            {
                if (cmd.guaranteedExec)
                {
                    var bytes = Serialization.PrependInt(new CmdServerUpdate(cmd).Encode(), client.lastPolledCUpdate);
                    await Task.Delay(sendDelay);

                    await Communication.TCPSendMessageAsync(client.relUpdateSocket, bytes);
                }
                else
                {
                    var bytes = Serialization.PrependInt(cmd.Encode(), client.lastPolledCUpdate);
                    if (random.NextDouble() < packetLoss)
                    {
                        return;
                    }
                    await Task.Delay(sendDelay);

                    await Communication.UDPSendMessageAsync(serverCommandsSender, client.updateAddress, bytes);
                }
            }
        }
Esempio n. 6
0
        // метод для відправки об'єкту команди
        private void SendCommand(ServerCommand command)
        {
            BinaryFormatter formatter = new BinaryFormatter();

            formatter.Serialize(TcpClient.GetStream(), command);
        }
Esempio n. 7
0
        public void SendDrawCommand()
        {
            ServerCommand command = new ServerCommand(CommandType.DRAW);

            SendCommand(command);
        }