private static void SetServerVariables(GameServerData gameServer, string[] serverDataFrag, IPEndPoint remote)
        {
            //gameServer.Country = (remote.Address.AddressFamily == AddressFamily.InterNetwork)
            //   ? GeoIP.GetCountryCode(remote.Address).ToUpperInvariant()
            //   : "??";

            using (var reader = new DatabaseReader("./GeoLite2-Country.mmdb"))
            {
                var response = reader.Country("128.101.101.101");
                var country  = response.Country;
                Console.WriteLine(country.IsoCode);            // 'US'
                Console.WriteLine(country.Name);               // 'United States'
                Console.WriteLine(country.Names["zh-CN"]);     // '美国'
                Console.WriteLine(country.Confidence);         // 99
            }

            for (int i = 0; i < serverDataFrag.Length - 1; i += 2)
            {
                //Fetch the properties
                PropertyInfo property = typeof(GameServerData).GetProperty(serverDataFrag[i]);
                if (property == null)
                {
                    continue;
                }
            }
        }
        public void RegisterGameServer(NetConnection connection, GameServerData gameServer)
        {
            gameServers.Add(connection.connectionId, gameServer);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"Game Server Registered: IP {gameServer.ipAddress} | Port {gameServer.port} | Name {gameServer.name}");
            Console.ForegroundColor = ConsoleColor.White;
        }
Example #3
0
 /// <summary>
 /// Sets a server's online status in the database
 /// </summary>
 /// <param name="server"></param>
 public void UpdateServerOffline(GameServerData server)
 {
     // Check if server exists in database
     if (server.DatabaseId > 0)
     {
         // Update
         string query = "UPDATE server SET online=0, lastseen=@P0 WHERE id=@P1";
         //    QRServer.DB.Execute(query, new DateTimeOffset(server.LastRefreshed).ToUnixTimeSeconds(), server.DatabaseId);
     }
 }
Example #4
0
        void OnRequestEnterRoom(Notification note)
        {
            Message msg = note.GetMessage();

            using (ByteBuffer buff = new ByteBuffer(note.GetBytes()))
            {
                long   roleId = buff.ReadInt64();
                string name   = buff.ReadString();
                int    state  = GameServerData.EnterGameRoom(roleId, name);
                msg.Reply(PtMessagePackage.Build((int)S2CMessageId.ResponseEnterRoom,
                                                 new ByteBuffer().WriteInt32(state).WriteBytes(GameRoomSvo.Write(GameServerData.GameRoom)).Getbuffer()));
                //Debug.Log("[server] OnRequestEnterRoom !" + roleId);
            }
        }
Example #5
0
        /// <summary>
        /// Fetches a property by fieldName from the provided Server Object
        /// </summary>
        /// <param name="server">The server we are fetching the field value from</param>
        /// <param name="fieldName">the field value we want</param>
        /// <returns></returns>
        private static string GetField(GameServerData server, string fieldName)
        {
            object value = server.GetType().GetProperty(fieldName).GetValue(server, null);

            if (value == null)
            {
                return(String.Empty);
            }
            else if (value is Boolean)
            {
                return((bool)value ? "1" : "0");
            }
            else
            {
                return(value.ToString());
            }
        }
        /// Client or server information come in
        /// </summary>
        /// <param name="server"></param>
        /// <param name="packet"></param>
        public static void HeartbeatResponse(QRServer server, EndPoint endPoint, byte[] buffer)
        {
            byte[] recvKeys = new byte[4];
            //we copy 4 bytes information prepare for reply
            Array.Copy(buffer, 1, recvKeys, 0, 4);

            byte[] restData = buffer.Skip(5).ToArray();
            string recvData = Encoding.UTF8.GetString(restData);

            string[] dataFrag;
            string   serverData, playerData, teamData;

            if (IsServerDataValid(recvData, out dataFrag))
            {
                serverData = dataFrag[0];
                playerData = dataFrag[1];
                teamData   = dataFrag[2];
            }
            else
            {
                //we revieved a wrong data, we have to send challege to game server
                byte[] sendingBuffer = GenerateChallenge(recvKeys);

                server.SendAsync(endPoint, sendingBuffer);
                string errorMsg = string.Format("[HeartBeat] Invalid Server Data Received From {0}:{1}-{2}", server.Endpoint.Address, server.Endpoint.Port, dataFrag[0]);
                server.ToLog(errorMsg);
                return;
            }
            // We only care about the server data
            string[] serverDataFrag = serverData.Split(new string[] { "\x00" }, StringSplitOptions.None);
            //server.ToLog(LogLevel.Debug, string.Format("[QR] [HeartBeat] Data received From {0}", server.Socket.RemoteEndPoint.ToString()));
            server.ToLog(LogLevel.Debug, string.Format("[QR] [HeartBeat] server info:{0} \t player info:{1} \t team info:{2}", serverData, playerData, teamData));

            GameServerData gameServer = new GameServerData(server.Endpoint);

            // set the country based off ip address if its IPv4

            //we set the server variables
            SetServerVariables(gameServer, serverDataFrag, server.Endpoint);

            LogWriter.Log.Write("[QR] No impliment function for Heartbeatpacket!", LogLevel.Debug);
            //TODO
        }
Example #7
0
        void OnRequestPlayerReady(Notification note)
        {
            Message msg = note.GetMessage();

            using (ByteBuffer buff = new ByteBuffer(note.GetBytes()))
            {
                long roleId = buff.ReadLong();
                GameServerData.SetGameMemeberReady(roleId);
                GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponsePlayerReady, buff.Getbuffer()));

                if (GameServerData.IsAllReadyInGameRoom())
                {
                    ByteBuffer buffer = new ByteBuffer();
                    buffer.WriteInt32(GameServerData.GameRoom.Members.Count);
                    foreach (var mem in GameServerData.GameRoom.Members)
                    {
                        buffer.WriteLong(mem.Id);
                    }
                    GameServerNetwork.Instance.Broadcast(PtMessagePackage.Build((int)S2CMessageId.ResponseAllPlayerReady, buffer.Getbuffer()));
                }
            }
        }
Example #8
0
    public static void LoginOK(Packet _packet)
    {
        int          id         = _packet.ReadInt();
        string       token      = _packet.ReadString();
        ServerListUI serverList = UIManager.Instance.UIWindows["ServerList"].GetComponent <ServerListUI>();

        for (int i = 0; i < _packet.UnreadLength(); i += 3)
        {
            GameServerData data = new GameServerData();
            data.name = _packet.ReadString();
            data.ip   = _packet.ReadString();
            data.port = _packet.ReadInt();
            data.ping = data.getPing();
            serverList.servers.Add(data);
        }

        GameManager.Instance.id    = id;
        GameManager.Instance.token = token;
        Debug.Log($"ID: {id} \n TOKEN: {token}");
        UIManager.Instance.ChangeUIWindow("ServerList");
        serverList.GenerateListing();
        GameManager.Instance.hasToken = true;
    }
Example #9
0
    public void Start()
    {
        m_Server = new Server();
        m_Server.Start(IPAddress.Parse("192.168.18.56"), 10000);

        m_Server.ClientConnected += (send, msg) =>
        {
            var player = GameServerData.AddNewPlayer();
            PtMessagePackage package = PtMessagePackage.Build((int)S2CMessageId.ResponseClientConnected, new ByteBuffer().WriteLong(player.Id).Getbuffer());
            byte[]           byts    = PtMessagePackage.Write(package);
            NetworkStreamUtil.Write(msg.GetStream(), byts);
        };

        m_Server.ClientDisconnected += (send, msg) =>
        {
            UnityEngine.Debug.Log("ClientDisconnected" + msg.ToString());
        };

        m_Server.DataReceived += (send, msg) =>
        {
            m_QueueMsg.Enqueue(msg);
            TickDispatchMessages();
        };
    }
Example #10
0
 public static void UpdateServerOffline(GameServerData data)
 {
 }
 public void OnRemoveGameServer(NetConnection connection, GameServerData gameServer)
 {
     gameServers.Remove(connection.connectionId);
 }
 public void OnUpdateStateServer(NetConnection connection, GameServerData gameServer)
 {
     gameServers[connection.connectionId] = gameServer;
 }