Пример #1
0
 public static void Load()
 {
     try
     {
         using (NpgsqlConnection npgsqlConnection = SQLjec.getInstance().conn())
         {
             NpgsqlCommand command = npgsqlConnection.CreateCommand();
             npgsqlConnection.Open();
             command.CommandText = "SELECT * FROM info_gameservers ORDER BY id ASC";
             command.CommandType = CommandType.Text;
             NpgsqlDataReader npgsqlDataReader = command.ExecuteReader();
             while (npgsqlDataReader.Read())
             {
                 GameServerModel gameServerModel = new GameServerModel(npgsqlDataReader.GetString(3), (ushort)npgsqlDataReader.GetInt32(5))
                 {
                     _id         = npgsqlDataReader.GetInt32(0),
                     _state      = npgsqlDataReader.GetInt32(1),
                     _type       = npgsqlDataReader.GetInt32(2),
                     _port       = (ushort)npgsqlDataReader.GetInt32(4),
                     _maxPlayers = npgsqlDataReader.GetInt32(6)
                 };
                 ServersXML._servers.Add(gameServerModel);
             }
             command.Dispose();
             npgsqlDataReader.Close();
             npgsqlConnection.Dispose();
             npgsqlConnection.Close();
         }
     }
     catch (Exception ex)
     {
         Logger.error(ex.ToString(), false);
     }
 }
Пример #2
0
    private void Start()
    {
        if (NetworkClient.active)
        {
            return;
        }

        // Check if this instance was started as a client.
        EnvironmentVariables environmentVariables = EnvironmentVariables.singleton;

        if (environmentVariables.isServer)
        {
            return;
        }

        // Show the loading screen and connect to the server.
        GameServerModel gameServerModel = environmentVariables.gameServerModel;

        // Override Access and Refresh Tokens.
        TokenManager.singleton.accessToken  = environmentVariables.accessToken;
        TokenManager.singleton.refreshToken = environmentVariables.refreshToken;

        // Set the port.
        kcpTransport.Port = Convert.ToUInt16(gameServerModel.port);

        // Set the URL.
        EnvironmentObject environment = EnvironmentManager.singleton.environmentObject;
        string            host        = new Uri(environment.gameServerApiBaseUrl).Host;
        Uri uri = new Uri(string.Format("tcp4://{0}", host));

        // Start the client.
        networkManager.StartClient(uri);
    }
Пример #3
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var server = await _context.Servers.FirstOrDefaultAsync((x) => x.IpPortInfo.Equals(request.IpPortInfo));

                if (server != null)
                {
                    throw new RestException(System.Net.HttpStatusCode.BadRequest, $"Server {request.IpPortInfo} already exists");
                }

                server = new GameServerModel
                {
                    IpPortInfo = request.IpPortInfo,
                    MaxMatches = request.MaxMatches,
                    Name       = request.Name,
                    State      = request.State,
                };

                _context.Servers.Add(server);

                bool success = await _context.SaveChangesAsync() > 0;

                if (success == false)
                {
                    throw new Exception("Problem Saving Changes");
                }

                return(Unit.Value);
            }
Пример #4
0
        public static void SendLoginKickInfo(Account player)
        {
            int serverId = (int)player._status.serverId;

            switch (serverId)
            {
            case 0:
            case (int)byte.MaxValue:
                player.setOnlineStatus(false);
                break;

            default:
                GameServerModel server = ServersXML.getServer(serverId);
                if (server == null)
                {
                    break;
                }
                using (SendGPacket sendGpacket = new SendGPacket())
                {
                    sendGpacket.writeH((short)10);
                    sendGpacket.writeQ(player.player_id);
                    Auth_SyncNet.SendPacket(sendGpacket.mstream.ToArray(), server.Connection);
                    break;
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="player">Conta principal</param>
        /// <param name="friend">Amigo que será adicionado/atualizado..</param>
        /// <param name="type">0=Adicionar|1=Atualizar|2=Deletar</param>
        ///
        // send to Game or sync
        public static void Load(Account player, Friend friend, int type)
        {
            if (player == null)
            {
                return;
            }

            GameServerModel gs = Game_SyncNet.GetServer(player._status);

            if (gs == null)
            {
                return;
            }

            using (SendGPacket pk = new SendGPacket())
            {
                pk.writeH(17);
                pk.writeQ(player.player_id);
                pk.writeC((byte)type);
                pk.writeQ(friend.player_id);

                if (type != 2)
                {
                    pk.writeC((byte)friend.state);
                }
                Game_SyncNet.SendPacket(pk.mstream.ToArray(), gs._syncConn);
            }
        }
Пример #6
0
 public override void write()
 {
     this.writeH((short)2049);
     this.writeD(this._sessionId);
     this.writeIP(this._ip);
     this.writeH((short)29890);
     this.writeH(this._sessionSeed);
     for (int index = 0; index < 10; ++index)
     {
         this.writeC((byte)ChannelsXML._channels[index]._type);
     }
     this.writeC((byte)1);
     this.writeD(ServersXML._servers.Count);
     for (int index = 0; index < ServersXML._servers.Count; ++index)
     {
         GameServerModel server = ServersXML._servers[index];
         this.writeD(server._state);
         this.writeIP(server.Connection.Address);
         this.writeH(server._port);
         this.writeC((byte)server._type);
         this.writeH((ushort)server._maxPlayers);
         this.writeD(server._LastCount);
     }
     this.writeH((short)1);
     this.writeH((short)300);
     this.writeD(200);
     this.writeD(100);
     this.writeC((byte)1);
     this.writeD(3);
     this.writeD(100);
     this.writeD(150);
 }
Пример #7
0
        public static void LoadItem(Account player, ItemsModel item)
        {
            if (player == null || player._status.serverId == 0)
            {
                return;
            }
            GameServerModel gs = Game_SyncNet.GetServer(player._status);

            if (gs == null)
            {
                return;
            }

            using (SendGPacket pk = new SendGPacket())
            {
                pk.writeH(18);
                pk.writeQ(player.player_id);
                pk.writeQ(item._objId);
                pk.writeD(item._id);
                pk.writeC((byte)item._equip);
                pk.writeC((byte)item._category);
                pk.writeD(item._count);
                Game_SyncNet.SendPacket(pk.mstream.ToArray(), gs._syncConn);
            }
        }
Пример #8
0
        public static void Load(Account player, Friend friend, int type)
        {
            if (player == null)
            {
                return;
            }
            GameServerModel server = Game_SyncNet.GetServer(player._status);

            if (server == null)
            {
                return;
            }
            using (SendGPacket sendGpacket = new SendGPacket())
            {
                sendGpacket.writeH((short)17);
                sendGpacket.writeQ(player.player_id);
                sendGpacket.writeC((byte)type);
                sendGpacket.writeQ(friend.player_id);
                if (type != 2)
                {
                    sendGpacket.writeC((byte)friend.state);
                    sendGpacket.writeC(friend.removed);
                }
                Game_SyncNet.SendPacket(sendGpacket.mstream.ToArray(), server.Connection);
            }
        }
        public override void read()
        {
            try
            {
                sessionId = nextUint();
                ip        = new IPAddress(nextByte(4));
                cryptoKey = nextShort();
                seed      = nextUshort();
                nextByte(11);
                countServer = nextInt();

                for (int i = 0; i < countServer; i++)
                {
                    GameServerModel server = new GameServerModel()
                    {
                        _id         = i,
                        _state      = nextInt(),
                        _ip         = new IPAddress(nextByte(4)),
                        _port       = nextUshort(),
                        _type       = nextByte(),
                        _maxPlayers = nextUshort(),
                        _LastCount  = nextInt()
                    };
                    _servers.Add(server);
                }
            }
            catch (Exception e)
            {
                Printf.b_danger("[BASE_SERVER_LIST_ACK.READ] \r\n" + e);
            }
        }
Пример #10
0
 public static void RefreshAccount(Account player, bool isConnect)
 {
     Auth_SyncNet.UpdateGSCount(0);
     AccountManager.getInstance().getFriendlyAccounts(player.FriendSystem);
     for (int index = 0; index < player.FriendSystem._friends.Count; ++index)
     {
         Friend     friend  = player.FriendSystem._friends[index];
         PlayerInfo player1 = friend.player;
         if (player1 != null)
         {
             GameServerModel server = ServersXML.getServer((int)player1._status.serverId);
             if (server != null)
             {
                 SEND_REFRESH_ACC.SendRefreshPacket(0, player.player_id, friend.player_id, isConnect, server);
             }
         }
     }
     if (player.clan_id <= 0)
     {
         return;
     }
     for (int index = 0; index < player._clanPlayers.Count; ++index)
     {
         Account clanPlayer = player._clanPlayers[index];
         if (clanPlayer != null && clanPlayer._isOnline)
         {
             GameServerModel server = ServersXML.getServer((int)clanPlayer._status.serverId);
             if (server != null)
             {
                 SEND_REFRESH_ACC.SendRefreshPacket(1, player.player_id, clanPlayer.player_id, isConnect, server);
             }
         }
     }
 }
Пример #11
0
        public static string GetServerPlayersCount(string str)
        {
            int             id     = int.Parse(str.Substring(9));
            GameServerModel server = ServersXML.getServer(id);

            if (server == null)
            {
                return(Translation.GetLabel("UsersInvalid"));
            }
            return(Translation.GetLabel("UsersCount2", (object)server._LastCount, (object)server._maxPlayers, (object)id));
        }
Пример #12
0
        public void Add(GameServerModel gs)
        {
            if (gs == null || string.IsNullOrEmpty(gs.Type) || gs.Uri == null)
            {
                throw new ArgumentException("Empty model");
            }

            var key = $"{gs.Type}_{gs.Uri.AbsoluteUri}";

            gs.LastUpdate = DateTime.Now;
            lock (_servers){
                _servers[key] = gs;
            }
        }
Пример #13
0
 public static GameServerModel getServer(int id)
 {
     lock (_servers)
     {
         for (int i = 0; i < _servers.Count; i++)
         {
             GameServerModel server = _servers[i];
             if (server._id == id)
             {
                 return(server);
             }
         }
         return(null);
     }
 }
Пример #14
0
        private void HandleHelloKey(TeraPacket packet)
        {
            string          key = packet.Reader.ReadString();
            GameServerModel gsm = GameServerTable.Cache.Find(x => x.Key.Equals(key));

            if (gsm != null)
            {
                this.Server = gsm;
                Logger.Info("GameServer " + gsm.ID + " Online");
            }
            else
            {
                Logger.Warn("Unknown key '" + key + "' received");
            }
        }
 public override void write()
 {
     writeH(2643);
     writeD(ServersXML._servers.Count);
     for (int i = 0; i < ServersXML._servers.Count; i++)
     {
         GameServerModel server = ServersXML._servers[i];
         writeD(server._state);
         writeIP(server._serverConn.Address);
         writeH((ushort)server._serverConn.Port);
         writeC((byte)server._type);
         writeH((ushort)server._maxPlayers);
         writeD(server._LastCount);
     }
 }
Пример #16
0
 public static GameServerModel getServer(int id)
 {
     lock (ServersXML._servers)
     {
         for (int index = 0; index < ServersXML._servers.Count; ++index)
         {
             GameServerModel server = ServersXML._servers[index];
             if (server._id == id)
             {
                 return(server);
             }
         }
         return((GameServerModel)null);
     }
 }
Пример #17
0
 public override void write()
 {
     this.writeH((short)2643);
     this.writeD(ServersXML._servers.Count);
     for (int index = 0; index < ServersXML._servers.Count; ++index)
     {
         GameServerModel server = ServersXML._servers[index];
         this.writeD(server._state);
         this.writeIP(server.Connection.Address);
         this.writeH(server._port);
         this.writeC((byte)server._type);
         this.writeH((ushort)server._maxPlayers);
         this.writeD(server._LastCount);
     }
 }
        public async Task RegisterGameServerAsync(string name, int maxMatches, IpPortInfo ipPortInfo)
        {
            if (Servers.ContainsKey(ipPortInfo))
            {
                _logger.LogError($"Trying to register duplicate server => {ipPortInfo}");

                return;
            }

            var serverModel = await _dbContext.Servers.TryFindGameServerModel(ipPortInfo);

            if (serverModel != null)
            {
                //Turn on server
                _logger.LogWarning($"Already has {serverModel.IpPortInfo} in the database. Turning on the server.");
                var newServer = new GameServer(serverModel, _loggerFactory, serverModel.MaxMatches);
                Servers.TryAdd(ipPortInfo, newServer);
                return;
            }

            //Register new servver
            serverModel = new GameServerModel
            {
                IpPortInfo = ipPortInfo,
                MaxMatches = maxMatches,
                Name       = name,
                State      = ServerState.Running,
            };

            _dbContext.Servers.Add(serverModel);
            await _dbContext.SaveChangesAsync();

            var server = new GameServer(serverModel, _loggerFactory);

            server.MaxMatches = maxMatches;

            var result = Servers.TryAdd(ipPortInfo, server);

            if (result == false)
            {
                _logger.LogError($"Failed to add {server} as it already exists");

                return;
            }

            _logger.LogInformation($"Registerd server {server}");
        }
Пример #19
0
        public GameServer(GameServerModel gameServerModel, ILoggerFactory loggerFactory, int maxMatches = 5)
        {
            Id         = gameServerModel.Id;
            Name       = gameServerModel.Name;
            IpPortInfo = gameServerModel.IpPortInfo;
            MaxMatches = maxMatches;

            Matches         = new ConcurrentDictionary <string, Match>(Environment.ProcessorCount * 2, 128);
            UserConnections = new ConcurrentDictionary <GameUser, int>(Environment.ProcessorCount * 2, 256);
            PendingMatches  = new ConcurrentDictionary <string, Match>(Environment.ProcessorCount * 2, 64);

            _logger = loggerFactory.CreateLogger <GameServer>();
            _logger.LogInformation($"GameServer : {this} has been launched!");

            var timer = new System.Timers.Timer();

            timer.Interval = 30 * 1000; //15sec
            timer.Elapsed += CleanPendingLists;
        }
Пример #20
0
        public override void Write()
        {
            WriteH(2);
            WriteD(AuthManager.SocketSessions.Count);
            WriteD(GameManager.SocketSessions.Count);
            WriteD(AccountManager.accounts.Count);
            WriteD(ClanManager.clans.Count);
            WriteD(Application.recordOnline);
            WriteQ(long.Parse(Application.StartDate.ToString("yyyyMMddHHmmss")));

            GameServerModel server = ServersManager.GetServer();

            WriteD(server.id);
            WriteD(server.type);
            WriteD(server.maxPlayers);

            int allRooms   = 0;
            int allPlayers = 0;

            WriteD(Settings.MaxPlayersChannel);
            WriteD(ServersManager.channels.Count);
            foreach (Channel channel in ServersManager.channels)
            {
                WriteD(channel.id);
                WriteD(channel.type);
                WriteD(channel.players.Count);
                WriteD(channel.rooms.Count);
                WriteD(channel.matchs.Count);
                WriteH((ushort)channel.announce.Length);
                WriteS(channel.announce, channel.announce.Length);
                allRooms   += channel.rooms.Count;
                allPlayers += channel.players.Count;
            }
            WriteD(allRooms);
            WriteD(allPlayers);

            RankManager.GetRankCounts(out int ranks47, out int ranks48, out int ranks49, out int ranks50, out int ranks51);
            WriteD(ranks47);
            WriteD(ranks48);
            WriteD(ranks49);
            WriteD(ranks50);
            WriteD(ranks51);
        }
Пример #21
0
        private void LoginQueue()
        {
            GameServerModel server = ServersXML.getServer(0);

            if (server._LastCount < server._maxPlayers)
            {
                return;
            }
            if (LoginManager._loginQueue.Count >= 100)
            {
                this._client.SendPacket((SendPacket) new BASE_LOGIN_PAK(EventErrorEnum.Login_SERVER_USER_FULL, this.login, 0L));
                Logger.LogLogin("Servidor cheio [" + this.login + "]");
                this._client.Close(1000, false);
            }
            else
            {
                int num = LoginManager.EnterQueue(this._client);
                this._client.SendPacket((SendPacket) new A_LOGIN_QUEUE_PAK(num + 1, (num + 1) * 120));
            }
        }
Пример #22
0
        public static void SendCompleteBytes(long playerId,byte[] buffer,int serverId)
        {
            if (buffer.Length == 0)
            {
                return;
            }
            GameServerModel server = Game_SyncNet.GetServer(serverId);

            if (server == null)
            {
                return;
            }
            using (SendGPacket sendGpacket = new SendGPacket())
            {
                sendGpacket.writeH((short)13);
                sendGpacket.writeQ(playerId);
                sendGpacket.writeC((byte)1);
                sendGpacket.writeH((ushort)buffer.Length);
                sendGpacket.writeB(buffer);
                Game_SyncNet.SendPacket(sendGpacket.mstream.ToArray(),server.Connection);
            }
        }
Пример #23
0
        public void OnPostNewGameServer(string newGameServerName)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(newGameServerName))
                {
                    ErrorMessage = "Invalid new game server name!";
                    return;
                }

                int maxGameServers = GetMaxGameServersPerGroup();

                if (GetUserGameServerCount() >= maxGameServers)
                {
                    ErrorMessage = $"Maximum game server count exceeded! ({maxGameServers})";
                    return;
                }

                var userGameServerGroup = DbContext.GetUserGameServerGroup(User).Result;

                if (userGameServerGroup == null)
                {
                    return;
                }

                var userGameServer = new GameServerModel
                {
                    GroupId = userGameServerGroup.Id,
                    Name    = newGameServerName.Trim()
                };

                DbContext.GameServer.Add(userGameServer);
                DbContext.SaveChanges();
            }
            catch (Exception)
            {
                ErrorMessage = "Creating new game server failed!";
            }
        }
        public override void write()
        {
            writeH(2049);
            writeD(_sessionId); //sessionId
            writeIP(_ip);
            writeH(29890);
            writeH(0); // Hash|Seed
            for (int i = 0; i < 10; i++)
            {
                writeC((byte)ChannelsXML._channels[i]._type);
            }
            writeC(1);
            writeD(ServersXML._servers.Count);
            for (int i = 0; i < ServersXML._servers.Count; i++)
            {
                GameServerModel server = ServersXML._servers[i];
                writeD(server._state);
                writeIP(server._serverConn.Address);
                writeH((ushort)server._serverConn.Port);
                writeC((byte)server._type);
                writeH((ushort)server._maxPlayers);
                writeD(server._LastCount);
            }
            writeH(1); //Quantidade de algo
            writeH(300);
            writeD(200);
            writeD(100);

            /*
             * writeH(0);
             * writeD(0);
             * writeD(0);
             *
             * */
            writeC(1);   //Events Count
            writeD(3);   //Type
            writeD(100); //Exp
            writeD(150); //Point
        }
Пример #25
0
        public static void Load(Account pl, Account member, int type)
        {
            if (pl == null)
            {
                return;
            }
            GameServerModel server = Game_SyncNet.GetServer(pl._status);

            if (server == null)
            {
                return;
            }
            using (SendGPacket sendGpacket = new SendGPacket())
            {
                sendGpacket.writeH((short)16);
                sendGpacket.writeQ(pl.player_id);
                sendGpacket.writeC((byte)type);
                switch (type)
                {
                case 1:
                    sendGpacket.writeQ(member.player_id);
                    sendGpacket.writeC((byte)(member.player_name.Length + 1));
                    sendGpacket.writeS(member.player_name, member.player_name.Length + 1);
                    sendGpacket.writeB(member._status.buffer);
                    sendGpacket.writeC((byte)member._rank);
                    break;

                case 2:
                    sendGpacket.writeQ(member.player_id);
                    break;

                case 3:
                    sendGpacket.writeD(pl.clanId);
                    sendGpacket.writeC((byte)pl.clanAccess);
                    break;
                }
                Game_SyncNet.SendPacket(sendGpacket.mstream.ToArray(), server.Connection);
            }
        }
Пример #26
0
        public override void write()
        {
            writeH(2049);
            writeD(_sessionId);
            writeIP(_ip);
            writeH(29890);        //udpPort
            writeH(_sessionSeed); // Hash|Seed
            for (int index = 0; index < 10; ++index)
            {
                writeC(1);
            }
            writeC(1);
            writeD(ServersXML._servers.Count);
            for (int i = 0; i < ServersXML._servers.Count; i++)
            {
                GameServerModel server = ServersXML._servers[i];
                writeD(server._state);
                writeIP(server._serverConn.Address);
                writeH((ushort)server._serverConn.Port);
                writeC((byte)server._type);
                writeH((ushort)server._maxPlayers);
                writeD(server._LastCount); // Only in server
            }
            writeH(1);                     //Quantidade de algo
            writeH(300);
            writeD(200);
            writeD(100);

            /*
             * writeH(0); //Type
             * writeD(0); //Exp
             * writeD(0); //Point
             *
             * */
            writeC(1);   //Events
            writeD(1);   //Type
            writeD(100); //Exp
            writeD(150); //Point
        }
Пример #27
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pl">Conta principal</param>
        /// <param name="member"></param>
        /// <param name="type">0=Zerar players e clanId|1=Adicionar|2=Remover|3=att clanid e aux</param>
        public static void Load(Account pl, Account member, int type)
        {
            if (pl == null)
            {
                return;
            }
            GameServerModel gs = Game_SyncNet.GetServer(pl._status);

            if (gs == null)
            {
                return;
            }

            using (SendGPacket pk = new SendGPacket())
            {
                pk.writeH(16);
                pk.writeQ(pl.player_id);
                pk.writeC((byte)type);
                if (type == 1) //adicionar
                {
                    pk.writeQ(member.player_id);
                    pk.writeC((byte)(member.player_name.Length + 1));
                    pk.writeS(member.player_name, member.player_name.Length + 1);
                    pk.writeB(member._status.buffer);
                    pk.writeC((byte)member._rank);
                }
                else if (type == 2) //remover
                {
                    pk.writeQ(member.player_id);
                }
                else if (type == 3) //atualizar id do clã e aux
                {
                    pk.writeD(pl.clanId);
                    pk.writeC((byte)pl.clanAccess);
                }
                Game_SyncNet.SendPacket(pk.mstream.ToArray(), gs._syncConn);
            }
        }
Пример #28
0
        public static void SendBytes(long playerId,SendPacket sp,int serverId)
        {
            if (sp == null)
            {
                return;
            }
            GameServerModel server = Game_SyncNet.GetServer(serverId);

            if (server == null)
            {
                return;
            }
            byte[] bytes = sp.GetBytes("Game_SyncNet.SendBytes");
            using (SendGPacket sendGpacket = new SendGPacket())
            {
                sendGpacket.writeH((short)13);
                sendGpacket.writeQ(playerId);
                sendGpacket.writeC((byte)0);
                sendGpacket.writeH((ushort)bytes.Length);
                sendGpacket.writeB(bytes);
                Game_SyncNet.SendPacket(sendGpacket.mstream.ToArray(),server.Connection);
            }
        }
Пример #29
0
        public static void SendCompleteBytes(long playerId,byte[] buffer,short serverId)
        {
            if (buffer.Length == 0)
            {
                return;
            }
            GameServerModel gs = GetServer(serverId);

            if (gs == null)
            {
                return;
            }

            using (SendGPacket pk = new SendGPacket())
            {
                pk.writeH(13);
                pk.writeQ(playerId);
                pk.writeC(1);
                pk.writeH((ushort)buffer.Length);
                pk.writeB(buffer);
                SendPacket(pk.mstream.ToArray(),gs._syncConn);
            }
        }
Пример #30
0
        public static void LoadGoldCash(Account player)
        {
            if (player == null)
            {
                return;
            }
            GameServerModel server = Game_SyncNet.GetServer(player._status);

            if (server == null)
            {
                return;
            }
            using (SendGPacket sendGpacket = new SendGPacket())
            {
                sendGpacket.writeH((short)19);
                sendGpacket.writeQ(player.player_id);
                sendGpacket.writeC((byte)0);
                sendGpacket.writeC((byte)player._rank);
                sendGpacket.writeD(player._gp);
                sendGpacket.writeD(player._money);
                Game_SyncNet.SendPacket(sendGpacket.mstream.ToArray(), server.Connection);
            }
        }