Ejemplo n.º 1
0
        private void HandleAuthentication(object cliento)
        {
            var client   = (NPHandler)cliento;
            var database = XNP.Create();
            var keys     = from key in database.LicenseKeys
                           where key.Key == Message.licenseKey
                           select key;

            var  valid  = (keys.Count() == 1);
            var  result = (keys.Count() == 1) ? 0 : 1;
            long npid   = 0;

            if (valid)
            {
                npid = 0x120000100000000 | keys.First().ID;

                NPHandler existingClient = NPSocket.GetClient(npid);

                if (existingClient != null)
                {
                    existingClient.CloseConnection(true);
                }
            }

            var reply = MakeResponse <AuthenticateResultMessage>(client);

            reply.Message.result = result;

            if (valid)
            {
                reply.Message.npid         = (ulong)npid;
                reply.Message.sessionToken = new byte[16] {
                    0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };
            }
            else
            {
                reply.Message.npid         = (ulong)0;
                reply.Message.sessionToken = new byte[16] {
                    0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
                };
            }

            reply.Send();

            client.Authenticated = valid;
            client.NPID          = npid;

            database.Dispose();
        }
Ejemplo 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"));
        }
Ejemplo 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);
        }
Ejemplo n.º 4
0
        public override void Process(NPHandler client)
        {
            var ipNum  = (uint)IPAddress.NetworkToHostOrder(Message.clientIP);
            var ip     = new IPAddress(BitConverter.GetBytes(ipNum));
            var ticket = ReadTicket(Message.ticket);
            var npid   = Message.npid;

            if (npid == 0)
            {
                npid = ticket.clientID;
            }

            var valid   = false;
            var groupID = 0;

            if (ticket.version == 1)
            {
                if (client.NPID == (long)ticket.serverID)
                {
                    if (npid == ticket.clientID)
                    {
                        var remoteClient = NPSocket.GetClient((long)ticket.clientID);
                        remoteClient.CurrentServer = client.NPID;

                        if (remoteClient != null && !remoteClient.Unclean)
                        {
                            Log.Debug("Ticket auth: remote address " + remoteClient.Address.Address.ToString());
                            Log.Debug("Ticket auth: message address " + ip.ToString());

                            if (ipNum == 0 || remoteClient.Address.Address.Equals(ip))
                            {
                                valid = true;

                                groupID = remoteClient.GroupID;

                                Log.Debug("Successfully authenticated a ticket for client " + remoteClient.NPID.ToString("x16"));
                            }
                            else
                            {
                                Log.Debug("Ticket auth: IP address didn't match.");
                            }
                        }
                        else
                        {
                            Log.Debug("Ticket auth: no such client");
                        }
                    }
                    else
                    {
                        Log.Debug("Ticket auth: NPID didn't match.");
                    }
                }
                else
                {
                    Log.Debug("Ticket auth: server NPID didn't match.");
                }
            }
            else
            {
                Log.Debug("Ticket auth: version didn't match.");
            }

            var reply = MakeResponse <AuthenticateValidateTicketResultMessage>(client);

            reply.Message.result  = (valid) ? 0 : 1;
            reply.Message.groupID = groupID;
            reply.Message.npid    = npid;
            reply.Send();
        }
Ejemplo 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
            });
        }