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]); } }
public bool Reset(string worldName = null) { var world = Worlds.Find(worldName); world.GetActor <RoomReset>().Reset = true; return(true); }
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")); }
public Server Get() { var world = Worlds.Find(); return(new Server { PlayerCount = Player.GetWorldPlayers(world).Count, WorldCount = Worlds.AllWorlds.Count }); }
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); }
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; } }
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 })); }
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)); }
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); } }
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); }
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() }); }
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; } } }
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 }
public World FindWorld(string name) { return(Worlds.Find((World x) => { return x.Name == name; })); }
public World FindWorld(string name) { return(Worlds.Find((x) => x.Name == name)); }
public World FindWorld(int id) { return(Worlds.Find((x) => x._id == id)); }
public World FindWorld(int id) { return(Worlds.Find((World x) => { return x.ID == id; })); }
internal World FindWorld(int id) { return(Worlds.Find((x) => x.ID == id)); }
internal World FindWorld(string name) { return(Worlds.Find((x) => x.Name == name)); }