Ejemplo n.º 1
0
        private void UpdateOtherInfo()
        {
            using (var db = new retrospyContext())
            {
                if (_request.HasPartnerIDFlag)
                {
                    _subProfile.Partnerid = _request.PartnerID;
                }

                if (_request.HasProductIDFlag)
                {
                    _subProfile.Productid = _request.ProductID;
                }

                if (_request.HasGameNameFlag)
                {
                    _subProfile.Gamename = _request.GameName;
                }

                if (_request.HasGamePortFlag)
                {
                    _subProfile.Port = _request.GamePort;
                }

                if (_request.HasCDKeyEncFlag)
                {
                    _subProfile.Cdkeyenc = _request.CDKeyEnc;
                }

                db.Subprofiles.Update(_subProfile);
                db.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        protected override void DataOperation(GStatsSession session, Dictionary <string, string> recv)
        {
            using (var db = new retrospyContext())
            {
                var result = from p in db.Pstorage
                             where p.Profileid == _profileid && p.Dindex == _dindex && p.Ptype == _ptype
                             select p;

                Pstorage ps;
                if (result.Count() == 0)
                {
                    //insert a new record in database
                    ps           = new Pstorage();
                    ps.Dindex    = _dindex;
                    ps.Profileid = _profileid;
                    ps.Ptype     = _ptype;
                    ps.Data      = _keyValueStr;
                    db.Pstorage.Add(ps);
                }
                else if (result.Count() == 1)
                {
                    //update an existed record in database
                    ps      = result.First();
                    ps.Data = _keyValueStr;
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        protected override void DataOperation()
        {
            using (var db = new retrospyContext())
            {
                var result = from p in db.Pstorage
                             where p.Profileid == _request.ProfileID &&
                             p.Dindex == _request.DataIndex &&
                             p.Ptype == (uint)_request.StorageType
                             select p;

                Pstorage ps;
                if (result.Count() == 0)
                {
                    //insert a new record in database
                    ps           = new Pstorage();
                    ps.Dindex    = _request.DataIndex;
                    ps.Profileid = _request.ProfileID;
                    ps.Ptype     = (uint)_request.StorageType;
                    ps.Data      = _request.KeyValueString;
                    db.Pstorage.Add(ps);
                }
                else if (result.Count() == 1)
                {
                    //update an existed record in database
                    ps      = result.First();
                    ps.Data = _request.KeyValueString;
                }

                db.SaveChanges();
            }
        }
Ejemplo n.º 4
0
        private void UpdateOtherInfo(Dictionary <string, string> _recv)
        {
            using (var db = new retrospyContext())
            {
                uint partnerid;

                if (_recv.ContainsKey("partnerid"))
                {
                    if (uint.TryParse(_recv["partnerid"], out partnerid))
                    {
                        _subProfiles.Partnerid = partnerid;
                    }
                    else
                    {
                        _errorCode = GPErrorCode.Parse;
                    }
                }

                uint productid;

                if (_recv.ContainsKey("productid"))
                {
                    if (uint.TryParse(_recv["productid"], out productid))
                    {
                        _subProfiles.Productid = productid;
                    }
                    else
                    {
                        _errorCode = GPErrorCode.Parse;
                    }
                }

                if (_recv.ContainsKey("gamename"))
                {
                    _subProfiles.Gamename = _recv["gamename"];
                }

                uint port;

                if (_recv.ContainsKey("port"))
                {
                    if (uint.TryParse(_recv["port"], out port))
                    {
                        _subProfiles.Port = port;
                    }
                    else
                    {
                        _errorCode = GPErrorCode.Parse;
                    }
                }

                if (_recv.ContainsKey("cdkeyenc"))
                {
                    _subProfiles.Cdkeyenc = _recv["cdkeyenc"];
                }
                db.Subprofiles.Update(_subProfiles);
                db.SaveChanges();
            }
        }
 protected override void DataOperation()
 {
     try
     {
         using (var db = new retrospyContext())
         {
             db.Subprofiles.Where(s => s.Profileid == _session.UserInfo.Profileid && s.Namespaceid == _session.UserInfo.NamespaceID)
             .First().Uniquenick = _recv["uniquenick"];
             db.SaveChanges();
         }
     }
     catch (Exception)
     {
         _errorCode = GPErrorCode.DatabaseError;
     }
 }
 protected override void DataOperation()
 {
     try
     {
         using (var db = new retrospyContext())
         {
             db.Subprofiles.Where(s => s.Subprofileid == _session.UserData.SubProfileID)
             .FirstOrDefault().Uniquenick = _request.UniqueNick;
             db.SaveChanges();
         }
     }
     catch
     {
         _errorCode = GPError.DatabaseError;
     }
 }
        protected override void DataOperation()
        {
            using (var db = new retrospyContext())
            {
                var result = db.Subprofiles.Where(s => s.Profileid == _session.UserData.ProfileID &&
                                                  s.Namespaceid == _session.UserData.NamespaceID);
                //&& s.Productid == _session.UserInfo.ProductID);

                if (result.Count() == 0 || result.Count() > 1)
                {
                    _errorCode = GPError.DatabaseError;
                }

                db.Subprofiles.Where(s => s.Subprofileid == _session.UserData.SubProfileID)
                .FirstOrDefault().Cdkeyenc = _request.CDKeyEnc;

                db.SaveChanges();
            }
        }
Ejemplo n.º 8
0
 protected override void DataOperation()
 {
     using (var db = new retrospyContext())
     {
         if (_recv.ContainsKey("replace"))
         {
             db.Profiles.Where(p => p.Profileid == _session.UserInfo.Profileid &&
                               p.Nick == _recv["oldnick"]).First().Nick = _recv["nick"];
             db.SaveChanges();
         }
         else
         {
             Profiles profiles = new Profiles
             {
                 Profileid = _session.UserInfo.Profileid,
                 Nick      = _recv["nick"],
                 Userid    = _session.UserInfo.Userid
             };
             db.Add(profiles);
         }
     }
 }
Ejemplo n.º 9
0
        protected override void DataOperation()
        {
            using (var db = new retrospyContext())
            {
                if (_request.IsReplaceNickName)
                {
                    var result = from p in db.Profiles
                                 where p.Profileid == _session.UserData.ProfileID &&
                                 p.Nick == _request.OldNick
                                 select p;

                    if (result.Count() != 1)
                    {
                        _errorCode = GPError.DatabaseError;
                    }
                    else
                    {
                        result.First().Nick = _request.NewNick;
                    }

                    db.Profiles.Where(p => p.Profileid == _session.UserData.ProfileID &&
                                      p.Nick == _request.OldNick).First().Nick = _request.NewNick;

                    db.SaveChanges();
                }
                else
                {
                    Profiles profiles = new Profiles
                    {
                        Profileid = _session.UserData.ProfileID,
                        Nick      = _request.NewNick,
                        Userid    = _session.UserData.UserID
                    };

                    db.Add(profiles);
                }
            }
        }
Ejemplo n.º 10
0
        private void DatabaseOperationByType()
        {
            using (var db = new retrospyContext())
            {
                switch (_newUserStatus.CheckAccount)
                {
                case _newUserStatus.CheckAccount:
                    var users = db.Users.Where(u => u.Email == _request.Email)
                                .Select(u => u);
                    if (users.Count() == 0)
                    {
                        goto case _newUserStatus.AccountNotExist;
                    }
                    else if (users.Count() == 1)
                    {
                        _user = users.First();
                        goto case _newUserStatus.AccountExist;
                    }
                    else
                    {
                        // double user in database
                        _errorCode = GPError.DatabaseError;
                        LogWriter.ToLog(LogEventLevel.Error, "There are two same records in User table!");
                        break;
                    }

                case _newUserStatus.AccountNotExist:
                    _user = new Users {
                        Email = _request.Email, Password = _request.Password
                    };
                    db.Users.Add(_user);
                    db.SaveChanges();
                    goto case _newUserStatus.CheckProfile;

                case _newUserStatus.AccountExist:

                    if (_user.Password != _request.Password)
                    {
                        _errorCode = GPError.NewUserBadPasswords;
                        break;
                    }
                    else
                    {
                        goto case _newUserStatus.CheckProfile;
                    }

                case _newUserStatus.CheckProfile:
                    var profiles = db.Profiles.Where(p => p.Userid == _user.Userid && p.Nick == _request.Nick);
                    if (profiles.Count() == 0)
                    {
                        goto case _newUserStatus.ProfileNotExist;
                    }
                    else if (profiles.Count() == 1)
                    {
                        //same nick name can not register two profiles
                        _profile = profiles.First();
                        goto case _newUserStatus.ProfileExist;
                    }
                    else
                    {
                        //there are two profiles we stop
                        _errorCode = GPError.DatabaseError;
                        LogWriter.ToLog(LogEventLevel.Error, "There are two same records in Profile table!");
                        break;
                    }

                case _newUserStatus.ProfileNotExist:
                    _profile = new Profiles {
                        Userid = _user.Userid, Nick = _request.Nick
                    };
                    db.Profiles.Add(_profile);
                    db.SaveChanges();
                    goto case _newUserStatus.CheckSubProfile;

                case _newUserStatus.ProfileExist:
                //we do nothing here

                case _newUserStatus.CheckSubProfile:
                    var subProfiles = db.Subprofiles
                                      .Where(s => s.Profileid == _profile.Profileid &&
                                             s.Namespaceid == _request.NamespaceID);
                    if (subProfiles.Count() == 0)
                    {
                        goto case _newUserStatus.SubProfileNotExist;
                    }
                    else if (subProfiles.Count() == 1)
                    {
                        _subProfile = subProfiles.First();
                        goto case _newUserStatus.SubProfileExist;
                    }
                    else
                    {
                        _errorCode = GPError.DatabaseError;
                        LogWriter.ToLog(LogEventLevel.Error, "There are two same records in SubProfile table!");
                        break;
                    }

                case _newUserStatus.SubProfileNotExist:
                    //we create subprofile and return
                    _subProfile = new Subprofiles
                    {
                        Profileid   = _profile.Profileid,
                        Uniquenick  = _request.Uniquenick,
                        Namespaceid = _request.NamespaceID
                    };

                    db.Subprofiles.Add(_subProfile);
                    db.SaveChanges();
                    break;

                case _newUserStatus.SubProfileExist:
                    _errorCode = GPError.NewUserUniquenickInUse;
                    break;
                }
            }
        }
Ejemplo n.º 11
0
        protected override void DataOperation()
        {
            using (var db = new retrospyContext())
            {
                try
                {
                    switch (_newUserStatus.CheckAccount)
                    {
                    case _newUserStatus.CheckAccount:
                        int count = db.Users.Where(u => u.Email == _recv["email"]).Select(u => u).Count();
                        if (count == 0)
                        {
                            goto case _newUserStatus.AccountNotExist;
                        }
                        else
                        {
                            goto case _newUserStatus.AccountExist;
                        }

                    case _newUserStatus.AccountNotExist:
                        _users = new Users {
                            Email = _recv["email"], Password = _recv["passenc"]
                        };
                        db.Users.Add(_users);
                        db.SaveChanges();
                        goto case _newUserStatus.CheckProfile;

                    case _newUserStatus.AccountExist:
                        //we have to check password correctness
                        _users = db.Users.Where(u => u.Email == _recv["email"] && u.Password == _recv["passenc"]).FirstOrDefault();
                        if (_users == null)
                        {
                            _errorCode = GPErrorCode.NewUserBadPasswords;
                            break;
                        }
                        else
                        {
                            goto case _newUserStatus.CheckProfile;
                        }

                    case _newUserStatus.CheckProfile:
                        _profiles = db.Profiles.Where(p => p.Userid == _users.Userid && p.Nick == _recv["nick"]).FirstOrDefault();
                        if (_profiles == null)
                        {
                            goto case _newUserStatus.ProfileNotExist;
                        }
                        else
                        {
                            goto case _newUserStatus.ProfileExist;
                        }

                    case _newUserStatus.ProfileNotExist:
                        _profiles = new Profiles {
                            Userid = _users.Userid, Nick = _recv["nick"]
                        };
                        db.Profiles.Add(_profiles);
                        db.SaveChanges();
                        goto case _newUserStatus.CheckSubProfile;

                    case _newUserStatus.ProfileExist:
                    //we do nothing here

                    case _newUserStatus.CheckSubProfile:
                        _subProfiles = db.Subprofiles
                                       .Where(s => s.Profileid == _profiles.Profileid &&
                                              s.Uniquenick == _uniquenick &&
                                              s.Namespaceid == _namespaceid).FirstOrDefault();
                        if (_subProfiles == null)
                        {
                            goto case _newUserStatus.SubProfileNotExist;
                        }
                        else
                        {
                            goto case _newUserStatus.SubProfileExist;
                        }

                    case _newUserStatus.SubProfileNotExist:
                        //we create subprofile and return
                        _subProfiles = new Subprofiles
                        {
                            Profileid   = _profiles.Profileid,
                            Uniquenick  = _uniquenick,
                            Namespaceid = _namespaceid
                        };

                        db.Subprofiles.Add(_subProfiles);
                        db.SaveChanges();
                        break;

                    case _newUserStatus.SubProfileExist:
                        _errorCode = GPErrorCode.NewUserUniquenickInUse;
                        break;
                    }
                }
                catch (Exception)
                {
                    _errorCode = GPErrorCode.DatabaseError;
                }

                //update other information
                if (_errorCode != GPErrorCode.DatabaseError)
                {
                    UpdateOtherInfo(_recv);
                }
            }
        }
        protected override void DataOperation()
        {
            base.DataOperation();
            using (var db = new retrospyContext())
            {
                var result = db.Statusinfo
                             .Where(s => s.Profileid == _session.UserData.ProfileID &&
                                    s.Namespaceid == _session.UserData.NamespaceID)
                             .Select(s => s);



                if (result.Count() == 0)
                {
                    Statusinfo statusinfo = new Statusinfo
                    {
                        Profileid   = _session.UserData.ProfileID,
                        Namespaceid = _session.UserData.NamespaceID,
                        Productid   = _session.UserData.ProductID,
                        Statusstate = _request.StatusState,
                        //buddyip
                        //buddyport
                        Hostip         = _request.HostIP,
                        Hostprivateip  = _request.HostPrivateIP,
                        Queryreport    = _request.QueryReportPort,
                        Hostport       = _request.HostPort,
                        Sessionflags   = _request.SessionFlags,
                        Richstatus     = _request.RichStatus,
                        Gametype       = _request.GameType,
                        Gamevariant    = _request.GameVariant,
                        Gamemapname    = _request.GameMapName,
                        Quietmodefalgs = _request.QuietModeFlags
                    };

                    db.Statusinfo.Add(statusinfo);

                    db.SaveChanges();
                }
                else if (result.Count() == 1)
                {
                    result.First().Profileid   = _session.UserData.ProfileID;
                    result.First().Namespaceid = _session.UserData.NamespaceID;
                    result.First().Productid   = _session.UserData.ProductID;
                    result.First().Statusstate = _request.StatusState;
                    //buddyip
                    //buddyport
                    result.First().Hostip         = _request.HostIP;
                    result.First().Hostprivateip  = _request.HostPrivateIP;
                    result.First().Queryreport    = _request.QueryReportPort;
                    result.First().Hostport       = _request.HostPort;
                    result.First().Sessionflags   = _request.SessionFlags;
                    result.First().Richstatus     = _request.RichStatus;
                    result.First().Gametype       = _request.GameType;
                    result.First().Gamevariant    = _request.GameVariant;
                    result.First().Gamemapname    = _request.GameMapName;
                    result.First().Quietmodefalgs = _request.QuietModeFlags;

                    db.SaveChanges();
                }
                else
                {
                    _errorCode = GPError.DatabaseError;
                }
            }
        }