/// <summary> /// Sends the specified payload over TCP to the specified client. /// </summary> public static void SendTcp(INetworkServerClient recipient, TcpPacketType type, Action <BitBuffer> payloadWriter) { _server?.SendTcp(((NetworkServerClient)recipient).DoubleClient, buffer => { buffer.Write((byte)type); payloadWriter(buffer); }); }
private void ServerOnClientConnected(INetworkServerClient client) { Debug.Log("Client connected: " + client.Id); CreateStructure(client.Id); NetworkServer.SendTcpToAll(client.Id, TcpPacketType.Server_State_Joined, buffer => buffer.Write(client.Id)); if (NetworkServer.ClientCount > 0) { NetworkServer.SendTcp(client, TcpPacketType.Server_State_Joined, buffer => NetworkServer.ForEachClient(client.Id, other => buffer.Write(other.Id))); } }
private static void ServerOnClientConnected(INetworkServerClient client) { Debug.Log("Client connected: " + client.Id); if (NetworkServer.ClientCount == 0) { return; } NetworkServer.SendTcp(client, TcpPacketType.Server_State_Joined, buff => NetworkServer.ForEachClient(other => other != client && PlayerStructures.ContainsKey(other.Id), other => { buff.Write(other.Id); byte[] structure = PlayerStructures[other.Id]; buff.Write(structure.Length); buff.Write(structure); })); }
private static void OnClientJoin(INetworkServerClient client, BitBuffer buffer) { if (PlayerStructures.ContainsKey(client.Id)) { return; //TODO invalid packet } byte[] structure = buffer.ReadBytes(); //TODO validate structure: deserialize into EditableStructure PlayerStructures.Add(client.Id, structure); CreateStructure(client.Id); NetworkServer.SendTcpToAll(client.Id, TcpPacketType.Server_State_Joined, buff => { buff.Write(client.Id); buff.Write(structure.Length); buff.Write(structure); }); }
private static void ServerOnClientDisconnected(INetworkServerClient client) { Debug.Log("Client disconnected: " + client.Id); Object.Destroy(BotCache.Get(client.Id).gameObject); NetworkServer.SendTcpToClients(TcpPacketType.Server_State_Left, buffer => buffer.Write(client.Id)); }
/// <summary> /// Makes the specified client disconnect. /// </summary> public static void Kick(INetworkServerClient client) { _server?.Disconnect(((NetworkServerClient)client).DoubleClient); }