Example #1
0
        public static ServerProperties GetDefault(string hostName)
        {
            ServerProperties properties = Default;

            properties.Name = $"{hostName}'s Server";

            return(properties);
        }
Example #2
0
        /// <summary>
        /// Asynchronously creates a new <see cref="GameServer"/>.
        /// </summary>
        internal static async Task <GameServer> CreateAsync(GameManager manager, IUser user, IMessageChannel channel, ServerProperties properties = null)
        {
            properties ??= ServerProperties.GetDefault(user.Username);
            properties.GameId = manager.DefaultGameId;

            if (manager.ReservedUsers.ContainsKey(user.Id))
            {
                throw new ReservedException(user.Id, EntityType.User);
            }

            if (manager.ReservedChannels.ContainsKey(channel.Id))
            {
                throw new ReservedException(channel.Id, EntityType.Channel);
            }

            var server = new GameServer(manager, user, properties);

            server.DrawHeader();
            server.AddConsoleText($"[Console] {user.Username} has joined.");

            manager.ReservedUsers.Add(user.Id, server.Id);
            manager.ReservedChannels.Add(channel.Id, server.Id);

            var connectionProperties = new ConnectionProperties
            {
                AutoRefreshCounter = 4,
                CanDeleteMessages  = true,
                BlockInput         = false,
                Frequency          = 0,
                State = GameState.Waiting
            };

            var connection = await ServerConnection.CreateAsync(channel, server, connectionProperties);

            if (user is IGuildUser guildUser)
            {
                connection.Type    = ConnectionType.Guild;
                connection.GuildId = guildUser.GuildId;
            }

            server.Connections.Add(connection);
            manager.Servers.Add(server.Id, server);

            return(server);
        }
Example #3
0
 private GameServer(GameManager manager, IUser host, ServerProperties properties = null)
 {
     properties ??= ServerProperties.GetDefault(host.Username);
     _manager       = manager;
     HostId         = host.Id;
     Id             = KeyBuilder.Generate(8);
     Name           = properties.Name;
     GameId         = properties.GameId;
     Privacy        = properties.Privacy;
     Broadcasts     = DisplayBroadcast.GetReservedBroadcasts();
     Connections    = new List <ServerConnection>();
     Invites        = new List <ServerInvite>();
     AllowedActions = properties.AllowedActions;
     _players       = new List <Player>
     {
         new Player(this, host)
     };
     Destroyed   = false;
     LastUpdated = DateTime.UtcNow;
     LoadGameConfig();
 }