예제 #1
0
        public IEnumerable <GameConnection> GetPlayers(string worldName = null)
        {
            var world = Worlds.Find(worldName);

            if (world != null)
            {
                return(Player.GetWorldPlayers(world)
                       .Select(p => new GameConnection
                {
                    Name = p.Name,
                    Score = p.Score,
                    IsAlive = p.IsAlive,
                    IP = p.IP,
                    Backgrounded = p.Connection?.Backgrounded ?? false,
                    ClientFPS = p.Connection?.ClientFPS ?? 0,
                    ClientVPS = p.Connection?.ClientVPS ?? 0,
                    ClientUPS = p.Connection?.ClientUPS ?? 0,
                    ClientCS = p.Connection?.ClientCS ?? 0,
                    Bandwidth = p.Connection?.Bandwidth ?? 0,
                    Latency = p.Connection?.Latency ?? 0
                }));
            }
            else
            {
                return(new GameConnection[0]);
            }
        }
예제 #2
0
        public bool Reset(string worldName = null)
        {
            var world = Worlds.Find(worldName);

            world.GetActor <RoomReset>().Reset = true;

            return(true);
        }
예제 #3
0
        public async Task <IActionResult> GetMesh(string worldKey, string id)
        {
            this.SuppressWrapper = true;
            var world = Worlds.Find(worldKey);
            var mesh  = await world.MeshLoader.GetMeshStreamAsync(id);

            return(File(mesh, "model/gltf-binary", "server.glb"));
        }
예제 #4
0
        public Server Get()
        {
            var world = Worlds.Find();

            return(new Server
            {
                PlayerCount = Player.GetWorldPlayers(world).Count,
                WorldCount = Worlds.AllWorlds.Count
            });
        }
예제 #5
0
        public bool Announce(string message, string worldName = null)
        {
            var world   = Worlds.Find(worldName);
            var players = Player.GetWorldPlayers(world);

            foreach (var player in players)
            {
                player.SendMessage(message);
            }

            return(true);
        }
예제 #6
0
        protected override void CycleThink()
        {
            if (GameRestartTime > 0 && World.Time > GameRestartTime)
            {
                GameRestartTime = 0;
                foreach (var team in Teams)
                {
                    team.Score          = 0;
                    team.Flag.CarriedBy = null;
                    team.Flag.ReturnToBase();
                }

                foreach (var player in Player.GetWorldPlayers(World))
                {
                    player.Score = 0;
                }
            }

            foreach (var team in Teams)
            {
                if (team.Score >= 5 && GameRestartTime == 0)
                {
                    var world   = Worlds.Find();
                    var players = Player.GetWorldPlayers(world);
                    foreach (var player in players)
                    {
                        player.SendMessage("Next round of CTF (Capture the Flag) starts in 30 seconds, join now");
                    }

                    GameRestartTime = World.Time + 30000;
                }
            }

            var playerCount = Player.GetWorldPlayers(World)
                              .Where(p => p.IsAlive).Count();

            if (playerCount == 0)
            {
                if (GameEmptySince == 0)
                {
                    GameEmptySince = World.Time;
                }
                else if (Teams.Any(t => t.Score > 0) && World.Time - GameEmptySince > 10000)
                {
                    GameRestartTime = World.Time;
                }
            }

            if (playerCount > 0)
            {
                GameEmptySince = 0;
            }
        }
예제 #7
0
        public IEnumerable <GameConnection> GetPlayers()
        {
            var world = Worlds.Find();

            return(Player.GetWorldPlayers(world)
                   .Select(p => new GameConnection
            {
                Name = p.Name,
                Score = p.Score,
                IsAlive = p.IsAlive,
                IP = p.IP
            }));
        }
예제 #8
0
        public async Task <string> Hook()
        {
            string json = null;

            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
                json = await reader.ReadToEndAsync();

            var world = Worlds.Find();

            JsonConvert.PopulateObject(json, world.Hook);

            return(JsonConvert.SerializeObject(world.Hook, Formatting.Indented));
        }
예제 #9
0
        public bool SetMap([FromBody] MapModel mapModel, string worldKey)
        {
            var world = Worlds.Find(worldKey);

            if (world != null)
            {
                world.GetActor <MapActor>().SetMap(mapModel);
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #10
0
        public async Task <Hook> Hook(string worldName = null)
        {
            string json = null;

            using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
                json = await reader.ReadToEndAsync();

            var world = Worlds.Find(worldName);

            JsonConvert.PopulateObject(json, world.Hook);

            // connection is using getHashCode for change detection
            world.Hook = world.Hook.Clone();

            return(world.Hook);
        }
예제 #11
0
        public Server Get(string worldKey)
        {
            var world = Worlds.Find(worldKey);

            return(new Server
            {
                PlayerCount = Player.GetWorldPlayers(world).Count,
                WorldCount = Worlds.AllWorlds.Count,
                Callouts = Player
                           .GetWorldPlayers(world)
                           .Where(p => p.Roles?.Contains("Callouts") ?? false)
                           .Select(p => new Server.Callout {
                    AvatarUrl = p.Avatar,
                    Name = p.LoginName
                })
                           .ToList()
            });
        }
예제 #12
0
        public async Task ConnectAsync(HttpContext httpContext, WebSocket socket, CancellationToken cancellationToken = default(CancellationToken))
        {
            Socket = socket;

            var worldRequest = httpContext.Request.Query["world"].FirstOrDefault();

            this.Logger.LogInformation($"New Connection: {worldRequest}");

            world = Worlds.Find(worldRequest);

            var builder = new FlatBufferBuilder(1);

            await SendPingAsync();

            ConnectionHeartbeat.Register(this);

            try
            {
                lock (world.Bodies)
                {
                    player = new Player
                    {
                        IP         = httpContext.Connection.RemoteIpAddress.ToString(),
                        Connection = this
                    };
                    player.Init(world);
                }

                var updateTask = StartSynchronizing(cancellationToken);
                var readTask   = StartReadAsync(this.HandleIncomingMessage, cancellationToken);

                await Task.WhenAny(updateTask, readTask);
            }
            finally
            {
                ConnectionHeartbeat.Unregister(this);

                if (player != null)
                {
                    player.PendingDestruction = true;
                    player.Connection         = null;
                }
            }
        }
예제 #13
0
        public async Task MessageReceivedAsync(SocketMessage rawMessage)
        {
            // Ignore system messages, or messages from other bots
            if (!(rawMessage is SocketUserMessage message))
            {
                return;
            }
            if (message.Source != MessageSource.User)
            {
                return;
            }

            // This value holds the offset where the prefix ends
            var argPos = 0;

            if (!message.HasMentionPrefix(_discord.CurrentUser, ref argPos))
            {
                var textMessage = $"@{message.Author.Username}: {message.Content}";
                foreach (var mention in message.MentionedUsers)
                {
                    textMessage = textMessage.Replace($"<@{mention.Id}>", $"@{mention.Username}");
                }

                if (message.Channel.Name.StartsWith("arena-"))
                {
                    var world = Worlds.Find(message.Channel.Name.Substring(6));

                    await DiscordBotModule.WorldAnnounce(world, textMessage);
                }

                if (message.MentionedUsers.Any())
                {
                    await DiscordBotModule.UserMentions(message.MentionedUsers.Select(u => u.Id), textMessage);
                }

                return;
            }

            var context = new SocketCommandContext(_discord, message);
            await _commands.ExecuteAsync(context, argPos, _services); // we will handle the result in CommandExecutedAsync
        }
예제 #14
0
 public World FindWorld(string name)
 {
     return(Worlds.Find((World x) => {
         return x.Name == name;
     }));
 }
예제 #15
0
 public World FindWorld(string name)
 {
     return(Worlds.Find((x) => x.Name == name));
 }
예제 #16
0
 public World FindWorld(int id)
 {
     return(Worlds.Find((x) => x._id == id));
 }
예제 #17
0
 public World FindWorld(int id)
 {
     return(Worlds.Find((World x) => {
         return x.ID == id;
     }));
 }
예제 #18
0
 internal World FindWorld(int id)
 {
     return(Worlds.Find((x) => x.ID == id));
 }
예제 #19
0
 internal World FindWorld(string name)
 {
     return(Worlds.Find((x) => x.Name == name));
 }