예제 #1
0
        private static void smethod_23(Session session_0, ClientMessage clientMessage_0)
        {
            string str = clientMessage_0.ReadString();
            uint   num = clientMessage_0.ReadUnsignedInteger();

            using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
            {
                client.SetParameter("name", str);
                if (client.ExecuteQueryRow("SELECT id FROM islas WHERE nombre = @name AND id_parent = '0' LIMIT 1") != null)
                {
                    session_0.SendData(CreateIslandComposer.TakenNameComposer(), false);
                }
                else
                {
                    client.SetParameter("name", str);
                    client.SetParameter("model", num);
                    client.SetParameter("userid", session_0.CharacterId);
                    client.ExecuteNonQuery("INSERT INTO islas (nombre,modelo_area,id_usuario) VALUES (@name, @model, @userid)");
                    client.SetParameter("name", str);
                    DataRow row2 = client.ExecuteQueryRow("SELECT id FROM islas WHERE nombre = @name AND id_parent = '0' LIMIT 1");
                    if (row2 != null)
                    {
                        session_0.SendData(CreateIslandComposer.Compose((uint)row2["id"]), false);
                    }
                }
            }
        }
예제 #2
0
        public WiredData(uint ItemId, int Type)
        {
            mItemId = ItemId;
            mType   = Type;

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                MySqlClient.SetParameter("id", ItemId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM wired_items WHERE item_id = @id LIMIT 1");

                if (Row != null)
                {
                    GenerateWiredFromRow(Row);
                }
                else
                {
                    MySqlClient.SetParameter("id", ItemId);
                    MySqlClient.ExecuteNonQuery("INSERT INTO wired_items (item_id, data1, data2, data3, data4, data5, time) VALUES (@id, '','0','0', '0','', '0')");
                    mData1 = "";
                    mData2 = 0;
                    mData3 = 0;
                    mData4 = 0;
                    mData5 = "";
                    mTime  = 0;
                }
            }
        }
예제 #3
0
        public static CharacterInfo GetCharacterInfo(SqlDatabaseClient MySqlClient, uint CharacterId, uint LinkedClientId, bool IgnoreCache)
        {
            if (SessionManager.ContainsCharacterId(CharacterId))
            {
                Session Session = SessionManager.GetSessionByCharacterId(CharacterId);
                return(Session.CharacterInfo);
            }

            if (!IgnoreCache)
            {
                CharacterInfo CachedInfo = TryGetInfoFromCache(CharacterId);

                if (CachedInfo != null)
                {
                    return(CachedInfo);
                }
            }

            MySqlClient.SetParameter("id", CharacterId);
            DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM characters WHERE id = @id LIMIT 1");

            if (Row != null)
            {
                return(GenerateCharacterInfoFromRow(MySqlClient, LinkedClientId, Row));
            }

            return(null);
        }
예제 #4
0
        public static VoucherValueData GetVoucherValue(string Code)
        {
            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                MySqlClient.SetParameter("code", Code);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT value_credits,value_pixels,value_furni FROM vouchers WHERE code = @code AND enabled = '1' AND uses > 0 LIMIT 1");

                if (Row == null)
                {
                    return(null);
                }

                List <uint> FurniValue = new List <uint>();

                foreach (string FurniValueBit in Row["value_furni"].ToString().Split(','))
                {
                    uint NewValue = 0;
                    uint.TryParse(FurniValueBit, out NewValue);

                    if (NewValue > 0)
                    {
                        FurniValue.Add(NewValue);
                    }
                }

                return(new VoucherValueData((int)Row["value_credits"], (int)Row["value_pixels"], FurniValue));
            }
        }
예제 #5
0
        public static SpaceInfo GetSpaceInfo(uint SpaceId, bool IgnoreCache)
        {
            SpaceInstance instanceBySpaceId = SpaceManager.GetInstanceBySpaceId(SpaceId);

            if (instanceBySpaceId != null)
            {
                return(instanceBySpaceId.Info);
            }
            if (!IgnoreCache)
            {
                SpaceInfo info = smethod_1(SpaceId);
                if (info != null)
                {
                    return(info);
                }
            }
            using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
            {
                client.SetParameter("id", SpaceId);
                DataRow row = client.ExecuteQueryRow("SELECT * FROM escenarios WHERE id = @id LIMIT 1");
                if (row != null)
                {
                    return(GenerateSpaceInfoFromRow(row));
                }
            }
            return(null);
        }
예제 #6
0
        public static int GetAdministratorsCountFromDB()
        {
            DataRow row = null;

            try
            {
                using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
                {
                    row = client.ExecuteQueryRow("SELECT COUNT(*) FROM Administrator;");
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine(e.ToString(), Logger.LOG_LEVEL.WARN);
            }

            if (row == null)
            {
                return(-1);
            }

            int count;

            if (!Int32.TryParse(row[0].ToString(), out count))
            {
                return(-1);
            }

            return(count);
        }
예제 #7
0
 public static uint TryAuthenticate(SqlDatabaseClient MySqlClient, string Username, string Password, string RemoteAddress)
 {
     lock (object_0)
     {
         if (Password.Length < 4)
         {
             int_1++;
             return(0);
         }
         uint num = 0;
         MySqlClient.SetParameter("Username", Username);
         MySqlClient.SetParameter("Password", Password);
         DataRow row = MySqlClient.ExecuteQueryRow("SELECT id FROM usuarios WHERE usuario = @Username AND Password = @Password LIMIT 1");
         if (row != null)
         {
             num = (uint)row["id"];
             smethod_0(MySqlClient, num, RemoteAddress);
         }
         if (num <= 0)
         {
             int_1++;
             return(0);
         }
         if (SessionManager.ContainsCharacterId(num))
         {
             SessionManager.StopSession(SessionManager.GetSessionByCharacterId(num).UInt32_0);
         }
         Output.WriteLine(string.Concat(new object[] { "User ", Username, " (ID ", num, ") has logged in from ", RemoteAddress, "." }));
         int_0++;
         return(num);
     }
 }
예제 #8
0
 public static bool FriendshipExists(SqlDatabaseClient MySqlClient, uint UserId1, uint UserId2, bool ConfirmedOnly)
 {
     MySqlClient.SetParameter("user1", UserId1);
     MySqlClient.SetParameter("user2", UserId2);
     MySqlClient.SetParameter("confirmed", ConfirmedOnly ? 0 : 2);
     return(MySqlClient.ExecuteQueryRow("SELECT null FROM laptop_amigos WHERE id_usuario = @user1 AND id_amigo = @user2 AND aceptado != @confirmed OR id_amigo = @user1 AND id_usuario = @user2 AND aceptado != @confirmed LIMIT 1") != null);
 }
예제 #9
0
        public static RoomInfo GetRoomInfo(uint RoomId, bool IgnoreCache)
        {
            RoomInstance Instance = RoomManager.GetInstanceByRoomId(RoomId);

            if (Instance != null)
            {
                return(Instance.Info);
            }

            if (!IgnoreCache)
            {
                RoomInfo CachedInfo = TryGetInfoFromCache(RoomId);

                if (CachedInfo != null)
                {
                    return(CachedInfo);
                }
            }

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                MySqlClient.SetParameter("id", RoomId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM rooms WHERE id = @id LIMIT 1");

                if (Row != null)
                {
                    return(GenerateRoomInfoFromRow(Row));
                }
            }

            return(null);
        }
예제 #10
0
        public static uint GetFirstAdministratorAccount()
        {
            DataRow row = null;

            try
            {
                using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
                {
                    string sql = "SELECT m.id " +
                                 "FROM Administrator AS a " +
                                 "INNER JOIN Member AS m ON m.id = a.member_id " +
                                 "ORDER BY a.id " +
                                 "LIMIT 1;";
                    row = client.ExecuteQueryRow(sql);
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine(e.ToString(), Logger.LOG_LEVEL.WARN);
            }

            if (row == null)
            {
                return(0);
            }

            uint id;

            if (!UInt32.TryParse(row[0].ToString(), out id))
            {
                return(0);
            }

            return(id);
        }
예제 #11
0
        public static bool FriendshipExists(SqlDatabaseClient MySqlClient, uint UserId1, uint UserId2, bool ConfirmedOnly)
        {
            MySqlClient.SetParameter("user1", UserId1);
            MySqlClient.SetParameter("user2", UserId2);
            MySqlClient.SetParameter("confirmed", (ConfirmedOnly ? 0 : 2));

            return(MySqlClient.ExecuteQueryRow("SELECT null FROM messenger_friendships WHERE user_1_id = @user1 AND user_2_id = @user2 AND confirmed != @confirmed OR user_2_id = @user1 AND user_1_id = @user2 AND confirmed != @confirmed LIMIT 1") != null);
        }
예제 #12
0
        private static void smethod_24(Session session_0, ClientMessage clientMessage_0)
        {
            uint num = clientMessage_0.ReadUnsignedInteger();

            using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
            {
                client.SetParameter("islandid", num);
                DataRow island = client.ExecuteQueryRow("SELECT * FROM islas WHERE id = @islandid LIMIT 1");
                if (island != null)
                {
                    session_0.SendData(PreEnterIslandComposer.Compose(session_0.CharacterInfo, island), false);
                }
            }
        }
예제 #13
0
        public static LocalUser GetAdministratorFromDB(string userName, string password)
        {
            DataRow userRow = null;

            try
            {
                using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
                {
                    string sql = "SELECT m.id, m.name, m.role, m.profile_photo_format, a.date_added " +
                                 "FROM Administrator AS a " +
                                 "INNER JOIN Member AS m ON m.id = a.member_id " +
                                 "WHERE m.name = @user_name AND a.password_hash = @password_hash;";
                    client.SetParameter("@user_name", userName);
                    client.SetParameterByteArray("@password_hash", Convert.FromBase64String(password));

                    userRow = client.ExecuteQueryRow(sql);
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine(e.ToString(), Logger.LOG_LEVEL.WARN);
            }

            if (userRow == null)
            {
                return(null);
            }

            uint userId;

            if (!UInt32.TryParse(userRow["id"].ToString(), out userId))
            {
                return(null);
            }

            //uint profilePhoto = UInt32.TryParse(userRow["profile_photo"].ToString(), out profilePhoto) ? profilePhoto : 0;

            LocalUser newUser = new LocalUser();

            newUser.UserID              = userId;
            newUser.IsOwner             = true;
            newUser.Role                = userRow["role"].ToString();
            newUser.Name                = userRow["name"].ToString();
            newUser.ProfilePhotoFormat  = userRow["profile_photo_format"].ToString() == "2" ? "image/png" : "image/jpeg";
            newUser.ProfilePhoto        = URL_USER_IMAGE + userId.ToString() + URL_USER_PROFILE_IMAGE; // + userRow["profile_photo_path"];
            newUser.TimeRegisteredLocal = DateTime.Parse(userRow["date_added"].ToString());            // DateTime.ParseExact(userRow["date_added"].ToString(), "yyyy-MM-dd HH:mm:ss", null, DateTimeStyles.AssumeLocal);
            return(newUser);
        }
예제 #14
0
 private static uint smethod_1(string string_0)
 {
     if (WordFilterManager.ModeratorNames.Contains(string_0.ToLower()))
     {
         return(1);
     }
     using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
     {
         client.SetParameter("Username", string_0);
         if (client.ExecuteQueryRow("SELECT id FROM usuarios WHERE usuario = @Username LIMIT 1") != null)
         {
             return(1);
         }
     }
     return(0);
 }
예제 #15
0
        private static void smethod_3(Session session_0, ClientMessage clientMessage_0)
        {
            string str = InputFilter.FilterString(clientMessage_0.ReadString().Replace('%', ' '), false);

            if (str.Length >= 1)
            {
                CharacterInfo characterInfo = null;
                using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
                {
                    client.SetParameter("query", str);
                    DataRow row = client.ExecuteQueryRow("SELECT id FROM usuarios WHERE usuario = @query LIMIT 1");
                    if (row != null)
                    {
                        characterInfo = CharacterInfoLoader.GetCharacterInfo(client, (uint)row["id"]);
                    }
                }
                session_0.SendData(LaptopSearchResultComposer.Compose(characterInfo), false);
            }
        }
예제 #16
0
        private static void ProcessThread()
        {
            Int32 user_peak = 0;

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT sval FROM server_statistics WHERE skey = 'online_peak' LIMIT 1");
                if (Row != null)
                {
                    user_peak = Convert.ToInt32(Row[0]);
                }
            }

            while (Program.Alive)
            {
                using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
                {
                    MySqlClient.SetParameter("skey", "active_connections");
                    MySqlClient.SetParameter("sval", SessionManager.ActiveConnections);
                    MySqlClient.ExecuteNonQuery("UPDATE server_statistics SET sval = @sval WHERE skey = @skey LIMIT 1");

                    MySqlClient.SetParameter("skey", "stamp");
                    MySqlClient.SetParameter("sval", UnixTimestamp.GetCurrent());
                    MySqlClient.ExecuteNonQuery("UPDATE server_statistics SET sval = @sval WHERE skey = @skey LIMIT 1");

                    if (SessionManager.ActiveConnections > user_peak)
                    {
                        user_peak = SessionManager.ActiveConnections;

                        MySqlClient.SetParameter("skey", "online_peak");
                        MySqlClient.SetParameter("sval", user_peak);
                        MySqlClient.ExecuteNonQuery("UPDATE server_statistics SET sval = @sval WHERE skey = @skey LIMIT 1");

                        MySqlClient.SetParameter("skey", "online_peak_stamp");
                        MySqlClient.SetParameter("sval", UnixTimestamp.GetCurrent());
                        MySqlClient.ExecuteNonQuery("UPDATE server_statistics SET sval = @sval WHERE skey = @skey LIMIT 1");
                    }
                }

                Thread.Sleep(60 * 1000);
            }
        }
예제 #17
0
        public static SongData GetSong(uint SongId)
        {
            lock (mSyncRoot)
            {
                if (mSongCache.ContainsKey(SongId))
                {
                    double CacheTime = UnixTimestamp.GetCurrent() - mCacheTimer[SongId];

                    if (CacheTime >= CACHE_LIFETIME)
                    {
                        mSongCache.Remove(SongId);
                        mCacheTimer.Remove(SongId);
                    }
                    else
                    {
                        return(mSongCache[SongId]);
                    }
                }
            }

            SongData Song = null;

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                MySqlClient.SetParameter("id", SongId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM songs WHERE id = @id LIMIT 1");

                if (Row != null)
                {
                    Song = GetSongFromDataRow(Row);

                    lock (mSyncRoot)
                    {
                        mSongCache.Add(Song.Id, Song);
                        mCacheTimer.Add(Song.Id, UnixTimestamp.GetCurrent());
                    }
                }
            }

            return(Song);
        }
예제 #18
0
 public static uint TryAuthenticate(SqlDatabaseClient MySqlClient, string Username, string Password, string RemoteAddress)
 {
     try
     {
         lock (object_0)
         {
             if (Password.Length < 4)
             {
                 int_1++;
                 return(0);
             }
             uint num = 0;
             MySqlClient.SetParameter("Username", Username);
             MySqlClient.SetParameter("Password", Password);
             string  query = "SELECT id FROM usuarios WHERE usuario = '" + Username + "' AND password = '******' LIMIT 1";
             DataRow row   = MySqlClient.ExecuteQueryRow(query);
             if (row != null)
             {
                 num = uint.Parse(row["id"].ToString());
                 UpdateUser(MySqlClient, num, RemoteAddress);
             }
             if (num <= 0)
             {
                 int_1++;
                 return(0);
             }
             if (SessionManager.ContainsCharacterId(num))
             {
                 SessionManager.StopSession(SessionManager.GetSessionByCharacterId(num).Id);
             }
             Output.WriteLine(string.Concat(new object[] { "User ", Username, " (ID ", num, ") has logged in from ", RemoteAddress, "." }));
             int_0++;
             return(num);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return(0);
     }
 }
예제 #19
0
        /*public static int GetImagesByUserFromDB(uint userId, out List<String> images)
         * {
         *  images = new List<String>();
         *
         *  DataTable table = null;
         *  try
         *  {
         *      using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
         *      {
         *          client.SetParameter("@user_id", userId);
         *          table = client.ExecuteQueryTable("SELECT p.id " +
         *              "FROM Photo AS p " +
         *              "INNER JOIN Member AS m ON m.id = p.member_id " +
         *              "WHERE m.id = @user_id;");
         *
         *      }
         *  }
         *  catch (Exception e)
         *  {
         *      Logger.WriteLine(e.ToString(), Logger.LOG_LEVEL.WARN);
         *  }
         *
         *  if (table == null)
         *      return -1;
         *
         *  foreach (DataRow row in table.Rows)
         *  {
         *      images.Add(URL_TO_IMAGE + row["id"].ToString());
         *  }
         *
         *  return 0;
         * }*/

        public static int GetUserFromDB(uint userId, out LocalUser user)
        {
            DataRow row = null;

            user = null;

            try
            {
                using (SqlDatabaseClient client = SqlDatabaseManager.GetClient())
                {
                    client.SetParameter("@user_id", userId);
                    row = client.ExecuteQueryRow("SELECT m.id, m.name, m.role, m.profile_photo_format, a.id AS admin_id " +
                                                 "FROM Member AS m " +
                                                 "LEFT JOIN Administrator AS a ON m.id = a.member_id " +
                                                 "WHERE m.id = @user_id;");
                }
            }
            catch (Exception e)
            {
                Logger.WriteLine(e.ToString(), Logger.LOG_LEVEL.WARN);
            }

            if (row == null)
            {
                return(-1);
            }

            //uint profilePhoto = UInt32.TryParse(row["profile_photo"].ToString(), out profilePhoto) ? profilePhoto : 0;
            uint adminID = UInt32.TryParse(row["admin_id"].ToString(), out adminID) ? adminID : 0;

            user                    = new LocalUser();
            user.UserID             = userId;
            user.Role               = row["role"].ToString();
            user.IsOwner            = adminID > 0;
            user.Name               = row["name"].ToString();
            user.ProfilePhoto       = URL_USER_IMAGE + userId.ToString() + URL_USER_PROFILE_IMAGE;
            user.ProfilePhotoFormat = row["profile_photo_format"].ToString() == "2" ? "image/png" : "image/jpeg";

            return(0);
        }
예제 #20
0
        private static void IsNameTaken(Session Session, ClientMessage Message)
        {
            String Username = Message.PopString();

            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                MySqlClient.SetParameter("username", Username);
                DataRow Taken = MySqlClient.ExecuteQueryRow("SELECT null FROM characters WHERE username = @username LIMIT 1");
                if (Taken == null)
                {
                    ServerMessage awnser = new ServerMessage(571);
                    awnser.AppendInt32(0);
                    awnser.AppendStringWithBreak(Username);
                    awnser.AppendInt32(0);
                    Session.SendData(awnser);
                }
                else
                {
                    Session.SendData(NameTaken.Compose(Username));
                }
            }
        }
예제 #21
0
        public static CharacterInfo GetCharacterInfo(SqlDatabaseClient MySqlClient, uint CharacterId, uint LinkedClientId, bool IgnoreCache)
        {
            if (SessionManager.ContainsCharacterId(CharacterId))
            {
                return(SessionManager.GetSessionByCharacterId(CharacterId).CharacterInfo);
            }
            if (!IgnoreCache)
            {
                CharacterInfo info = smethod_1(CharacterId);
                if (info != null)
                {
                    return(info);
                }
            }
            MySqlClient.SetParameter("id", CharacterId);
            DataRow row = MySqlClient.ExecuteQueryRow("SELECT * FROM usuarios WHERE id = @id LIMIT 1");

            if (row != null)
            {
                return(GenerateCharacterInfoFromRow(MySqlClient, LinkedClientId, row));
            }
            return(null);
        }
예제 #22
0
        public Player LoadPlayer(int id)
        {
            Player player = null;

            try
            {
                using (SqlDatabaseClient mySqlClient = SqlDatabaseManager.GetClient())
                {
                    var    queryRow  = mySqlClient.ExecuteQueryRow("SELECT * FROM player_data WHERE player_data.PLAYER_ID=" + id);
                    string name      = queryRow["PLAYER_NAME"].ToString();
                    string sessionId = queryRow["SESSION_ID"].ToString();
                    int    clanId    = intConv(queryRow["CLAN_ID"]);
                    var    clan      = Main.Global.StorageManager.GetClan(clanId);

                    player = new Player(id, name, sessionId, clan);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                //new ExceptionLog("dbmanager", "Failed to load character...", e);
            }
            return(player);
        }
        /// <summary>
        /// Attemps to authenticate an user using an SSO (Single Sign On) ticket.
        /// </summary>
        /// <param name="Ticket">The ticket string.</param>
        /// <returns>Character id on success, 0 on authentication failure.</returns>
        public static uint TryAuthenticate(SqlDatabaseClient MySqlClient, string Ticket, string RemoteAddress)
        {
            lock (mAuthSyncRoot)
            {
                // Remove any spacing from single sign on ticket
                Ticket = Ticket.Trim();

                // Ensure the ticket meets the minimum length requirement
                if (Ticket.Length <= 5)
                {
                    mFailedLoginCount++;
                    Output.WriteLine("Login from " + RemoteAddress + " rejected: SSO ticket too short.");
                    return(0);
                }

                // Debug
                string DebugTicket = (string)ConfigManager.GetValue("debug.sso");
                if (DebugTicket.Length > 0 && Ticket == DebugTicket)
                {
                    return(1);
                }

                // Check the database for a matching single sign on ticket
                uint   UserId  = 0;
                string LogName = string.Empty;

                MySqlClient.SetParameter("ticket", Ticket);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT id,username FROM characters WHERE auth_ticket = @ticket LIMIT 1");

                if (Row != null)
                {
                    UserId  = (uint)Row["id"];
                    LogName = (string)Row["username"];

                    RemoveTicket(MySqlClient, (uint)Row["id"], RemoteAddress);
                }

                // Check if ticket was OK + Check for user id bans
                if (UserId <= 0)
                {
                    mFailedLoginCount++;
                    Output.WriteLine("Login from " + RemoteAddress + " rejected: invalid SSO ticket.");
                    return(0);
                }

                if (ModerationBanManager.IsUserIdBlacklisted(UserId))
                {
                    mFailedLoginCount++;
                    Output.WriteLine("Login from " + RemoteAddress + " rejected: blacklisted IP address.");
                    return(0);
                }

                // Disconnect any previous sessions for this account
                if (SessionManager.ContainsCharacterId(UserId))
                {
                    Session TargetSession = SessionManager.GetSessionByCharacterId(UserId);
                    SessionManager.StopSession(TargetSession.Id);
                }

                // Mark as a successful login and continue

                Output.WriteLine("User " + LogName + " (ID " + UserId + ") has logged in from " + RemoteAddress + ".");
                MySqlClient.ExecuteNonQuery("UPDATE characters SET online = '1' WHERE id = " + UserId + " LIMIT 1");
                mSuccessfulLoginCount++;
                return(UserId);
            }
        }
예제 #24
0
        public void TryAuthenticate(string Ticket, string RemoteAddress)
        {
            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                uint AuthedUid = SingleSignOnAuthenticator.TryAuthenticate(MySqlClient, Ticket, RemoteAddress);

                if (AuthedUid <= 0)
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                CharacterInfo Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, AuthedUid, mId, true);

                if (Info == null || !Info.HasLinkedSession) // not marked online = CharacterInfoLoader failed somehow
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo = Info;

                mAchieventCache = new AchievementCache(MySqlClient, CharacterId);
                mBadgeCache     = new BadgeCache(MySqlClient, CharacterId, mAchieventCache);

                if (!HasRight("login"))
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo.TimestampLastOnline = UnixTimestamp.GetCurrent();

                CharacterResolverCache.AddToCache(mCharacterInfo.Id, mCharacterInfo.Username, true);

                mMessengerFriendCache = new SessionMessengerFriendCache(MySqlClient, CharacterId);
                mFavoriteRoomsCache   = new FavoriteRoomsCache(MySqlClient, CharacterId);
                mRatedRoomsCache      = new RatedRoomsCache();
                mInventoryCache       = new InventoryCache(MySqlClient, CharacterId);
                mIgnoreCache          = new UserIgnoreCache(MySqlClient, CharacterId);
                mNewItemsCache        = new NewItemsCache(MySqlClient, CharacterId);
                mAvatarEffectCache    = new AvatarEffectCache(MySqlClient, CharacterId);
                mQuestCache           = new QuestCache(MySqlClient, CharacterId);
                mPetCache             = new PetInventoryCache(MySqlClient, CharacterId);

                // Subscription manager
                MySqlClient.SetParameter("userid", CharacterId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM user_subscriptions WHERE user_id = @userid");

                mSubscriptionManager = (Row != null ? new ClubSubscription(CharacterId,
                                                                           (ClubSubscriptionLevel)int.Parse((Row["subscription_level"].ToString())), (double)Row["timestamp_created"],
                                                                           (double)Row["timestamp_expire"], (double)Row["past_time_hc"], (double)Row["past_time_vip"]) :
                                        new ClubSubscription(CharacterId, ClubSubscriptionLevel.None, 0, 0, 0, 0));

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_VipClub");
                }

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.BasicClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_BasicClub");
                }

                mAvatarEffectCache.CheckEffectExpiry(this);

                mAuthProcessed = true;

                SendData(AuthenticationOkComposer.Compose());
                SendData(FuseRightsListComposer.Compose(this));
                SendData(UserHomeRoomComposer.Compose(mCharacterInfo.HomeRoom));
                SendData(UserEffectListComposer.Compose(AvatarEffectCache.Effects));
                SendData(NavigatorFavoriteRoomsComposer.Compose(FavoriteRoomsCache.FavoriteRooms));
                SendData(InventoryNewItemsComposer.Compose(NewItemsCache.NewItems));
                SendData(AchievementDataListComposer.Compose(AchievementManager.Achievements.Values.ToList()));

                SendData(AvailabilityStatusMessageComposer.Compose());
                SendData(InfoFeedEnableMessageComposer.Compose(1));
                SendData(ActivityPointsMessageComposer.Compose());

                if (HasRight("moderation_tool"))
                {
                    SendData(ModerationToolComposer.Compose(this, ModerationPresets.UserMessagePresets,
                                                            ModerationPresets.UserActionPresets, ModerationPresets.RoomMessagePresets));

                    foreach (ModerationTicket ModTicket in ModerationTicketManager.ActiveTickets)
                    {
                        SendData(ModerationTicketComposer.Compose(ModTicket));
                    }
                }

                MessengerHandler.MarkUpdateNeeded(this, 0, true);
            }
        }
예제 #25
0
파일: Session.cs 프로젝트: habb0/Snowlight
        public void TryAuthenticate(string Ticket, string RemoteAddress)
        {
            using (SqlDatabaseClient MySqlClient = SqlDatabaseManager.GetClient())
            {
                uint AuthedUid = SingleSignOnAuthenticator.TryAuthenticate(MySqlClient, Ticket, RemoteAddress);

                if (AuthedUid <= 0)
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                CharacterInfo Info = CharacterInfoLoader.GetCharacterInfo(MySqlClient, AuthedUid, mId, true);

                if (Info == null || !Info.HasLinkedSession) // not marked online = CharacterInfoLoader failed somehow
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo = Info;

                mAchieventCache = new AchievementCache(MySqlClient, CharacterId);
                mBadgeCache     = new BadgeCache(MySqlClient, CharacterId, mAchieventCache);

                if (!HasRight("login"))
                {
                    SessionManager.StopSession(mId);
                    return;
                }

                mCharacterInfo.TimestampLastOnline = UnixTimestamp.GetCurrent();

                CharacterResolverCache.AddToCache(mCharacterInfo.Id, mCharacterInfo.Username, true);

                mMessengerFriendCache = new SessionMessengerFriendCache(MySqlClient, CharacterId);
                mFavoriteRoomsCache   = new FavoriteRoomsCache(MySqlClient, CharacterId);
                mRatedRoomsCache      = new RatedRoomsCache();
                mInventoryCache       = new InventoryCache(MySqlClient, CharacterId);
                mIgnoreCache          = new UserIgnoreCache(MySqlClient, CharacterId);
                mNewItemsCache        = new NewItemsCache(MySqlClient, CharacterId);
                mAvatarEffectCache    = new AvatarEffectCache(MySqlClient, CharacterId);
                mQuestCache           = new QuestCache(MySqlClient, CharacterId);
                mPetCache             = new PetInventoryCache(MySqlClient, CharacterId);

                // Subscription manager
                MySqlClient.SetParameter("userid", CharacterId);
                DataRow Row = MySqlClient.ExecuteQueryRow("SELECT * FROM user_subscriptions WHERE user_id = @userid");

                mSubscriptionManager = (Row != null ? new ClubSubscription(CharacterId,
                                                                           (ClubSubscriptionLevel)int.Parse((Row["subscription_level"].ToString())), (double)Row["timestamp_created"],
                                                                           (double)Row["timestamp_expire"], (double)Row["past_time_hc"], (double)Row["past_time_vip"]) :
                                        new ClubSubscription(CharacterId, ClubSubscriptionLevel.None, 0, 0, 0, 0));

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.VipClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_VipClub");
                }

                if (mSubscriptionManager.SubscriptionLevel < ClubSubscriptionLevel.BasicClub)
                {
                    mBadgeCache.DisableSubscriptionBadge("ACH_BasicClub");
                }

                mAvatarEffectCache.CheckEffectExpiry(this);

                mAuthProcessed = true;

                SendData(AuthenticationOkComposer.Compose());
                SendData(FuseRightsListComposer.Compose(this));
                SendData(UserHomeRoomComposer.Compose(mCharacterInfo.HomeRoom));
                SendData(UserEffectListComposer.Compose(AvatarEffectCache.Effects));
                SendData(NavigatorFavoriteRoomsComposer.Compose(FavoriteRoomsCache.FavoriteRooms));
                SendData(InventoryNewItemsComposer.Compose(NewItemsCache.NewItems));
                SendData(MessageOfTheDayComposer.Compose("Welcome to uberHotel.org BETA.\n\n\nThank you for participating in the uberHotel.org BETA test. We hope to gather relevant feedback and ideas to help make this hotel into a success.\n\nPlease submit any bugs, feedback, or ideas via:\nhttp://snowlight.uservoice.com\n\n\nHave fun, and thank you for joining us!"));
                SendData(AchievementDataListComposer.Compose(AchievementManager.Achievements.Values.ToList()));

                // This is available status packet (AvailabilityStatusMessageComposer)
                ServerMessage UnkMessage2 = new ServerMessage(290);
                UnkMessage2.AppendInt32(1);
                UnkMessage2.AppendInt32(0);
                SendData(UnkMessage2);

                // This is info feed packet (InfoFeedEnableMessageComposer)
                ServerMessage UnkMessage3 = new ServerMessage(517);
                UnkMessage3.AppendInt32(1); // 1 = enabled     0 = disabled  (true/false)
                SendData(UnkMessage3);

                // This is activity points message (ActivityPointsMessageComposer)  not sure how this is handled...
                ServerMessage UnkMessage4 = new ServerMessage(628);
                UnkMessage4.AppendInt32(1);
                UnkMessage4.AppendInt32(0);
                UnkMessage4.AppendInt32(2971);
                SendData(UnkMessage4);

                SendData(ClientConfigComposer.Compose(CharacterInfo.ConfigVolume, false));

                if (HasRight("moderation_tool"))
                {
                    SendData(ModerationToolComposer.Compose(this, ModerationPresets.UserMessagePresets,
                                                            ModerationPresets.UserActionPresets, ModerationPresets.RoomMessagePresets));

                    foreach (ModerationTicket ModTicket in ModerationTicketManager.ActiveTickets)
                    {
                        SendData(ModerationTicketComposer.Compose(ModTicket));
                    }
                }

                MessengerHandler.MarkUpdateNeeded(this, 0, true);
            }
        }