public void SendMoveCommand(CellCoord moveCoord) { ServerCommand command = new ServerCommand(CommandType.MOVE) { MoveCoord = moveCoord }; SendCommand(command); }
public void SendStartCommand(string opponentName) { ServerCommand command = new ServerCommand(CommandType.START) { IsX = this.IsX, OpponentName = opponentName }; SendCommand(command); }
public void SendLoseCommand(string opponentName) { ServerCommand command = new ServerCommand(CommandType.LOSE) { OpponentName = opponentName }; SendCommand(command); }
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(); } }
/// <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); } } }
// метод для відправки об'єкту команди private void SendCommand(ServerCommand command) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(TcpClient.GetStream(), command); }
public void SendDrawCommand() { ServerCommand command = new ServerCommand(CommandType.DRAW); SendCommand(command); }