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); }
private void SendOtherTanks(DiepConnection Connection) { foreach (var connection in Connections.ToArray().Where(a => a.Id != Connection.Id && a.Tank != null)) { var tank = connection.Tank; var bounds = tank.Bounds; var spawnMessage = new TankSpawnMessage() { Id = connection.Id, ServerTankId = tank.Id, Name = connection.Tank.Name, Height = bounds.Height, Width = bounds.Width, TeamColor = tank.TeamColor, Weight = tank.Weight, X = bounds.X, Y = bounds.Y }; Connection.Enqueue(spawnMessage); } }