private void UpdateLastProcessedInputId(PlayerInput playerInput) { if (lastProcessedInputId >= playerInput.id) { Logger.LogError(LoggerSection.GameSnapshots, $"Got less or equal last inputId. Last remembered: {lastProcessedInputId}, new: {playerInput.id}"); return; } lastProcessedInputId = playerInput.id; }
public void SendPacket(Packet packet, IPEndPoint ipEndPoint) { try { udpClient.BeginSend(packet.ToArray(), packet.GetLength(), ipEndPoint, null, null); } catch (Exception exception) { Logger.LogError(LoggerSection.Network, $"Error sending UDP data to {ipEndPoint}: {exception}"); } }
private void OnConnection(IAsyncResult result) { try { IPEndPoint clientIpEndPoint = new IPEndPoint(IPAddress.Any, 0); byte[] data = udpClient.EndReceive(result, ref clientIpEndPoint); // Start listening for the next client connection udpClient.BeginReceive(OnConnection, null); if (data.Length < sizeof(int)) { return; } Packet packet = new Packet(data); int playerId = packet.ReadInt(); if (!playersManager.clients.ContainsKey(playerId)) { Logger.LogNotice(LoggerSection.Network, $"Skipping tcp packed from player {playerId}, because it is already disconnected"); return; } if (!playersManager.clients[playerId].IsConnectedViaUdp()) { playersManager.clients[playerId].ConnectUdp(clientIpEndPoint); return; } if (!playersManager.clients[playerId].IsCorrectUdpIpEndPoint(clientIpEndPoint)) { Logger.LogError(LoggerSection.Network, "Hacking attempt, client ids doesn't match"); return; } HandlePacketData(playerId, packet); } catch (ObjectDisposedException objectDisposedException) { Logger.LogNotice(LoggerSection.Network, $"Error receiving UDP data because udpClient is already disposed: {objectDisposedException}"); } catch (Exception exception) { Logger.LogError(LoggerSection.Network, $"Error receiving UDP data: {exception}"); } }
public void SendPacket(Packet packet) { if (udpClient == null) { throw new Exception("Uninitialized UdpClient"); } try { packet.InsertInt(connectionToServer.myPlayerId); udpClient.BeginSend(packet.ToArray(), packet.GetLength(), null, null); } catch (Exception exception) { Logger.LogError(LoggerSection.Network, $"Error sending data through udp: {exception}"); } }
private string GetLabelText() { switch (textLabel.text) { case TextLabelOneDot: return(TextLabelTwoDots); case TextLabelTwoDots: return(TextLabelThreeDots); case TextLabelThreeDots: return(TextLabelOneDot); default: Logger.LogError(LoggerSection.MainMenu, "Undefined textLabel text"); return(""); } }
private void OnConnection(IAsyncResult result) { TcpClient tcpClient = tcpListener.EndAcceptTcpClient(result); Logger.LogEvent(LoggerSection.Network, $"Incoming tcp connection from {tcpClient.Client.RemoteEndPoint}..."); // Start listening for the next client connection tcpListener.BeginAcceptTcpClient(OnConnection, null); for (int playerId = Game.PlayersManager.MinPlayerId; playerId <= Game.PlayersManager.MaxPlayerId; playerId++) { // If this client exists already - skip this playerId in order to find a free one if (playersManager.clients.ContainsKey(playerId)) { continue; } playersManager.clients[playerId] = new Client(playerId, udpClient, packetsReceiver, packetsSender, playersManager, metaMonoBehaviours); playersManager.clients[playerId].ConnectTcp(tcpClient); return; } Logger.LogError(LoggerSection.Connection, $"{tcpClient.Client.RemoteEndPoint} failed to connect a client: Server is full"); }
public Dictionary <int, int> GeneratePlayersData(int playerId) { if (!playersLockable.IsPlayerLocked(playerId)) { Logger.LogError(LoggerSection.AdminPanelViewing, $"Unable to generate admin panel information for player {playerId}, because he is not viewing it right now"); return(null); } Dictionary <int, int> adminPanelData = new Dictionary <int, int>(); foreach (KeyValuePair <int, List <int> > playerIdsInRoom in playerIdsInRooms) { if (playerIdsInRoom.Value.Count == 0) { continue; } adminPanelData[playerIdsInRoom.Key] = playerIdsInRoom.Value.Count; } Logger.LogEvent(LoggerSection.AdminPanelViewing, $"Generated admin panel data for player {playerId}"); return(adminPanelData); }