Exemplo n.º 1
0
        public static byte CreateNewChar(string strAccountID, string userID, byte nHair, short sClass, byte bCharIndex, byte bRace, byte bFace, byte str, byte sta, byte dex, byte intel, byte cha)
        {
            var AccountChar = m_GameDb.ACCOUNT_CHAR.Where(i => i.strAccountID == strAccountID).FirstOrDefault();

            if (AccountChar == null)
            {
                return(globals.NEWCHAR_DB_ERROR);
            }

            if ((bCharIndex == 0 && !string.IsNullOrWhiteSpace(AccountChar.strCharID1)) ||
                (bCharIndex == 1 && !string.IsNullOrWhiteSpace(AccountChar.strCharID2)) ||
                (bCharIndex == 2 && !string.IsNullOrWhiteSpace(AccountChar.strCharID3)))
            {
                return(globals.NEWCHAR_NO_MORE);
            }

            if (string.IsNullOrWhiteSpace(userID))
            {
                return(globals.NEWCHAR_INVALID_NAME);
            }

            if (m_GameDb.USERDATA.Where(i => i.strUserID == userID).Count() >= 1)
            {
                return(globals.NEWCHAR_BAD_NAME);
            }

            try
            {
                m_GameDb.Database.ExecuteSqlCommand("INSERT INTO USERDATA (strUserID, Nation, Race, Class, Face, HairR, HairG, HairB, Hair, Strong, Sta, Dex, Intel, Cha) " +
                                                    $"VALUES ('{userID}', {AccountChar.bNation}, {bRace}, {sClass}, {bFace}, {nHair}, 0, 0, {nHair}, {str}, {sta}, {dex}, {intel}, {cha})");

                m_GameDb.Database.ExecuteSqlCommand("INSERT INTO USER_QUEST (strUserID, strQuest, strAchievementStatics) VALUES ('" + userID + "', 0x00, 0x00)");
                m_GameDb.Database.ExecuteSqlCommand("INSERT INTO USER_SKILLSHORTCUT (UserID, SkillCount, SkillData) VALUES ('" + userID + "', 0, 0x00)");

                switch (bCharIndex)
                {
                case 0:
                    AccountChar.strCharID1 = userID;
                    break;

                case 1:
                    AccountChar.strCharID2 = userID;
                    break;

                case 2:
                    AccountChar.strCharID3 = userID;
                    break;
                }
                AccountChar.bCharNum++;

                m_GameDb.SaveChanges();
            }
            catch
            {
                return(globals.NEWCHAR_DB_ERROR);
            }
            return(globals.NEWCHAR_SUCCESS);
        }
Exemplo n.º 2
0
 public bool SetUser(User user)
 {
     using var db = new ServerDB();
     try
     {
         var currentUser = db.Users.Single(u => u.UserId == user.UserId);
         currentUser = user;
         db.SaveChanges();
         return(true);
     }catch (Exception e)
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 public User Register(string nickname, string password, string email)
 {
     using var db = new ServerDB();
     try
     {
         var user = new User()
         {
             Nickname  = nickname,
             Email     = email,
             IsBanned  = false,
             IsSpector = false,
             Password  = password,
             UserId    = db.Users.Count()
         };
         db.Users.Add(user);
         db.SaveChanges();
         return(user);
     }
     catch (Exception e)
     {
         //TODO: добавить агрументы.
         return(null);
     }
 }