Ejemplo n.º 1
0
        public static void SendBlockList(GPCMSession session)
        {
            if (session.PlayerInfo.BlockListSent)
            {
                return;
            }
            session.PlayerInfo.BlockListSent = true;

            string sendingBuffer = @"\blk\";
            Dictionary <string, object> result = SendBlockListQuery.SearchBlockList(session.PlayerInfo.Profileid, session.PlayerInfo.NamespaceID);

            uint[] profileids;
            if (result != null)
            {
                profileids     = result.Values.Cast <uint>().ToArray();
                sendingBuffer += result.Count + @"\list\";
                for (int i = 0; i < profileids.Length; i++)
                {
                    //last one we do not add ,
                    if (i == profileids.Length - 1)
                    {
                        sendingBuffer += profileids[i];
                        break;
                    }
                    sendingBuffer += profileids[i] + @",";
                }
                sendingBuffer += @"\final\";
            }
            else
            {
                sendingBuffer = @"\blk\0\list\\final\";
            }

            session.SendAsync(sendingBuffer);
        }
Ejemplo n.º 2
0
        public static void UpdateStatus(GPCMSession session, Dictionary <string, string> recv)
        {
            //TODO
            _recv = recv;
            if (!IsContainAllKey())
            {
                return;
            }

            ushort sessionkey;

            if (!ushort.TryParse(recv["sesskey"], out sessionkey))
            {
                return;
            }
            // Invalid session key
            // Are you trying to update another user?
            //you can only update your status.?
            if (sessionkey != session.PlayerInfo.SessionKey)
            {
                return;
            }
            //update the status in playerinfomation.
            //notify all user in that namespace who have this friend.


            //StatusQuery.UpdateStatus(session.PlayerInfo,Convert.ToUInt32(recv["status"]),recv["statstring"],recv["locstring"]);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Tell server send back extra information according to the number of  sdkrevision
        /// </summary>
        public static void Switch(GPCMSession session, Dictionary <string, string> recv)
        {
            switch (Convert.ToInt32(session.PlayerInfo.SDKRevision))
            {
            case Type1:
                SendBuddiesHandler.SendBuddyList(session);
                SendBlockListHandler.SendBlockList(session);
                break;

            case Type2:
                SendBuddiesHandler.SendBuddyList(session);
                SendBlockListHandler.SendBlockList(session);
                break;

            case Type3:
                SendBuddiesHandler.SendBuddyList(session);
                break;

            case Type4:
                SendBuddiesHandler.SendBuddyList(session);
                break;

            default:
                session.ToLog("No sdkrevision found");
                break;
            }
        }
Ejemplo n.º 4
0
        protected override void CheckRequest(GPCMSession session)
        {
            // for pass operation id to session,Playerinfo
            base.CheckRequest(session);

            // Make sure we have all the required data to process this login
            if (!_recv.ContainsKey("challenge") || !_recv.ContainsKey("response"))
            {
                _errorCode = GPErrorCode.Parse;
                // session.PlayerInfo.DisconReason = DisconnectReason.InvalidLoginQuery;
                return;
            }
            if (_recv.ContainsKey("partnerid"))
            {
                if (!uint.TryParse(_recv["partnerid"], out session.PlayerInfo.PartnerID))
                {
                    _errorCode = GPErrorCode.Parse;
                    // session.PlayerInfo.DisconReason = DisconnectReason.InvalidLoginQuery;
                }
            }

            ParseDataBasedOnLoginType(session);

            ParseOtherData(session);
        }
Ejemplo n.º 5
0
 public static void ChangeNick(GPCMSession session, Dictionary <string, string> recv)
 {
     //create a new profile with new nick
     // @"  \newprofile\sesskey\<>\nick\<>\id\1\final\"
     //replace a existed nick with new nick
     //@"  \newprofile\sesskey\<>\nick\<>\replace\1\oldnick\<>\id\1\final\"
 }
Ejemplo n.º 6
0
        protected override void ConstructResponse(GPCMSession session)
        {
            session.PlayerInfo.SessionKey = _crc.ComputeChecksum(session.PlayerInfo.Nick + session.PlayerInfo.NamespaceID);
            string responseProof = ChallengeProof.GenerateProof
                                   (
                session.PlayerInfo.UserData,
                session.PlayerInfo.LoginType,
                session.PlayerInfo.PartnerID,
                session.PlayerInfo.ServerChallenge,
                session.PlayerInfo.UserChallenge,
                session.PlayerInfo.PasswordHash
                                   );

            _sendingBuffer  = @"\lc\2\sesskey\" + session.PlayerInfo.SessionKey;
            _sendingBuffer += @"\proof\" + responseProof;
            _sendingBuffer += @"\userid\" + _result[0]["userid"];
            _sendingBuffer += @"\profileid\" + _result[0]["profileid"];

            if (session.PlayerInfo.LoginType != LoginType.Nick)
            {
                _sendingBuffer += @"\uniquenick\" + _result[0]["uniquenick"];
            }

            _sendingBuffer += @"\lt\" + session.Id.ToString().Replace("-", "").Substring(0, 22) + "__";
            _sendingBuffer += @"\id\" + _operationID + @"\final\";

            session.PlayerInfo.LoginProcess = LoginStatus.Completed;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Send a presence error
        /// </summary>
        /// <param name="session">The stream that will receive the error</param>
        /// <param name="errorCode">The error code</param>
        /// <param name="operationID">The operation id</param>
        public static void SendGPCMError(GPCMSession session, GPErrorCode errorCode, uint operationID)
        {
            string errorMsg      = ErrorMsg.GetErrorMsg(errorCode);
            string sendingBuffer = string.Format(@"\error\\err\{0}\fatal\\errmsg\{1}\id\{2}\final\", (uint)errorCode, errorMsg, operationID);

            session.SendAsync(sendingBuffer);
        }
Ejemplo n.º 8
0
        public override void Handle(GPCMSession session)
        {
            CheckRequest(session);
            if (_errorCode != GPErrorCode.NoError)
            {
                //TODO
                ErrorMsg.SendGPCMError(session, _errorCode, _operationID);
                return;
            }

            DataBaseOperation(session);
            if (_errorCode == GPErrorCode.DatabaseError)
            {
                //TODO
                ErrorMsg.SendGPCMError(session, _errorCode, _operationID);
                return;
            }

            ConstructResponse(session);
            if (_errorCode == GPErrorCode.ConstructResponseError)
            {
                ErrorMsg.SendGPCMError(session, _errorCode, _operationID);
                return;
            }

            Response(session);
        }
 public PCMCommandHandlerBase(ISession session, Dictionary <string, string> recv) : base(session)
 {
     _recv        = recv;
     _errorCode   = GPErrorCode.NoError;
     _operationID = 1;
     _namespaceid = 0;
     _session     = (GPCMSession)session.GetInstance();
 }
Ejemplo n.º 10
0
 protected virtual void Response(GPCMSession session)
 {
     if (_sendingBuffer == null)
     {
         return;
     }
     session.SendAsync(_sendingBuffer);
 }
Ejemplo n.º 11
0
 protected override void CheckRequest(GPCMSession session)
 {
     base.CheckRequest(session);
     if (!_recv.ContainsKey("profileid"))
     {
         _errorCode = GPErrorCode.Parse;
     }
 }
Ejemplo n.º 12
0
 protected virtual void CheckRequest(GPCMSession session)
 {
     if (_recv.ContainsKey("id"))
     {
         if (!ushort.TryParse(_recv["id"], out _operationID))
         {
             _errorCode = GPErrorCode.Parse;
         }
     }
 }
Ejemplo n.º 13
0
        //public static GPCMDBQuery DBQuery = null;
        public static void InvitePlayer(GPCMSession session, Dictionary <string, string> recv)
        {
            GPErrorCode error = IsContainAllKeys(recv);

            if (error != GPErrorCode.NoError)
            {
                GameSpyLib.Common.GameSpyUtils.SendGPError(session, error, "Parsing error in request");
            }
            //session.SendAsync(@"\pinvite\\sesskey\223\profileid\13\productid\1038\final\");
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Polls the connection, and checks for drops
 /// </summary>
 public static void SendKeepAlive(GPCMSession session)
 {
     if (session.PlayerInfo.LoginProcess == LoginStatus.Completed)
     {
         // Try and send a Keep-Alive
         try
         {
             session.Send(@"\ka\\final\");
         }
         catch
         {
             session.DisconnectByReason(DisconnectReason.KeepAliveFailed);
         }
     }
 }
Ejemplo n.º 15
0
        private void ParseDataBasedOnLoginType(GPCMSession session)
        {
            session.PlayerInfo.UserChallenge = _recv["challenge"];

            if (_recv.ContainsKey("uniquenick"))
            {
                session.PlayerInfo.LoginType  = LoginType.Uniquenick;
                session.PlayerInfo.UniqueNick = _recv["uniquenick"];
                session.PlayerInfo.UserData   = _recv["uniquenick"];
                return;
            }
            if (_recv.ContainsKey("authtoken"))
            {
                session.PlayerInfo.LoginType = LoginType.AuthToken;
                session.PlayerInfo.AuthToken = _recv["authtoken"];
                session.PlayerInfo.UserData  = _recv["authtoken"];
                return;
            }
            if (_recv.ContainsKey("user"))
            {
                session.PlayerInfo.LoginType = LoginType.Nick;
                session.PlayerInfo.UserData  = _recv["user"];
                string user = _recv["user"];

                int Pos = user.IndexOf('@');
                if (Pos == -1 || Pos < 1 || (Pos + 1) >= user.Length)
                {
                    // Ignore malformed user
                    // Pos == -1 : Not found
                    // Pos < 1 : @ or @example
                    // Pos + 1 >= Length : example@
                    _errorCode = GPErrorCode.LoginBadEmail;
                    return;
                }
                string nick  = user.Substring(0, Pos);
                string email = user.Substring(Pos + 1);

                session.PlayerInfo.Nick      = nick;
                session.PlayerInfo.Email     = email;
                session.PlayerInfo.LoginType = LoginType.Nick;
                return;
            }

            //if no login method found we can not continue.
            session.ToLog("Unknown login method detected!");
            _errorCode = GPErrorCode.Parse;
        }
Ejemplo n.º 16
0
        private void CheckUserBasedOnLoginType(GPCMSession session)
        {
            switch (session.PlayerInfo.LoginType)
            {
            case LoginType.Nick:
                _result = LoginQuery.GetUserFromNickAndEmail(session.PlayerInfo.NamespaceID, session.PlayerInfo.Nick, session.PlayerInfo.Email);
                break;

            case LoginType.Uniquenick:
                _result = LoginQuery.GetUserFromUniqueNick(session.PlayerInfo.UniqueNick, session.PlayerInfo.NamespaceID);
                break;

            case LoginType.AuthToken:
                _result = LoginQuery.GetPreAuthenticatedUser(session.PlayerInfo.AuthToken, session.PlayerInfo.PartnerID, session.PlayerInfo.NamespaceID);
                break;
            }
        }
Ejemplo n.º 17
0
        public static void Addfriends(GPCMSession session, Dictionary <string, string> recv)
        {
            _recv      = recv;
            _errorCode = GPErrorCode.NoError;

            //\addbuddy\\sesskey\<>\newprofileid\<>\reason\<>\final\
            IsContainAllKey();
            if (_errorCode != GPErrorCode.NoError)
            {
                return;
            }
            if (session.PlayerInfo.Profileid == Convert.ToUInt16(_recv["profileid"]))
            {
                //you can not add yourself friend
                return;
            }
            AddBuddyQuery.SaveAddBuddyRequest(session.PlayerInfo.Profileid, Convert.ToUInt16(_recv["newprofileid"]), session.PlayerInfo.NamespaceID, _recv["reason"]);
        }
Ejemplo n.º 18
0
 private void ParseOtherData(GPCMSession session)
 {
     if (_recv.ContainsKey("partnerid"))
     {
         // the default partnerid will be (uint)gamespy.
         session.PlayerInfo.PartnerID = Convert.ToUInt32(_recv["partnerid"]);
     }
     if (_recv.ContainsKey("namespaceid"))
     {
         // the default namespaceid = 0
         session.PlayerInfo.NamespaceID = Convert.ToUInt32(_recv["namespaceid"]);
     }
     //store sdkrevision
     if (_recv.ContainsKey("sdkrevision"))
     {
         session.PlayerInfo.SDKRevision = Convert.ToUInt32(_recv["sdkrevision"]);
     }
 }
Ejemplo n.º 19
0
        protected bool IsChallengeCorrect(GPCMSession session)
        {
            string response = ChallengeProof.GenerateProof
                              (
                session.PlayerInfo.UserData,
                session.PlayerInfo.LoginType,
                session.PlayerInfo.PartnerID,
                session.PlayerInfo.UserChallenge,
                session.PlayerInfo.ServerChallenge,
                session.PlayerInfo.PasswordHash
                              );

            if (_recv["response"] == response)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 20
0
        //**********************************************************
        //\bm\<MESSAGE>\f\<from profileid>\msg\<>\final\
        //\bm\<UTM>\f\<from profileid>\msg\<>\final\
        //\bm\<REQUEST>\f\<from profileid>\msg\|signed|\final\
        //\bm\<AUTH>\f\<from profileid>\final\
        //\bm\<REVOKE>\f\<from profileid>\final\
        //\bm\<STATUS>\f\<from profileid>\msg\|s|<status code>|ss|<status string>|ls|<location string>|ip|<>|p|<port>|qm|<quiet mode falgs>\final\
        //\bm\<INVITE>\f\<from profileid>\msg\|p|<productid>|l|<location string>
        //\bm\<ping>\f\<from profileid>\msg\final\
        //\bm\<pong>\f\<from profileid>\final\

        public static void SendBuddyList(GPCMSession session)
        {
            // \bdy\<number of friends>\list\<array of profileids>\
            //total number of friends
            // we have to separate friends by productid,namespaceid,partnerid,gamename
            //because you will have different friends in different game

            if (session.PlayerInfo.BuddiesSent)
            {
                return;
            }
            session.PlayerInfo.BuddiesSent = true;
            //return;
            string sendingBuffer = @"\bdy\";
            var    result        = SendBuddiesQuery.SearchBuddiesId(session.PlayerInfo.Profileid, session.PlayerInfo.NamespaceID);

            uint[] profileids;
            if (result != null)
            {
                //convert the object in dictionary to uint array
                profileids     = result.Values.Cast <uint>().ToArray();
                sendingBuffer += profileids.Length + @"\list\";
                for (int i = 0; i < profileids.Length; i++)
                {
                    //last one we do not add ,
                    if (i == profileids.Length - 1)
                    {
                        sendingBuffer += profileids[i];
                        break;
                    }
                    sendingBuffer += profileids[i] + @",";
                }

                sendingBuffer += @"\final\";
                session.SendAsync(sendingBuffer);
                //we send the player's status info to client
                SendBuddyStatusInfo(session, profileids);
            }
            else
            {
                sendingBuffer = @"\bdy\0\list\\final\";
                session.SendAsync(sendingBuffer);
            }
        }
Ejemplo n.º 21
0
        public static void SendBuddyStatusInfo(GPCMSession session, uint[] profileids)
        {
            Dictionary <string, object> result;

            foreach (uint profileid in profileids)
            {
                string sendingBuffer = @"\bm\" + (uint)GPBasic.BmStatus + @"\f\";
                result         = SendBuddiesQuery.GetStatusInfo(profileid, session.PlayerInfo.NamespaceID);
                sendingBuffer += profileid + @"\msg\";
                sendingBuffer += @"|s|" + Convert.ToUInt32(result["status"]);
                sendingBuffer += @"|ss|" + result["statstring"].ToString();
                sendingBuffer += @"|ls|" + result["location"].ToString();
                sendingBuffer += @"|ip|" + result["lastip"];
                sendingBuffer += @"|p|" + Convert.ToUInt32(result["port"]);
                sendingBuffer += @"|qm|" + result["quietflags"] + @"\final\";

                session.SendAsync(sendingBuffer);
            }
        }
Ejemplo n.º 22
0
        protected bool CheckAccount(GPCMSession session)
        {
            bool isVerified = Convert.ToBoolean(_result[0]["emailverified"]);
            bool isBanned   = Convert.ToBoolean(_result[0]["banned"]);

            if (!isVerified)
            {
                _errorCode = GPErrorCode.LoginBadEmail;
                return(false);
            }

            // Check the status of the account.
            // If the single profile is banned, the account or the player status
            if (isBanned)
            {
                _errorCode = GPErrorCode.LoginProfileDeleted;
                return(false);
            }

            return(true);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// Tell server send back extra information according to the number of  sdkrevision
        /// </summary>
        public static void ExtendedFunction(ISession client)
        {
            GPCMSession _session = (GPCMSession)client.GetInstance();

            if (_session.UserInfo.SDKRevision == 0)
            {
                LogWriter.ToLog(Serilog.Events.LogEventLevel.Error, "[SDKRev] No sdkrevision!");
                return;
            }

            if ((_session.UserInfo.SDKRevision ^ (uint)SDKRevisionType.GPINewAuthNotification) != 0)
            {
                //Send add friend request
            }

            if ((_session.UserInfo.SDKRevision ^ (uint)SDKRevisionType.GPINewRevokeNotification) != 0)
            {
                //send revoke request
            }

            if ((_session.UserInfo.SDKRevision ^ (uint)SDKRevisionType.GPINewStatusNotification) != 0)
            {
                //send new status info
            }

            if ((_session.UserInfo.SDKRevision ^ (uint)SDKRevisionType.GPINewListRetrevalOnLogin) != 0)
            {
                //send buddy list and block list
            }

            if ((_session.UserInfo.SDKRevision ^ (uint)SDKRevisionType.GPIRemoteAuthIDSNotification) != 0)
            {
                //Remote auth
            }

            if ((_session.UserInfo.SDKRevision ^ (uint)SDKRevisionType.GPINewCDKeyRegistration) != 0)
            {
                //register cdkey with product id
            }
        }
Ejemplo n.º 24
0
        protected override void DataBaseOperation(GPCMSession session)
        {
            CheckUserBasedOnLoginType(session);
            if (_result == null)
            {
                _errorCode = GPErrorCode.DatabaseError;
                return;
            }

            if (!CheckAccount(session))
            {
                return;
            }

            session.PlayerInfo.PasswordHash = _result[0]["password"].ToString();

            if (!IsChallengeCorrect(session))
            {
                //TODO check the challenge response correctness
                _errorCode = GPErrorCode.LoginBadLoginTicket;
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        /// update the uniquenick
        /// </summary>
        /// <param name="session"></param>
        /// <param name="dict"></param>
        public static void RegisterNick(GPCMSession session, Dictionary <string, string> dict)
        {
            GPErrorCode error = IsContainAllKeys(dict);

            if (error != GPErrorCode.NoError)
            {
                GameSpyUtils.SendGPError(session, error, "Parsing error");
                return;
            }
            string sendingBuffer;

            try
            {
                RegisterNickQuery.UpdateUniquenick(dict["uniquenick"], session.PlayerInfo.SessionKey, Convert.ToUInt16(dict["patnerid"]));
                sendingBuffer = @"\rn\final\";
                session.Send(sendingBuffer);
            }
            catch (Exception e)
            {
                LogWriter.Log.WriteException(e);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// Creates an account and use new account to login
        /// </summary>
        /// <param name="session">The client that sended the data</param>
        /// <param name="dict">The request that the stream sended</param>
        public static void NewUser(GPCMSession session, Dictionary <string, string> dict)
        {
            //Format the password for our database storage
            GPErrorCode error = IsRequestContainAllKeys(dict);

            //if there do not recieved right <key,value> pairs we send error
            if (error != GPErrorCode.NoError)
            {
                GameSpyUtils.SendGPError(session, error, "Error recieving request. Please check the input!");
                return;
            }

            //Check the nick and uniquenick is formated correct and uniquenick is existed in database
            string sendingBuffer;

            error = IsEmailNickUniquenickValied(dict);
            if (error != GPErrorCode.NoError)
            {
                sendingBuffer = string.Format(@"\nur\{0}\final\", (int)error);
                session.Send(sendingBuffer);
                return;
            }

            //if the request did not contain uniquenick and namespaceid we use our way to create it.
            PreProcessRequest(dict);
            //we get the userid in database. If no userid found according to email we create one
            //and store the new account into database.
            int profileid = CreateAccount(dict);

            if (profileid == -1)
            {
                GameSpyUtils.SendGPError(session, GPErrorCode.DatabaseError, "Account is existed, please use another one.");
            }
            else
            {
                sendingBuffer = string.Format(@"\nur\0\pid\{0}\final\", profileid);
                session.Send(sendingBuffer);
            }
        }
Ejemplo n.º 27
0
 protected override void Response(GPCMSession session)
 {
     base.Response(session);
     SDKRevision.Switch(session, _recv);
 }
Ejemplo n.º 28
0
 public static void UpdateUI(GPCMSession client, Dictionary <string, string> recv)
 {
     GameSpyUtils.PrintReceivedGPDictToLogger(recv);
     GameSpyUtils.SendGPError(client, GPErrorCode.General, "This request is not supported yet.");
 }
Ejemplo n.º 29
0
 public static void SendBuddyStatusInfo(GPCMSession session, Dictionary <string, string> recv)
 {
     _recv = recv;
 }
Ejemplo n.º 30
0
 public static void SendBuddyUTM(GPCMSession session, uint profileid)
 {
 }