/// <summary>Tells a client to spawn a player.</summary> /// <param name="_toClient">The client that should spawn the player.</param> /// <param name="_cursor">The player to spawn.</param> public static void SpawnCursor(int _toClient, ServerCursor _cursor) { using (Packet _packet = new Packet((int)ServerPackets.spawnCursor)) { _packet.Write(_cursor.id); _packet.Write(_cursor.username); _packet.Write(_cursor.transform.position); _packet.Write(_cursor.transform.rotation); _packet.Write(_cursor.cursorColor); //Debug.Log("Sending the color"); //Debug.Log(_cursor.cursorColor); int pillColor = Random.Range(0, 2); //Debug.Log(pillColor); if (pillColor == 0) { _packet.Write(_cursor.pill1Color); _packet.Write(_cursor.pill2Color); } else if (pillColor == 1) { _packet.Write(_cursor.pill2Color); _packet.Write(_cursor.pill1Color); } SendTCPData(_toClient, _packet); } }
/// <summary>Sends the client into the game and informs other clients of the new player.</summary> /// <param name="_playerName">The username of the new player.</param> public void SendIntoGame(string _playerName) { cursor = NetworkManager.instance.InstantiatePlayer(); cup = cursor.GetComponent <ServerCup>(); cursor.Initialize(id, _playerName, NetworkManager.instance.playerColors[id - 1], NetworkManager.instance.pill1Colors[id - 1], NetworkManager.instance.pill2Colors[id - 1]); // Send all players to the new player foreach (ServerClient _client in Server.clients.Values) { if (_client.cursor != null) { if (_client.id != id) { ServerSend.SpawnCursor(id, _client.cursor); } } } // Send the new player to all players (including himself) foreach (ServerClient _client in Server.clients.Values) { if (_client.cursor != null) { ServerSend.SpawnCursor(_client.id, cursor); } } }
public static void PlayerDisconnect(int _toClient, ServerCursor _cursor) { using (Packet _packet = new Packet((int)ServerPackets.playerDisconnect)) { _packet.Write(_cursor.id); SendTCPDataToAll(_cursor.id, _packet); } }
public static void ReceivePill(ServerCursor _cursor, Pill _pill) { using (Packet _packet = new Packet((int)ServerPackets.receivePill)) { _packet.Write(_cursor.id); _packet.Write(_pill); SendTCPDataToAll(_packet); } }
public static void BeginSection(ServerCursor _cursor, Goal g1, Goal g2) { using (Packet _packet = new Packet((int)ServerPackets.beginSection)) { _packet.Write(g1); _packet.Write(g2); //Add all cups to cup manager for each player SendTCPData(_cursor.id, _packet); } }
/// <summary>Sends a player's updated position to all clients.</summary> /// <param name="_player">The player whose position to update.</param> public static void CursorPosition(ServerCursor _cursor) { using (Packet _packet = new Packet((int)ServerPackets.playerPosition)) { _packet.Write(_cursor.id); _packet.Write(_cursor.cursorPos); SendUDPDataToAll(_cursor.id, _packet); } }
//returns previously locked shape, caller should broadcast cursor free event if result != null public void LockShape(IServerVdShape sh, int owner) { if (sh.GetCursor() != null) { throw new InvalidOperationException("cannot lock locked shape"); } var cursor = new ServerCursor(owner); sh.SetCursor(cursor); _userIdToCursor.Add(owner, sh); }
/// <summary>Disconnects the client and stops all network traffic.</summary> private void Disconnect() { Debug.Log($"{tcp.socket.Client.RemoteEndPoint} has disconnected."); //Debug.Log(Environment.StackTrace); ServerSend.PlayerDisconnect(id, cursor); NetworkManager.instance.Disconnect(id); ThreadManager.ExecuteOnMainThread(() => { UnityEngine.Object.Destroy(cursor.gameObject); cursor = null; }); tcp.Disconnect(); udp.Disconnect(); }
public void UnsetCursor() { _cursor = null; }
public void SetCursor(ServerCursor c) { _cursor = c; }