private void InvalidCommand(Socket socket, string cmd) { DebugUtilities.Log( msg: UCCommand.InvalidCmd + " {" + cmd + "}", type: LogType.Error ); NetworkUtilities.Send(socket, UCCommand.InvalidCmd); }
/* Error handling */ private void PlayerNotFound(Socket socket, int playerId) { DebugUtilities.Log( msg: UCCommand.PlayerNotFound + " {" + UCCommand.PlayerId + playerId + "}", type: LogType.Error ); NetworkUtilities.Send(socket, UCCommand.PlayerNotFound); }
/* Command handling */ private void RegisterClient(Socket socket, string playerName) { for (int i = 0; i < clients.Length; i++) { if (clients[i] == null) { clients[i] = socket; cmdHandler.Register(i, playerName); // Replies player ID // example - PLAYER_ID:1 SendMsg(i, UCCommand.PlayerId + i); DebugUtilities.Log(playerName + "registered with player ID " + i); return; } } DebugUtilities.Log("Unable to register player " + playerName + ". Maximum player numbers reached."); NetworkUtilities.Send(socket, UCCommand.ServerFull); }
/// <summary> /// Send message to a connected player. /// </summary> /// <param name="targetPlayer">ID of the selected player /// which uses to get the related socket.</param> /// <param name="msg">String that needs to be sent to /// the player.</param> public void SendMsg(int targetPlayer, string msg) { NetworkUtilities.Send(clients[targetPlayer], msg); }