Exemplo n.º 1
0
        public void CloseConnection(bool closeApp)
        {
            if (closeApp)
            {
                var closeMessage = new NPRPCResponse <CloseAppMessage>(this);
                closeMessage.Message.reason = "Another client connected with the same ID.";
                closeMessage.Send();
            }

            //NPSocket.Close(_client);
        }
Exemplo n.º 2
0
        public override void Process(NPHandler client)
        {
            if (!client.Authenticated)
            {
                return;
            }

            var npidTo   = (long)Message.npid;
            var clientTo = NPSocket.GetClient(npidTo);

            var response = new NPRPCResponse <MessagingSendDataMessage>(clientTo);

            response.Message.npid = (ulong)client.NPID;
            response.Message.data = Message.data;
            response.Send();

            Log.Info("sent instant message from " + client.NPID.ToString("X16") + " to " + npidTo.ToString("X16"));
        }
Exemplo n.º 3
0
        private void SendAuthResult(RPCAuthenticateWithTokenMessage message, NPHandler client, int userID, int group)
        {
            var reply = message.MakeResponse <AuthenticateResultMessage>(client);

            reply.Message.npid         = (ulong)0;
            reply.Message.sessionToken = new byte[16];

            if (userID > 0)
            {
                var npid = (0x110000100000000 | (uint)userID);

                var existingClient = NPSocket.GetClient(npid);
                //NPHandler existingClient = null;
                if (existingClient != null)
                {
                    //reply.Message.result = 4;
                    existingClient.CloseConnection(true);
                }

                reply.Message.result       = 0;
                reply.Message.npid         = (ulong)npid;
                reply.Message.sessionToken = message.Message.token;

                client.Authenticated = true;
                client.NPID          = npid;
                client.GroupID       = group;
                client.SessionToken  = Encoding.UTF8.GetString(message.Message.token);

                NPSocket.SetClient(npid, client);
            }
            else if (userID == 0)
            {
                reply.Message.result = 1;
            }
            else if (userID == -1)
            {
                reply.Message.result = 2;
            }

            reply.Send();

            if (group > 0)
            {
                var groupReply = new NPRPCResponse <AuthenticateUserGroupMessage>(client);
                groupReply.Message.groupID = group;
                groupReply.Send();
            }

            ThreadPool.QueueUserWorkItem(delegate(object cliento)
            {
                try
                {
                    var cclient = (NPHandler)cliento;
                    var uid     = (int)(cclient.NPID & 0xFFFFFFFF);

                    var db     = XNP.Create();
                    var result = from platform in db.ExternalPlatforms
                                 where platform.UserID == uid && platform.PlatformAuthenticated == 1
                                 select platform.PlatformID;

                    var value = 1;

                    if (result.Count() > 0)
                    {
                        value = 0;
                    }

                    Thread.Sleep(600);

                    var linkReply            = new NPRPCResponse <AuthenticateExternalStatusMessage>(cclient);
                    linkReply.Message.status = value;
                    linkReply.Send();
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }, client);
        }
Exemplo n.º 4
0
        public override void Process(NPHandler client)
        {
            var platformID = (long)Message.steamID;
            var userID     = (int)(client.NPID & 0xFFFFFFFF);
            var gdb        = XNP.Create();

            var currentLink = from link in gdb.ExternalPlatforms
                              where link.UserID == userID// && link.PlatformType == "steam"
                              select link;

            var newLink = new ExternalPlatforms();

            if (currentLink.Count() > 0)
            {
                newLink = currentLink.First();

                if (newLink.PlatformID == platformID && newLink.PlatformAuthenticated == 1)
                {
                    return;
                }

                //gdb.ExternalPlatforms.DeleteOnSubmit(newLink);
                gdb.SubmitChanges();

                newLink = new ExternalPlatforms();
            }

            newLink.UserID                = userID;
            newLink.PlatformType          = "steam";
            newLink.PlatformID            = platformID;
            newLink.PlatformAuthenticated = 0;

            if (currentLink.Count() == 0)
            {
                SteamFriendsLinker.UpdateForUser(userID, platformID);
                gdb.ExternalPlatforms.InsertOnSubmit(newLink);
            }

            gdb.SubmitChanges();

            ThreadPool.QueueUserWorkItem(delegate(object stateo)
            {
                var state  = (SteamAuthCheckState)stateo;
                var result = 3; // error occurred, magic numbers ftw

                try
                {
                    var wc       = new WebClient();
                    var gameList = wc.DownloadString(string.Format("http://steamcommunity.com/profiles/{0}/games?xml=1", state.platformID));

                    // we don't parse xml here, laziness...
                    var ownsTheGame = gameList.Contains(">10190<"); // >< is to prevent accidental hashes containing 10190

                    result = (ownsTheGame) ? 0 : 2;                 // 2 = doesn't own the game

                    // update the database too based on this
                    var db = XNP.Create();

                    var id = (state.client.NPID & 0xFFFFFFFF);

                    var clinks = from link in db.ExternalPlatforms
                                 where link.UserID == id
                                 select link;

                    if (clinks.Count() > 0)
                    {
                        var clink = clinks.First();
                        clink.PlatformAuthenticated = (sbyte)((ownsTheGame) ? 1 : 0);

                        db.SubmitChanges();
                    }
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }

                try
                {
                    var linkReply            = new NPRPCResponse <AuthenticateExternalStatusMessage>(client);
                    linkReply.Message.status = result;
                    linkReply.Send();
                }
                catch (Exception ex)
                {
                    Log.Error(ex.ToString());
                }
            }, new SteamAuthCheckState()
            {
                client     = client,
                platformID = platformID
            });
        }
Exemplo n.º 5
0
        public static void Handle(NPHandler client, string data)
        {
            var reason = int.Parse(data.Split(' ')[1]);

            if (reason == 0 || reason == 50001)
            {
                client.LastCI = DateTime.UtcNow;
                return;
            }

            ThreadPool.QueueUserWorkItem(stateo =>
            {
                var state = (CIReportState)stateo;

                if (client.Unclean)
                {
                    return;
                }

                // first, ban the player globally
                try
                {
                    using (var wc = new WebClient())
                    {
                        var url = string.Format("http://auth.iw4.prod.fourdeltaone.net/log.php?s={0}&r={1}", state.Client.SessionToken, state.Reason);
                        Log.Debug(url);
                        Log.Info(wc.DownloadString(url));
                    }
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }

                // then try to send a message to the server they're on
                Thread.Sleep(500);

                var serverID = state.Client.CurrentServer;
                var npID     = state.Client.NPID;

                try
                {
                    var remote                   = NPSocket.GetClient(serverID);
                    var message                  = new NPRPCResponse <AuthenticateKickUserMessage>(remote);
                    message.Message.npid         = (ulong)npID;
                    message.Message.reason       = 1;
                    message.Message.reasonString = string.Format("Cheat detected (#{0})", state.Reason);
                    message.Send();
                }
                catch (Exception e)
                {
                    Log.Error(e.ToString());
                }

                state.Client.Unclean = true;
            }, new CIReportState()
            {
                Client = client,
                Reason = reason
            });
        }