Exemplo n.º 1
0
        private void SpawnTank(ServerDiepConnection connection)
        {
            var tank = new Tank(GUI.Controller.Screen, TeamColor.DeepSkyBlue, Tank.StandardWeight)
            {
                Name = $"{connection.Name}@{connection.Id}",
                Id   = ++CurrentTankId
            };

            tank.InitializeTank();
            var bounds = tank.Bounds;

            bounds.X    = (float)(Extensions.Random.NextDouble() * 300);
            bounds.Y    = (float)(Extensions.Random.NextDouble() * 300);
            tank.Bounds = bounds;
            // This line is removed because the Spawn is now performed through the Spawn Message
            ///GUI.Controller.Screen.Tanks.Add(tank);
            var spawnMessage = new TankSpawnMessage()
            {
                Id           = connection.Id,
                ServerTankId = tank.Id,
                Name         = tank.Name,
                X            = bounds.X,
                Y            = bounds.Y,
                Width        = bounds.Width,
                Height       = bounds.Height,
                TeamColor    = tank.TeamColor,
                Weight       = tank.Weight,
            };

            connection.Tank = tank;
            // @null to broadcast it to every user connected at server
            Broadcast(null, spawnMessage);
        }
Exemplo n.º 2
0
 private void AcceptConnection()
 {
     while (Running)
     {
         var freshConnection = new ServerDiepConnection(TcpListener.AcceptTcpClient());
         freshConnection.Start();
         freshConnection.MessageReceived += FreshConnection_MessageReceived;
     }
 }
Exemplo n.º 3
0
 private void AuthenticateClient(ServerDiepConnection connection, ConnectMessage message)
 {
     message.Id      = ++CurrentConnectionId;
     connection.Id   = message.Id;
     connection.Name = message.Name;
     connection.Enqueue(message);
     Connections.Add(connection);
     InvokerMainThread.Invoke((amount) => { labelUserAmount.Text = amount.ToString(); }, Connections.Count);
 }
Exemplo n.º 4
0
        private void ExecuteShoot(ServerDiepConnection connection, ShootMessage shootMessage)
        {
            Broadcast(null, shootMessage);
            //
            var spawnMessage = new ShootSpawnMessage()
            {
                Id            = ++CurrentShootId,
                IdSupport     = connection.Tank.Id,
                SupportType   = shootMessage.SupportType,
                ShootServerId = CurrentShootId,
                CannonIndex   = shootMessage.CannonIndex
            };

            //
            Broadcast(null, spawnMessage);
        }