Exemple #1
0
        public static void EnemyHit(int fromClient, Packet packet)
        {
            if (!Server.IsRoundStarted())
            {
                return;
            }
            int playerId = packet.ReadInt();

            Server.clients[playerId].player.SetHealth(fromClient);
            Console.WriteLine($"{playerId} was hit by player {fromClient}.");
            Server.clients[fromClient].SendHitIntoGame(playerId);
            if (Server.clients[playerId].player.IsDead())
            {
                ServerSend.KillCountUpdate(fromClient);
            }
        }
Exemple #2
0
        public void UpdateIsReady(bool _isReady)
        {
            // updates whenever player changes isReady status
            isReady = _isReady;

            if (_isReady)
            {
                GameLogic.readyPlayers++;
            }
            else
            {
                GameLogic.readyPlayers--;
            }

            ServerSend.IsReadyToAllExcept(this);
        }
Exemple #3
0
            public void Connect(TcpClient socket)
            {
                this.socket = socket;

                socket.ReceiveBufferSize = dataBufferSize;
                socket.SendBufferSize    = dataBufferSize;

                stream = socket.GetStream();

                receivedData  = new Packet();
                receiveBuffer = new byte[dataBufferSize];

                stream.BeginRead(receiveBuffer, 0, dataBufferSize, ReceiveCallback, null);

                ServerSend.Welcome(id, "Welcome from the server!");
            }
 public void _Disconnect()
 {
     if (tcp.clientSocket != null)
     {
         Console.WriteLine($"{tcp.clientSocket.Client.RemoteEndPoint} has disconnected.");
         if (player.isReady)
         {
             GameLogic.readyPlayers--;
         }
         GameLogic.currentPlayers--;
         player = null;
         tcp.Disconnect();
         udp.Disconnect();
         ServerSend.KickPlayerToAllExcept(id);
     }
 }
 public void SendIntoGame(string _playerName)
 {
     player = new Player(id, _playerName);
     GameLogic.currentPlayers++;
     // update info
     foreach (ServerSideClient _client in Server.clients.Values)
     {
         if (_client.player != null)
         {
             if (_client.id != id)
             {
                 ServerSend.SpawnPlayer(id, _client.player); // info of all other players -> new player
             }
             ServerSend.SpawnPlayer(_client.id, player);     // info of new player -> all other players
         }
     }
 }
Exemple #6
0
        /// <summary>Disconnects the client and stops all network traffic.</summary>
        private void Disconnect()
        {
            ThreadManager.ExecuteOnMainThread(() =>
            {
                player = null;
            });

            tcp.Disconnect();
            udp.Disconnect();

            ServerSend.PlayerDisconnected(id);
            int connectedClients = Server.ClientsCount();

            if (connectedClients == 1 || connectedClients == 0)
            {
                Server.StopRound();
            }
        }
            public void ReceiveConnect(TcpClient _clientSocket)
            {
                if (RouterServer.ClientCount < RouterServer.MaxPlayers)
                {
                    clientSocket = _clientSocket;
                    clientSocket.ReceiveBufferSize = dataBufferSize;
                    clientSocket.SendBufferSize    = dataBufferSize;

                    stream = clientSocket.GetStream();

                    receivedPacket = new Packet();
                    receiveBuffer  = new byte[dataBufferSize];
                    stream.BeginRead(receiveBuffer, 0, dataBufferSize, _ReceiveCallback, null);

                    int _port = RouterServer.ports[(RouterServer.ClientCount % RouterServer.MaxPlayers) + 1];
                    RouterServer.ClientCount += 1;

                    ServerSend.RouterWelcome(id, $"Assigned port {_port} by the Router Server!", _port);
                }
            }
        public static void Update()
        {
            ThreadManager.UpdateMain();

            if (isGameStarted)
            {
                if (timer == 0)
                {
                    ServerSend.PositionRotationAllUpdate();
                }
                timer = (timer + 1) % frameIncreaseFactor;

                if (currentPlayers == 0)
                {
                    Reset();

                    Console.WriteLine($"RESET: No player is online, reset Game Logic");
                }
            }
        }
Exemple #9
0
        public static void PlayerShoot(int _fromClient, Packet _packet)
        {
            if (Server.clients[_fromClient].player != null)
            {
                int     _hitId    = _packet.ReadInt();
                Vector3 _hitPoint = _packet.ReadVector3();

                int _hitHealth = -1;
                if (_hitId != -1)
                {
                    Player _hitPlayer = Server.clients[_hitId].player;
                    _hitPlayer.health -= 5;
                    // TODO: Handle Death?
                    if (_hitPlayer.health == 0)
                    {
                        _hitPlayer.deathCount += 1;
                    }
                    _hitHealth = _hitPlayer.health;
                }

                ServerSend.ShootToAll(_fromClient, _hitId, _hitPoint, _hitHealth);
            }
        }