Ejemplo n.º 1
0
        private void HandleAuthentication(object cliento)
        {
            var client = (NPHandler)cliento;

            using (var wc = new WebClient())
            {
                var authString = string.Format("{0}&&{1}", Message.username, Message.password);

                // TODO: properly implement all of this (error checking, ...)
                var resultString = wc.UploadString("http://auth.iw4.prod.fourdeltaone.net/remauth.php", authString);
                var result       = resultString.Split('#');
                var success      = false;
                var npid         = 0L;

                Log.Data(resultString);

                if (result[0] == "ok")
                {
                    success = true;
                    npid    = (0x110000100000000 | uint.Parse(result[2]));
                }

                var reply = MakeResponse <AuthenticateResultMessage>(client);
                reply.Message.result       = (success) ? 0 : 1;
                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
                };

                if (resultString.Contains("banned from this board"))
                {
                    reply.Message.result = 3;
                }

                client.Authenticated = success;
                client.NPID          = npid;
                NPSocket.SetClient(npid, client);

                reply.Send();
            }
        }
Ejemplo n.º 2
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.º 3
0
        private void HandleAuthentication(object cliento)
        {
            var client = (NPHandler)cliento;

            int  result = 1;
            long npid   = 0;
            bool valid  = false;

            if (Message.licenseKey != "")
            {
                var database = XNP.Create();
                var keys     = from key in database.LicenseKeys
                               where key.Key == Message.licenseKey
                               select key;

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

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

                    NPHandler existingClient = NPSocket.GetClient(npid);

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

                database.Dispose();
            }
            else
            {
                valid  = true;
                result = 0;
                npid   = 0x130000100000000 | (uint)Interlocked.Increment(ref _anonymousNPID);
            }

            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;
            NPSocket.SetClient(npid, client);
        }