Пример #1
0
 public static void RemoveClan(virtualUser User)
 {
     if (User.ClanID != -1)      // If user has a clan
     {
         if (User.ClanRank == 2) // If user is the master
         {
             /* Execute query for the database */
             DB.runQuery("DELETE FROM clans WHERE clanname='" + User.ClanName + "'");
             DB.runQuery("DELETE FROM clans_clanwars WHERE clanname1='" + User.ClanName + "' OR clanname2='" + User.ClanName + "'");
             DB.runQuery("UPDATE users SET clanid='-1', clanrank='-1' WHERE clanid='" + User.ClanID + "'");
             foreach (virtualUser Players in UserManager.getAllUsers())
             {
                 if (Players.ClanID == User.ClanID)
                 {
                     // If user is in the same clan of master updates live!
                     Players.send(new PACKET_CHAT("ClanSystem", PACKET_CHAT.ChatType.Clan, "ClanSystem >> " + User.Nickname + " disbanded the clan :(", Players.ClanID, "NULL"));
                     Players.ClanID     = -1;
                     Players.ClanRank   = -1;
                     Players.ClanIconID = -1;
                 }
             }
             // Remove the clan
             Clans.Remove(getClan(User.ClanID));
             User.send(new PACKET_CLAN());
             return;
         }
         else // If user has clan but isn't the master
         {
             User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Cannot delete the clan because you're not the master!", User.SessionID, User.Nickname));
         }
     }
 }
Пример #2
0
 public static void UpgradeClan(virtualUser User)
 {
     if (User.ClanID == -1)
     {
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> You doesn't own a clan!", User.SessionID, User.Nickname));
     }
     else if (User.ClanRank != 2)
     {
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> You're not the owner of the clan!", User.SessionID, User.Nickname));
     }
     else if (User.Cash - 10000 < 0)
     {
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Not enough money!", User.SessionID, User.Nickname));
     }
     else if (getClan(User.ClanID).maxUsers >= 100)
     {
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Your clan cannot be extended more!!", User.SessionID, User.Nickname));
     }
     else
     {
         int MaxUsers = getClan(User.ClanID).maxUsers;
         getClan(User.ClanID).maxUsers += 20;
         int NewMaxUsers = getClan(User.ClanID).maxUsers;
         foreach (virtualUser ClanUser in getClanUsers(User.ClanID))
         {
             ClanUser.send(new PACKET_CHAT("ClanSystem", PACKET_CHAT.ChatType.Clan, "ClanSystem >> " + User.Nickname + " has upgraded clan slots from: " + MaxUsers + " to: " + NewMaxUsers + ":)!", User.ClanID, "NULL"));
         }
         DB.runQuery("UPDATE clans SET maxusers=maxusers+20 WHERE id='" + User.ClanID + "'");
     }
 }
Пример #3
0
 public static void ChangeName(virtualUser User, string oldName, string newName)
 {
     string[] GetCheck = DB.runReadRow("SELECT * FROM clans WHERE clanname='" + newName + "'");
     if (GetCheck.Length == 0) // Prevent double clan name!
     {
         if (User.Cash - 5000 >= 0)
         {
             if (User.ClanRank == 5) // Check if user is master
             {
                 User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> You've changed clan name for 5,000 cash!", User.SessionID, User.Nickname));
                 foreach (virtualUser ClanUser in getClanUsers(User.ClanID))
                 {
                     ClanUser.ClanName = newName;
                     ClanUser.send(new PACKET_CHAT("ClanSystem", PACKET_CHAT.ChatType.Clan, "ClanSystem >> Clan name was changed from: " + oldName + " to: " + newName, ClanUser.ClanID, ClanUser.Nickname));
                 }
                 User.Cash -= 5000;
                 DB.runQuery("UPDATE users SET cash=cash-2500 WHERE id='" + User.UserID + "'");
                 DB.runQuery("UPDATE clans SET clanname='" + newName + "' WHERE id='" + User.ClanID + "'");
             }
             else
             {
                 User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> You cannot change the clan name because you're not the master!", User.SessionID, User.Nickname));
             }
         }
         else
         {
             User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Not enough cash!", User.SessionID, User.Nickname));
         }
     }
     else
     {
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> This clan name is already in use!", User.SessionID, User.Nickname));
     }
 }
Пример #4
0
        public override void Handle(virtualUser User)
        {
            try
            {
                if (User.Room != null)
                {
                    if (User.Room.PlayerCount < User.Room.MaxPlayers)
                    {
                        string Username = getNextBlock();
                        string Message  = getNextBlock();

                        if (Username == "NULL") // Send Random User
                        {
                            System.Collections.ArrayList _ValidPlayers = new System.Collections.ArrayList();
                            foreach (virtualUser _User in Managers.UserManager.getAllUsers())
                            {
                                if (_User != null && _User.Room == null && _User.Channel == User.Channel)
                                {
                                    _ValidPlayers.Add(_User);
                                }
                            }

                            if (_ValidPlayers.Count > 0)
                            {
                                int rPlayer = new System.Random().Next(0, _ValidPlayers.Count - 1);

                                virtualUser _Target = (virtualUser)_ValidPlayers[rPlayer];
                                if (_Target != null)
                                {
                                    _Target.send(new Packets.PACKET_ROOM_INVITE(User, Message));
                                    User.send(new Packets.PACKET_ROOM_INVITE(Packets.PACKET_ROOM_INVITE.ErrorCodes.Invited));
                                }
                            }
                        }
                        else
                        { // Match User
                            foreach (virtualUser _User in Managers.UserManager.getAllUsers())
                            {
                                if (_User.Nickname.ToLower() == Username.ToLower())
                                {
                                    if (_User.Room == null)
                                    {
                                        _User.send(new Packets.PACKET_ROOM_INVITE(User, Message));
                                        User.send(new Packets.PACKET_ROOM_INVITE(User, Message));
                                        return;
                                    }
                                    else
                                    {
                                        User.send(new Packets.PACKET_ROOM_INVITE(Packets.PACKET_ROOM_INVITE.ErrorCodes.IsPlaying));
                                        return;
                                    }
                                }
                            }
                            User.send(new Packets.PACKET_ROOM_INVITE(Packets.PACKET_ROOM_INVITE.ErrorCodes.GenericError));
                        }
                    }
                }
            }
            catch { }
        }
Пример #5
0
        public override void Handle(virtualUser User)
        {
            int    ID             = Convert.ToInt32(getBlock(0));
            int    Days           = 0;
            int    CouponToRemove = 0;
            string WeaponToBuy    = null;

            #region Calculate
            switch (ID)
            {
            case 0: WeaponToBuy = "DS01"; Days = 3; CouponToRemove = 5; break;

            case 1: WeaponToBuy = "DS10"; Days = 3; CouponToRemove = 10; break;

            case 2: WeaponToBuy = "DS03"; Days = 3; CouponToRemove = 10; break;

            case 3: WeaponToBuy = "DF15"; Days = 3; CouponToRemove = 20; break;

            case 4: WeaponToBuy = "DG40"; Days = 3; CouponToRemove = 25; break;

            case 5: WeaponToBuy = "DJ35"; Days = 3; CouponToRemove = 30; break;

            case 6: WeaponToBuy = "CC41"; Days = 1; CouponToRemove = 30; break;

            case 7: WeaponToBuy = "DG22"; Days = 3; CouponToRemove = 35; break;

            case 8: WeaponToBuy = "DC77"; Days = 7; CouponToRemove = 45; break;

            default: User.disconnect(); break;
            }
            #endregion
            if (User.Coupons >= CouponToRemove)
            {
                int InventorySlot = User.InventorySlots;
                if (InventorySlot > 0)
                {
                    User.Coupons -= CouponToRemove;
                    DB.runQuery("UPDATE users SET coupons='" + User.Coupons + "' WHERE id='" + User.UserID + "'");
                    if (WeaponToBuy == null)
                    {
                        User.disconnect();
                    }
                    User.AddItem(WeaponToBuy, Days, 1);
                    User.send(new PACKET_COUPON_BUY(WeaponToBuy, User));
                    User.send(new PACKET_COUPON_EVENT(User));
                    User.reloadCash();
                }
                else
                {
                    User.send(new PACKET_ITEMSHOP(PACKET_ITEMSHOP.ErrorCodes.InventoryFull, "NULL"));
                }
            }
            else
            {
                User.send(new PACKET_COUPON_BUY(PACKET_COUPON_BUY.ErrorCode.NotEnoughCoupons));
            }
        }
Пример #6
0
 public override void Handle(virtualUser User)
 {
     if (User.Rank > 2)
     {
         int EnterRoom = Convert.ToInt32(getNextBlock());
         int roomID    = Convert.ToInt32(getNextBlock());
         if (EnterRoom == 1) // 1 == Join, 2 == Leave, 3 == UpdateGameData [30017]
         {
             virtualRoom Room = RoomManager.getRoom(User.Channel, roomID);
             if (Room != null)
             {
                 if (User.isSpectating == true)
                 {
                     return;
                 }
                 if (Room.addSpectator(User))
                 {
                     User.send(new PACKET_SPECTATE_ROOM(User, Room));
                     User.send(new PACKET_ROOM_UDP(User, Room.Players));
                     foreach (virtualUser RoomUser in Room.Players)
                     {
                         if (RoomUser.Equals(User) == false && RoomUser.isSpectating == false)
                         {
                             RoomUser.send(new PACKET_ROOM_UDP_SPECTATE(User));
                         }
                     }
                 }
                 else
                 {
                     StringBuilder SpectatorList = new StringBuilder();
                     int           Count         = 0;
                     foreach (virtualUser Spectator in Room.Spectators)
                     {
                         SpectatorList.Append(Spectator.Nickname);
                         Count++;
                     }
                     SpectatorList.ToString().Remove(SpectatorList.ToString().Length - 1, 1);
                     User.send(new PACKET_CHAT("SPECTATE", PACKET_CHAT.ChatType.Room_ToAll, "SPECTATE >> There is no slot empty for this room!", 999, User.Nickname));
                 }
             }
         }
         else
         {
             User.Room.removeSpectator(User);
         }
     }
     else
     {
         User.disconnect();
     }
 }
Пример #7
0
        public static void AddClan(virtualUser User, string Name, string Description)
        {
            string[] GetCheck = DB.runReadRow("SELECT * FROM clans WHERE clanname='" + Name + "'");
            if (GetCheck.Length == 0)
            {
                //if (User.Rank < 1)
                //{
                //    User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Cannot create the clan " + Name + " because is available only for donators!", User.SessionID, User.Nickname));
                //    return;
                //}
                if (User.ClanID == -1) // If user hasn't a clan
                {
                    string ActualTime = DateTime.Now.ToString("yyyy.MM.dd");

                    if (Description != "")
                    {
                        DB.runQuery("INSERT INTO clans (clanjoindate, clanname, maxusers, win, lose, description, announcment, iconid) VALUES('" + ActualTime + "', '" + Name + "', '20', '0', '0', '" + Description + "', 'Insert here The Announcement!', '1001001')");
                    }

                    if (Description == "")
                    {
                        DB.runQuery("INSERT INTO clans (clanjoindate, clanname, maxusers, win, lose, description, announcment, iconid) VALUES('" + ActualTime + "', '" + Name + "', '20', '0', '0', 'Insert Here The Introduction!', 'Insert here The Announcement!', '1001001')");
                    }

                    int         ClanID = getClanIDByName(Name);
                    virtualClan Clan   = new virtualClan(ClanID, Name, 1001001, 20, 0, 0, 0); // Add the new clan for live update
                    Clans.Add(Clan);                                                          // Add it in the arraylist
                    User.ClanID     = ClanID;                                                 // Set clan id to the master
                    User.ClanName   = Name;                                                   // Set clan name to the maste
                    User.ClanRank   = 2;                                                      // Set clan rank as master
                    User.ClanIconID = 1001001;
                    User.Clan       = getClan(ClanID);
                    User.Dinar     -= 10000;
                    /* Execute query for the database */
                    DB.runQuery("UPDATE users SET dinar='" + User.Dinar + "', clanid='" + ClanID + "', clanrank='2', clanjoindate='" + ActualTime + "' WHERE id='" + User.UserID + "'");
                    // Finaly result
                    User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Successfully created the clan (" + Name + ")!", User.SessionID, User.Nickname));
                    User.send(new PACKET_CLAN(Name, ClanID));
                }
                else // else if user has already a clan
                {
                    string Rank = (User.ClanRank == 2 ? "own" : "are in"); // Calculate if is a master or an normal clan member
                    User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Cannot create the clan because you " + Rank + " a clan!", User.SessionID, User.Nickname));
                }
            }
            else
            {
                User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Cannot create the clan because this clan name is already in use!", User.SessionID, User.Nickname));
            }
        }
Пример #8
0
        public static void KickClan(virtualUser User, string Nickname)
        {
            // Kick a member from the clan
            bool UserFound = false;

            if (User.ClanID != 1 && User.ClanRank == 5 && Nickname.ToLower() != User.Nickname.ToLower())
            {
                string[] selectedUser = DB.runReadRow("SELECT id, clanrank FROM users WHERE nickname='" + Nickname.ToLower() + "' AND clanid='" + User.ClanID + "'");
                if (selectedUser.Length > 0)
                {
                    if (selectedUser[1] == "5")
                    {
                        return;
                    }
                    DB.runQuery("UPDATE users SET clanid='-1', clanrank='1' WHERE id='" + selectedUser[0] + "'");
                    foreach (virtualUser Players in getClanUsers(User.ClanID))
                    {
                        Players.send(new PACKET_CHAT("ClanSystem", PACKET_CHAT.ChatType.Clan, "ClanSystem >> " + Nickname + " got kicked from the clan by" + User.Nickname + " :/!", User.ClanID, "NULL"));
                    }
                    return;
                }
                else
                {
                    UserFound = false;
                }
                if (UserFound == false)
                {
                    User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> The user " + Nickname + " is not in your clan or doesn't exist!", User.SessionID, User.Nickname));
                }
            }
        }
Пример #9
0
 public override void Handle(virtualUser User)
 {
     try
     {
         //if (User.Room.RoomType == 1 && User.Room.RoomStatus == 2) return;
         Virtual_Objects.Room.virtualRoom Room = User.Room;
         if (Room.Channel == 3 && Room.Mode == 12)
         {
             if (User.IsEscapeZombie)
             {
                 Room.EscapeZombie--;
             }
             else
             {
                 Room.EscapeHuman--;
             }
         }
         if (User.isSpectating)
         {
             User.Room.removeSpectator(User);
             return;
         }
         if (User.Room != null)
         {
             User.Room.RemoveUser(User.RoomSlot);
         }
         User.Alive        = false; //FreeWar : Test Per Bug CQC
         User.BackedToRoom = false;
         User.send(new Packets.PACKET_ROOM_LIST(User, User.Page));
     }
     catch (Exception ex)
     {
         Log.AppendError(ex.Message);
     }
 }
Пример #10
0
        public override void Handle(virtualUser User)
        {
            virtualRoom Room = User.Room;

            if (User.Room != null)
            {
                if (User.Channel != 3)
                {
                    User.send(new PACKET_SCORE_BOARD(User));
                }
                else
                {
                    User.send(new PACKET_SCORE_BOARD_AI(User));
                }
            }
        }
Пример #11
0
 public static void JoinClan(virtualUser User, int ClanID)
 {
     if (User.ClanID == -1 && ClanID != -1) // If user hasn't a clan
     {
         /* Execute query for the database */
         string ActualTime = DateTime.Now.ToString("yyyy.MM.dd");
         DB.runQuery("UPDATE users SET clanid='" + ClanID + "', clanrank='0', clanjoindate='" + ActualTime + "' WHERE id='" + User.UserID + "'");
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Successfull joined in the clan: " + getClan(ClanID).clanName + "!!", User.SessionID, User.Nickname));
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Please re-login for take the effects of clan!!", User.SessionID, User.Nickname));
         User.ClanID   = ClanID;
         User.ClanRank = 0;
         foreach (virtualUser Players in getClanUsers(User.ClanID))
         {
             Players.send(new PACKET_CHAT("ClanSystem", PACKET_CHAT.ChatType.Clan, "ClanSystem >> " + User.Nickname + " has joined the clan :)!", User.ClanID, "NULL"));
         }
     }
 }
Пример #12
0
        public override void Handle(virtualUser User)
        {
            //N***a will invade the world.
            bool   Equip        = (getBlock(0) == "0") ? true : false;
            int    Class        = Convert.ToInt32(getBlock(1));
            string Code         = getBlock(4);
            int    WhereToPlace = Convert.ToInt32(getBlock(5));

            string Costume = getCostume(User, Class);

            Item Item = ItemManager.getItem(Code);

            {
                if (Equip == true)
                {
                    string[] Placment = Costume.Split(new char[] { ',' });
                    if (Code.Contains("BA"))
                    {
                        for (int I = 0; I < Placment.Length; I++)
                        {
                            Placment[I] = "^";
                        }
                        Placment[0] = Code;
                    }
                    else
                    {
                        Placment[WhereToPlace] = Code;
                    }
                    string newCostumeParts = string.Join(",", Placment);
                    Code = newCostumeParts;
                    updateCostume(User, Class, Code);
                    DB.runQuery("UPDATE users_costumes SET class_" + Class + "='" + Code + "' WHERE ownerid='" + User.UserID + "'");
                }
                else
                {
                    string[] Placment = Costume.Split(new char[] { ',' });
                    if (Code.Contains("BA"))
                    {
                        for (int I = 0; I < Placment.Length; I++)
                        {
                            Placment[I] = "^";
                        }
                        Placment[0] = getDefaultClass(Class);
                    }
                    else
                    {
                        Placment[WhereToPlace] = "^";
                    }
                    string newCostumeParts = string.Join(",", Placment);
                    Code = newCostumeParts;
                    updateCostume(User, Class, Code);
                    DB.runQuery("UPDATE users_costumes SET class_" + Class + "='" + Code + "' WHERE ownerid='" + User.UserID + "'");
                }
            }
            User.send(new Packets.PACKET_COSTUME_EQUIPMENT(User, Class, Code));
            User.reloadCash();
        }
Пример #13
0
 public static void LeaveClan(virtualUser User)
 {
     if (User.ClanRank == 5)
     {
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Cannot leave the clan because you're master, disband the clan if you want to leave!!", User.SessionID, User.Nickname));
     }
     else if (User.ClanID != -1)
     {
         DB.runQuery("UPDATE users SET clanid='-1', clanrank='1' WHERE id='" + User.UserID + "'");
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Sucessfully left the clan " + User.ClanName + "!!", User.SessionID, User.Nickname));
         User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Please re-login for take the effects!!", User.SessionID, User.Nickname));
         int SaveID = User.ClanID;
         User.ClanID = User.ClanRank = -1;
         foreach (virtualUser Players in getClanUsers(SaveID))
         {
             Players.send(new PACKET_CHAT("ClanSystem", PACKET_CHAT.ChatType.Clan, "ClanSystem >> " + User.Nickname + " has left the clan :(!", SaveID, "NULL"));
         }
         if (getClanMembersCount(SaveID) <= 0)
         {
             DB.runQuery("DELETE FROM clans WHERE id='" + SaveID + "'");
         }
     }
 }
Пример #14
0
        public static void InviteMember(virtualUser User, string Nickname)
        {
            // Invite a member
            bool UserFound = false;

            foreach (virtualUser Client in UserManager.getAllUsers())
            {
                if (Client.Nickname.ToLower().Equals(Nickname.ToLower()) || Client.Username.ToLower().Equals(Nickname.ToLower()))
                {
                    if (Client.UserID == User.UserID)
                    {
                        return;
                    }
                    if (Client.ClanID == User.ClanID) // If user is the same
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> " + Client.Nickname + " is already in your clan!", User.SessionID, User.Nickname));
                    }
                    else if (User.ClanRank != 2) // If user isn't master
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> You cannot invite a member because you're not clan master / leader / operator !", User.SessionID, User.Nickname));
                    }
                    else if (Client.ClanID != -1) // If user has a clan
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> " + Client.Nickname + " has already a clan!", User.SessionID, User.Nickname));
                    }
                    else if (getClanMembersCount(User.ClanID) >= getClanMembersMaxCount(User.ClanID)) // If clan is full
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> There is no free empty slot for the clan!", User.SessionID, User.Nickname));
                    }
                    else if (Client.InvitationBy != -1) // If user has already invited
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Someone has already invited this user!", User.SessionID, User.Nickname));
                    }
                    else // Else do n***a work
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Successfully sent invitation to: " + Client.Nickname + "!", User.SessionID, User.Nickname));
                        Client.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> " + User.Nickname + " has invited you to join in the clan: " + User.ClanName + "! Write /accept to accept or /decline to decline", Client.SessionID, Client.Nickname));
                        Client.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Remember: if you relogin, the invite will be automaticaly declined.", Client.SessionID, Client.Nickname));
                        Client.InvitationBy = User.ClanID;
                    }
                    return;
                }
                else
                {
                    UserFound = false;
                }
            }
            if (UserFound == false)
            {
                User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> The user " + Nickname + " isn't online or doesn't exist!", User.SessionID, User.Nickname));
            }
        }
Пример #15
0
 public override void Handle(virtualUser User)
 {
     try
     {
         User.HWID = getBlock(2);
         string[] HWIDCheck = DB.runReadRow("SELECT * FROM users_hwid WHERE hwid='" + User.HWID.ToString() + "'");
         if (HWIDCheck.Length > 0)
         {
             Log.AppendError(User.HWID + " tried to login but this HWID is banned!");
             User.disconnect();
         }
         else
         {
             User.send(new PACKET_LOGIN());
         }
     }
     catch (Exception ex) { Log.AppendError(ex.Message); }
 }
Пример #16
0
 public override void Handle(virtualUser User)
 {
     User.send(new Packets.PACKET_COUPON_EVENT(User));
 }
Пример #17
0
        public override void Handle(virtualUser User)
        {
            try
            {
                int     Operation = Convert.ToInt32(getBlock(0));
                Subtype sub       = (Subtype)Operation;
                switch (sub)
                {
                case Subtype.FriendList:
                {
                    //32256 1 5606 3 <- [Count] 0 FrostyPrime 1 0 1 SiroSick 1 0 -1 tishina 1 4
                    User.LoadFriends();
                    User.send(new SP_MESSENGER_FRIENDS(User));
                    break;
                }

                case Subtype.SendMessage:
                {
                    string nickname = getBlock(1), message = "";
                    if (nickname.Length > 0 && nickname.Length <= 32)
                    {
                        message = getBlock(2).Trim();         // Remove unused spaces. (Just incase)

                        virtualUser friend = UserManager.getUser(nickname);
                        if (friend != null)
                        {
                            virtualMessenger vm = User.getFriend(nickname);

                            if (vm != null && (vm.Status == 0 || vm.Status == 1))
                            {
                                User.send(new SP_MESSENGER_MESSAGE(User.Nickname, friend.Nickname, message));
                                friend.send(new SP_MESSENGER_MESSAGE(User.Nickname, friend.Nickname, message));
                            }
                        }
                    }
                    break;
                }

                case Subtype.AvaialbleToChat:
                {
                    string nickname = getBlock(1);
                    if (nickname.Length > 0 && nickname.Length <= 32)
                    {
                        virtualMessenger vm         = User.getFriend(nickname);
                        virtualUser      tempClient = UserManager.getUser(nickname);
                        bool             ChatAble   = false;
                        if (tempClient != null)
                        {
                            ChatAble = true;
                        }
                        if (vm != null && (vm.Status == 0 || vm.Status == 1) && ChatAble)
                        {
                            User.send(new PacketUnknown(32256, 1, 5609, vm.Nickname, 0));
                        }
                    }
                    break;
                }

                case Subtype.BlockUnblock:
                {
                    string nickname = getBlock(1);
                    if (nickname.Length > 0 && nickname.Length <= 32)
                    {
                        int FriendID = Convert.ToInt32(DB.runReadRow("SELECT id FROM users WHERE nickname='" + DB.Stripslash(nickname) + "'")[0]);
                        if (FriendID > 0)
                        {
                            virtualMessenger v = User.getFriend(FriendID);

                            if (v.Status == 1)
                            {
                                v.Status = 2;
                            }
                            else if (v.Status == 2)
                            {
                                v.Status = 1;
                            }

                            DB.runQuery("UPDATE friends SET status='" + v.Status + "' WHERE id1='" + FriendID + "' AND id2='" + User.UserID + "' OR id1='" + User.UserID + "' AND id2='" + FriendID + "'");

                            virtualUser friend = UserManager.getUser(FriendID);
                            if (friend != null)
                            {
                                friend.send(new SP_MESSENGER_FRIENDS(friend));

                                virtualMessenger u2 = User.getFriend(FriendID);
                                if (u2 != null)
                                {
                                    u2.Status = v.Status;
                                }
                            }

                            User.send(new SP_MESSENGER_FRIENDS(User));
                        }
                    }
                    break;
                }

                case Subtype.DeleteFriend:
                {
                    string   Nickname = getBlock(1);
                    string[] Query    = DB.runReadRow("SELECT id FROM users WHERE nickname='" + Nickname + "'");
                    if (Query.Length > 0)
                    {
                        int FriendID = Convert.ToInt32(Query[0]);
                        if (FriendID > 0)
                        {
                            DB.runQuery("DELETE FROM friends WHERE id1='" + FriendID + "' AND id2='" + User.UserID + "' OR id1='" + User.UserID + "' AND id2='" + FriendID + "'");

                            virtualUser friend = UserManager.getUser(FriendID);
                            if (friend != null)
                            {
                                friend.Friends.Remove(User.UserID);
                                friend.send(new SP_MESSENGER_FRIENDS(User));
                            }

                            User.Friends.Remove(FriendID);
                            User.send(new SP_MESSENGER_FRIENDS(User));
                        }
                    }
                    break;
                }
                //case Subtype.FriendRequest:
                //    {
                //        string Nickname = getBlock(1);
                //        string[] SearchUser = DB.runReadRow("SELECT id FROM users WHERE nickname='" + Nickname + "'");
                //        if (SearchUser.Length > 0 && SearchUser[0] != User.UserID.ToString())
                //        {
                //            if (User.UserID == -1 || SearchUser[0] == "-1") return;
                //            DB.runQuery("INSERT INTO friends (id1, id2, requesterid, status) VALUES ('" + User.UserID + "', '" + SearchUser[0] + "', '" + User.UserID + "', '5')");
                //            virtualUser Friend = Managers.UserManager.getUser(Nickname);

                //            User.send(new SP_FRIEND_REQUEST(User.Nickname, Nickname));

                //            if (Friend != null)
                //            {
                //                User.send(new SP_FRIEND_REQUEST(User.Nickname, Nickname));
                //            }
                //            User.LoadFriends();
                //            User.send(new SP_MESSENGER_FRIENDS(User));
                //        }
                //        else
                //        {
                //            User.send(new PacketUnknown(32256, -11));
                //            //User.send(new SP_WARROCK_MESSENGER(SP_WARROCK_MESSENGER.Subtype.InvalidNickname));
                //        }
                //        break;
                //    }
                case Subtype.FriendRequest:
                {
                    string   Nickname   = getBlock(1);
                    string[] SearchUser = DB.runReadRow("SELECT id FROM users WHERE nickname='" + Nickname + "'");
                    if (SearchUser.Length > 0 && SearchUser[0] != User.UserID.ToString())
                    {
                        DB.runQuery("INSERT INTO friends (id1, id2, requesterid, status) VALUES ('" + User.UserID + "', '" + SearchUser[0] + "', '" + User.UserID + "', '5')");
                        virtualUser Friend = Managers.UserManager.getUser(Nickname);

                        User.send(new SP_FRIEND_REQUEST(User.Nickname, Nickname));

                        if (Friend != null)
                        {
                            User.send(new SP_FRIEND_REQUEST(User.Nickname, Nickname));
                        }
                        User.LoadFriends();
                        User.send(new SP_MESSENGER_FRIENDS(User));
                    }
                    else
                    {
                        User.send(new PacketUnknown(32256, -11));
                    }
                    break;
                }
                //case Subtype.FriendRequest:
                //    {
                //        //32256 1 5615 xK1llSt3am Realiity <- Server
                //        string Nickname = getBlock(1);
                //        string[] SearchUser = DB.runReadRow("SELECT id, nickname FROM users WHERE nickname='" + Nickname + "'");
                //        if (SearchUser.Length > 0 && SearchUser[0] != User.UserID.ToString())
                //        {
                //            int FriendID = Convert.ToInt32(SearchUser[0]);
                //            if (FriendID > 0)
                //            {
                //                if (User.UserID == -1 || FriendID <= 0) return;
                //                DB.runQuery("INSERT INTO friends (id1, id2, requesterid, status, nick1, nick2) VALUES ('" + User.UserID + "', '" + SearchUser[0] + "', '" + User.UserID + "', '5', '" + User.Nickname + "', '" + SearchUser[1] + "')");
                //                virtualUser Friend = UserManager.getUser(Convert.ToInt32(SearchUser[0]));

                //                User.send(new SP_FRIEND_REQUEST(User.Nickname, Nickname));
                //                if (Friend != null)
                //                {
                //                    Friend.AddFriend(User.UserID, User.UserID, User.Nickname);
                //                    Friend.send(new SP_FRIEND_REQUEST(User.Nickname, Nickname));
                //                    Friend.send(new SP_MESSENGER_FRIENDS(User));
                //                }

                //                User.AddFriend(Convert.ToInt32(SearchUser[0]), User.UserID, SearchUser[1]);
                //                User.send(new SP_FRIEND_REQUEST(User.Nickname, Nickname));
                //                User.LoadFriends();
                //                User.send(new SP_MESSENGER_FRIENDS(User));
                //            }
                //        }
                //        else
                //        {
                //            User.send(new PacketUnknown(32256, -11));
                //        }
                //        break;
                //    }
                case Subtype.FriendAccept:
                {
                    //5610 xK1llSt3am 0  <- Client
                    string Nickname = getBlock(1).Trim();
                    User.LoadFriends();
                    if (Nickname.Length > 0 && Nickname.Length <= 32)                                                  // Check for the nickname length for safety
                    {
                        string[] SearchUser = DB.runReadRow("SELECT id FROM users WHERE nickname='" + Nickname + "'"); // Search the user in the database
                        if (SearchUser.Length > 0 && SearchUser[0] != User.UserID.ToString())                          // If the user is in the database
                        {
                            int FriendID = Convert.ToInt32(SearchUser[0]);
                            if (FriendID > 0)
                            {
                                DB.runQuery("UPDATE friends SET requesterid='-1', status='1' WHERE id1='" + FriendID + "' AND id2='" + User.UserID + "' OR id1='" + User.UserID + "' AND id2='" + FriendID + "'");

                                virtualUser f = UserManager.getUser(FriendID);
                                if (f != null)
                                {
                                    virtualMessenger u = f.getFriend(User.UserID);
                                    if (u != null)
                                    {
                                        u.Status = 1;
                                    }
                                    f.send(new SP_MESSENGER_FRIENDS(f));
                                }

                                virtualMessenger u2 = User.getFriend(FriendID);
                                if (u2 != null)
                                {
                                    u2.Status = 1;
                                }
                                User.send(new SP_MESSENGER_FRIENDS(User));
                                break;
                            }
                        }
                    }

                    break;
                }

                case Subtype.FriendDecline:
                {
                    string Nickname = getBlock(1).Trim();
                    if (Nickname.Length > 0 && Nickname.Length <= 32)                                                  // Check for the nickname length for safety
                    {
                        string[] SearchUser = DB.runReadRow("SELECT id FROM users WHERE nickname='" + Nickname + "'"); // Search the user in the database
                        if (SearchUser.Length > 0)                                                                     // If the user is in the database
                        {
                            int FriendID = Convert.ToInt32(SearchUser[0]);
                            if (FriendID > 0)
                            {
                                DB.runQuery("DELETE FROM friends WHERE id1='" + FriendID + "' AND id2='" + User.UserID + "' OR id1='" + User.UserID + "' AND id2='" + FriendID + "'");
                                virtualUser f = UserManager.getUser(FriendID);
                                if (f != null)
                                {
                                    User.RemoveFriend(User.UserID);
                                    f.send(new SP_MESSENGER_FRIENDS(f));
                                }

                                User.RemoveFriend(FriendID);
                                User.LoadFriends();
                                User.send(new SP_MESSENGER_FRIENDS(User));
                                break;
                            }
                        }
                    }
                    break;
                }
                }
            }
            catch { Log.AppendError("Error on the Messenger: " + User.Nickname + " - " + string.Join(" ", getAllBlocks())); }
        }
Пример #18
0
        public override void Handle(virtualUser User)
        {
            bool   Found      = false;
            string CouponCode = getBlock(0);

            int[]    array       = DB.runReadColumn("SELECT id FROM coupons", 0, null);
            string[] CouponArray = DB.runReadRow(string.Concat("SELECT id, coupon, code, days, amount, active, item, usedby, public, expiredate FROM coupons"));
            if ((int)CouponArray.Length <= 0)
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.WrongCoupon));
                return;
            }
            for (int I = 0; I < array.Length; I++)
            {
                string[] Coupon = DB.runReadRow("SELECT coupon FROM coupons WHERE id=" + array[I].ToString());
                if (Coupon[0] == CouponCode)
                {
                    Found = true;
                }
            }
            if (Found == false)
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.WrongCoupon));
                return;
            }
            int Actived = Convert.ToInt32(CouponArray[5]);

            string[] UsedBy = CouponArray[7].Split(',');
            int      Public = Convert.ToInt32(CouponArray[8]);

            DateTime dateTime = DateTime.ParseExact(CouponArray[9], "dd-MM-yyyy", null);
            string   str      = dateTime.ToString("yyMMdd");
            DateTime now      = DateTime.Now;
            int      num      = Convert.ToInt32(string.Format("{0:yyMMdd}", now));

            if (UsedBy.Length > 1 && Actived == '1' && Public == '0')
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.AlreadyUsedCouponByOther));
                return;
            }
            virtualUser user   = User;
            int         UserID = user.UserID;

            for (int N = 0; N < UsedBy.Length; N++)
            {
                if (UsedBy[N] == User.UserID.ToString())
                {
                    User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.AlreadyUsedCouponByHimself));
                    return;
                }
            }
            if (num >= Convert.ToInt32(str))
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.CouponIsExpired));
                return;
            }

            int InventorySlot = User.InventorySlots;

            if (InventorySlot == 0)
            {
                User.send(new PACKET_SHOP_COUPON(PACKET_SHOP_COUPON.Subtype.InventoryFull));
                return;
            }
            string str1 = CouponArray[2];

            User.AddOutBoxItem(str1, Convert.ToInt32(CouponArray[3]), Convert.ToInt32(CouponArray[4]));
            if (Public == 1)
            {
                Actived = 1;
            }
            DB.runQuery("UPDATE coupons SET active = " + Actived + " ',' usedby = " + user.UserID + "" + "," + " WHERE id = " + CouponArray[9] + "");
            Log.AppendText(User.Nickname + " enter ingamepromocode: " + CouponArray[2]);
        }
Пример #19
0
        public override void Handle(virtualUser _User)
        {
            try
            {
                int       Operation  = Convert.ToInt32(getBlock(0));
                ArrayList PlayerList = new ArrayList();

                if (Operation == 0) // All
                {
                    foreach (virtualUser rPlayers in UserManager.getAllUsers())
                    {
                        if (rPlayers.GMMode == false && PlayerList.Count < 50)
                        {
                            PlayerList.Add(rPlayers);
                        }
                    }
                }
                else if (Operation == 1) // by Name
                {
                    string Nickname = getBlock(1);
                    foreach (virtualUser _Client in Managers.UserManager.getAllUsers())
                    {
                        if (_Client.Nickname.ToLower().Contains(Nickname.ToLower()) && PlayerList.Count < 50 && _Client.GMMode == false)
                        {
                            PlayerList.Add(_Client);
                        }
                    }
                }
                else if (Operation == 2) // by Clan
                {
                    string ClanName = getBlock(1).ToLower();
                    if (ClanName != "null")
                    {
                        foreach (virtualUser User in UserManager.getAllUsers())
                        {
                            if (User.ClanName.ToLower().Contains(ClanName) && User.GMMode == false && PlayerList.Count < 50)
                            {
                                PlayerList.Add(User);
                            }
                        }
                    }
                }
                else if (Operation == 3) // by Level
                {
                    string Range = getBlock(1);

                    if (Range.Contains("-"))
                    {
                        int Range1 = Convert.ToInt32(Range.Split(new char[] { '-' })[0]);
                        int Range2 = Convert.ToInt32(Range.Split(new char[] { '-' })[1]);

                        foreach (virtualUser _Client in Managers.UserManager.getAllUsers())
                        {
                            if (Managers.LevelCalculator.getLevelforExp(_Client.Exp) >= Range1 && Managers.LevelCalculator.getLevelforExp(_Client.Exp) <= Range2 && PlayerList.Count < 50 && _Client.GMMode == false)
                            {
                                PlayerList.Add(_Client);
                            }
                        }
                    }
                    else
                    {
                        foreach (virtualUser _Client in Managers.UserManager.getAllUsers())
                        {
                            if (Managers.LevelCalculator.getLevelforExp(_Client.Exp) == Convert.ToInt32(Range) && _Client.GMMode == false && PlayerList.Count < 50)
                            {
                                PlayerList.Add(_Client);
                            }
                        }
                    }
                }

                _User.send(new Packets.PACKET_USER_LIST(PlayerList));
            }
            catch (Exception ex)
            {
                Log.AppendError(ex.Message);
            }
        }
        public override void Handle(virtualUser User)
        {
            int Operation = Convert.ToInt32(getBlock(0));

            if (Operation == 0) // Check duplicate
            {
                string[] clanData = DB.runReadRow("SELECT * FROM clans WHERE clanname='" + getBlock(1) + "'");
                if (clanData.Length > 0 && getBlock(1).Length > 0)
                {
                    User.send(new Packets.PACKET_CLAN(Packets.PACKET_CLAN.ErrorCodes.Exist, Operation));
                }
                else
                {
                    User.send(new Packets.PACKET_CLAN(Packets.PACKET_CLAN.ErrorCodes.NotExist, Operation));
                }
            }
            else if (Operation == 1) // Create clan
            {
                ClanManager.AddClan(User, getBlock(1), getBlock(2));
                // ClanManager.AddClan(User, getBlock(1));
                return;
            }
            else if (Operation == 2) // Apply Clan
            {
                int      ClanID                 = Convert.ToInt32(getBlock(1));
                string   ActualTime             = DateTime.Now.ToString("yyyy.MM.dd");
                string[] checkForAlreadyRequest = DB.runReadRow("SELECT * FROM clans_invite WHERE userid='" + User.UserID + "'");
                DB.runQuery("UPDATE users SET clanrank='9', clanid='" + ClanID + "' WHERE id='" + User.UserID + "'");
                if (checkForAlreadyRequest.Length > 0)
                {
                    DB.runQuery("UPDATE clans_invite SET clanid='" + ClanID + "' WHERE userid='" + User.UserID + "'");
                }
                else
                {
                    DB.runQuery("INSERT INTO clans_invite (userid, clanid) VALUES ('" + User.UserID + "', '" + ClanID + "')");
                }
                User.ClanID   = ClanID;
                User.ClanRank = 9;
                User.Clan     = ClanManager.getClan(ClanID);
                User.send(new PACKET_CLAN(-1));
                return;
            }
            else if (Operation == 3) // Leave Clan
            {
                if (User.ClanRank == 2)
                {
                    DB.runQuery("DELETE * FROM clans WHERE id='" + User.ClanID + "'");
                    DB.runQuery("UPDATE users SET clanid='-1', clanrank='-1' WHERE clanid='" + User.ClanID + "'");
                    foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                    {
                        if (Player.ClanID == User.ClanID)
                        {
                            Player.ClanID = Player.ClanRank = -1;
                        }
                    }
                }
                DB.runQuery("UPDATE users SET clanid='-1', clanrank='-1' WHERE id='" + User.UserID + "'");
                User.ClanID = User.ClanRank = -1;
                User.send(new PACKET_CLAN_PENDING_USERS());
            }
            else if (Operation == 4) // Open 'My Clan'
            {
                if (User.ClanRank == -1 || User.ClanRank == 9)
                {
                    User.send(new PACKET_CHAT(User, PACKET_CHAT.ChatType.Whisper, "You need to be accepted before.", User.SessionID, User.Nickname));
                }
                User.send(new Packets.PACKET_CLAN(User));
                User.send(new Packets.PACKET_CLAN(Packets.PACKET_CLAN.ClanCodes.Open));
                return;
            }
            else if (Operation == 5) // Member Information's
            {
                int Page = Convert.ToInt32(getBlock(1));
                if (Page == 1)
                {
                    User.send(new PACKET_CLAN_USERLIST(User));
                }
                else if (Page == 2 && (User.ClanRank == 1 || User.ClanRank == 2))
                {
                    User.send(new PACKET_CLAN_PENDING_USERS(User));
                }
            }
            else if (Operation == 6) // Search clan
            {
                //Log.WriteDebug(string.Join(" ", getAllBlocks()));
                int Subtype = Convert.ToInt32(getBlock(1));
                switch (Subtype)
                {
                case 0:
                {
                    string   ClanName = getBlock(2);
                    string[] ClanData = DB.runReadRow("SELECT * FROM clans WHERE clanname='" + ClanName + "'");
                    if (ClanData.Length > 0)
                    {
                        User.send(new PACKET_CLAN_USERLIST(User, ClanName));
                    }
                    else
                    {
                        User.send(new PACKET_CLAN(PACKET_CLAN.ErrorCodes.NotFound, Operation));
                    }
                    break;
                }

                default:
                {
                    User.send(new PACKET_CLAN(PACKET_CLAN.ErrorCodes.NotFound, Operation));
                    break;
                }
                }
            }
            else if (Operation == 7) // Clan Info
            {
                int ClanID = Convert.ToInt32(getBlock(1));
                User.send(new PACKET_CLAN_USERLIST(ClanID));
            }
            else if (Operation == 8) // Change announcment
            {
                string Check = (getBlock(1) == "1" ? "announcment" : "description");
                DB.runQuery("UPDATE clans SET " + Check + "='" + getBlock(2) + "' WHERE id='" + User.ClanID + "'");
            }
            else if (Operation == 9) // Accept/defuse clan join
            {
                int Connection = Convert.ToInt32(getBlock(1));
                int UserID     = Convert.ToInt32(getBlock(2));
                if (Connection == 0) // Accept Join
                {
                    if (ClanManager.getClanMembersCount(User.ClanID) >= ClanManager.getClanMembersMaxCount(User.ClanID))
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> No more slot available for the clan, please expand if is possible", User.SessionID, User.Nickname));
                        return;
                    }
                    string ActualTime = DateTime.Now.ToString("yyyy.MM.dd");
                    foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                    {
                        if (Player.UserID == UserID)
                        {
                            Player.ClanRank = 0;
                        }
                    }
                    DB.runQuery("DELETE FROM clans_invite WHERE userid='" + UserID + "'");
                    DB.runQuery("UPDATE users SET clanid='" + User.ClanID + "', clanrank='0', clanjoindate='" + ActualTime + "' WHERE id='" + UserID + "'");
                }
                else if (Connection == 1) // Refuse Join
                {
                    DB.runQuery("DELETE FROM clans_invite WHERE userid='" + UserID + "'");
                    DB.runQuery("UPDATE users SET clanid='-1' WHERE id='" + UserID + "'");
                    string ActualTime = DateTime.Now.ToString("yyyy.MM.dd");
                    foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                    {
                        if (Player.UserID == UserID)
                        {
                            Player.ClanRank   = -1;
                            Player.ClanID     = -1;
                            Player.ClanIconID = 0;
                        }
                    }
                }
                User.send(new PACKET_CLAN_PENDING_USERS(Connection, UserID));
            }
            else if (Operation == 10) // Promote / degrade / remove
            {
                int SubType = Convert.ToInt32(getBlock(1));
                int UserID  = Convert.ToInt32(getBlock(2));
                if (SubType == 0)
                {
                    DB.runQuery("UPDATE users SET clanrank=clanrank+1 WHERE id='" + UserID + "'");
                }
                else if (SubType == 1)
                {
                    DB.runQuery("UPDATE users SET clanrank=clanrank-1 WHERE id='" + UserID + "'");
                }
                else if (SubType == 2)
                {
                    DB.runQuery("UPDATE users SET clanid='-1', clanrank='-1' WHERE id='" + UserID + "'");
                    foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                    {
                        if (Player.UserID == UserID)
                        {
                            Player.ClanID = Player.ClanRank = -1;
                        }
                    }
                }
                User.send(new PACKET_CLAN_CHANGE(SubType, UserID));
            }
            else if (Operation == 11) // Promote master
            {
                //26384 11 23343041
                int UserID = Convert.ToInt32(getBlock(1));
                DB.runQuery("UPDATE users SET clanrank='0' WHERE id='" + User.UserID + "'");
                DB.runQuery("UPDATE users SET clanrank='2' WHERE id='" + UserID + "'");
                User.ClanRank = 0;
                foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                {
                    if (Player.UserID == UserID)
                    {
                        Player.ClanRank = 2;
                    }
                }
                User.send(new PACKET_CLAN_CHANGE());
            }
            else if (Operation == 12) // Clan change nick
            {
                string   newNick        = getBlock(1);
                string[] CheckForLength = DB.runReadRow("SELECT * FROM clans WHERE clanname='" + newNick + "'");
                if (CheckForLength.Length > 0)
                {
                    User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> A clan has already this name, please choose another one", User.SessionID, User.Nickname));
                }
                else
                {
                    DB.runQuery("UPDATE clans SET clanname='" + newNick + "' WHERE id='" + User.ClanID + "'");
                    DB.runQuery("DELETE FROM inventory WHERE ownerid='" + User.UserID + "' AND itemcode='CB02'");
                    User.Inventory = new InventoryItem[105];
                    User.LoadItems();
                    User.send(new PACKET_CLAN_CHANGE(User, true));
                }
            }
            else if (Operation == 14) // Clan Mark Change
            {
                int iconID = Convert.ToInt32(getBlock(1));
                DB.runQuery("DELETE FROM inventory WHERE ownerid='" + User.UserID + "' AND itemcode='CB54'");
                User.Inventory = new InventoryItem[105];
                User.LoadItems();
                DB.runQuery("UPDATE clans SET iconid='" + iconID + "' WHERE id='" + User.ClanID + "'");
                foreach (virtualUser Player in Managers.UserManager.getAllUsers())
                {
                    if (Player.ClanID == User.ClanID)
                    {
                        Player.ClanIconID = iconID;
                    }
                }
                User.send(new PACKET_CLAN_CHANGE(User, false));
            }
            else if (Operation == 16) // Disband Clan
            {
                ClanManager.RemoveClan(User);
            }
            else
            {
                Log.AppendError("Unknown Operation for ClanSystem: " + Operation);
                Log.AppendError("Blocks: " + string.Join(" ", getAllBlocks()));
            }
        }
Пример #21
0
        public override void Handle(virtualUser User)
        {
            try
            {
                bool   Equip      = (getNextBlock() == "0" ? true : false);
                bool   is6thSlot  = (getBlock(0) == "3" ? true : false);
                int    Class      = Convert.ToInt32(getNextBlock());
                string ItemID     = getBlock(4);
                int    TargetSlot = Convert.ToInt32(getBlock(5));
                int    Equip6th   = Convert.ToInt32(getBlock(0));

                bool DefaultWeapon = isDefaultWeapon(ItemID, Class, TargetSlot);

                string InventoryCode = User.getInventoryID(ItemID);

                if (is6thSlot)
                {
                    if (TargetSlot == 5 && ItemID.Contains("-"))
                    {
                        string[] CodeInfo = ItemID.Split(Convert.ToChar("-"));

                        if (User.hasItem(CodeInfo[0]) == false || User.hasItem(CodeInfo[1]) == false)
                        {
                            return;
                        }

                        string[] CodeInfoIDs = new string[2];
                        CodeInfoIDs[0] = User.getInventoryID(CodeInfo[0]);
                        CodeInfoIDs[1] = User.getInventoryID(CodeInfo[1]);

                        InventoryCode = string.Join("-", CodeInfoIDs);
                    }
                    else
                    {
                        if (ItemID.Contains("-"))
                        {
                            string[] CodeInfo = User.Equipment[Class, 5].Split(Convert.ToChar("-"));

                            if (CodeInfo[0] == InventoryCode)
                            {
                                InventoryCode = CodeInfo[1];
                            }
                            else if (CodeInfo[1] == InventoryCode)
                            {
                                InventoryCode = CodeInfo[0];
                            }
                        }
                    }

                    User.Equipment[Class, 5] = InventoryCode;

                    User.LoadRetails();

                    StringBuilder Items = new StringBuilder();
                    for (int I = 0; I < 8; I++)
                    {
                        Items.Append(User.Equipment[Class, I] + ",");
                    }
                    string EquipStr = Items.ToString().Remove(Items.ToString().Length - 1);

                    User.send(new PACKET_EQUIPMENT(Class, EquipStr));
                    DB.runQuery("UPDATE equipment SET class" + Class + "='" + EquipStr + "' WHERE ownerID=" + User.UserID.ToString());
                }
                else if (Equip)
                {
                    if (User.hasItem(ItemID) == false && DefaultWeapon == false)
                    {
                        return;
                    }

                    if (DefaultWeapon)
                    {
                        InventoryCode = ItemID;
                    }

                    bool hasItemEquipped = false;

                    for (int J = 0; J < 8; J++)
                    {
                        if (User.Equipment[Class, J] == InventoryCode)
                        {
                            hasItemEquipped = true;
                        }
                    }

                    //Check for the 5th slot

                    if (TargetSlot == 4)
                    {
                        string[] SplitSlots = User.getSlots().Split(Convert.ToChar(","));
                        if (SplitSlots[0] != "T")
                        {
                            User.disconnect();
                        }
                    }

                    if (hasItemEquipped == false)
                    {
                        User.Equipment[Class, TargetSlot] = InventoryCode;

                        User.LoadRetails();

                        StringBuilder Items = new StringBuilder();
                        for (int I = 0; I < 8; I++)
                        {
                            Items.Append(User.Equipment[Class, I] + ",");
                        }
                        string EquipStr = Items.ToString().Remove(Items.ToString().Length - 1);

                        User.send(new PACKET_EQUIPMENT(Class, EquipStr));
                        DB.runQuery("UPDATE equipment SET class" + Class + "='" + EquipStr + "' WHERE ownerID=" + User.UserID.ToString());
                    }
                    else
                    {
                        User.send(new PACKET_EQUIPMENT(PACKET_EQUIPMENT.ErrorCode.AlreadyEquipped));
                    }
                }
                else
                {
                    int _TargetSlot = Convert.ToInt32(getBlock(3));
                    if (User.Equipment[Class, _TargetSlot] == InventoryCode || _TargetSlot == 5)
                    {
                        if (User.Equipment[Class, _TargetSlot] != "^")
                        {
                            User.Equipment[Class, _TargetSlot] = "^";

                            User.LoadRetails();

                            StringBuilder Items = new StringBuilder();
                            for (int I = 0; I < 8; I++)
                            {
                                Items.Append(User.Equipment[Class, I] + ",");
                            }
                            string EquipStr = Items.ToString().Remove(Items.ToString().Length - 1);

                            User.send(new PACKET_EQUIPMENT(Class, EquipStr));
                            DB.runQuery("UPDATE equipment SET class" + Class + "='" + EquipStr + "' WHERE ownerID=" + User.UserID.ToString());
                        }
                    }
                    else
                    {
                        //User.disconnect();
                    }
                }
            }
            catch (Exception ex) { /*Log.AppendError(ex.Message);*/ }
        }
Пример #22
0
        public override void Handle(virtualUser User)
        {
            virtualRoom currentRoom = User.Room;
            Stopwatch   Timer       = new Stopwatch();

            int Open     = Convert.ToInt32(getBlock(0));
            int stageNum = Convert.ToInt32(getBlock(1));

            if (Open == 4 && stageNum == 0) //2° Stage
            {
                currentRoom.IsTimeOpenDoor = true;
                currentRoom.PowPlayer++;
            }

            if (Open == 4 && stageNum == 1) //3° Stage
            {
                currentRoom.IsTimeOpenDoor = true;
                currentRoom.PowPlayer++;
            }

            if (Open == 4 && stageNum == 2) //4° Stage Sembra che il client non manda questo pacchetto!
            {
                currentRoom.IsTimeOpenDoor = true;
                currentRoom.PowPlayer++;
            }

            if (Open == 6) //4° Stage Sembra che il client non manda questo pacchetto!
            {
                int  SupplyFind = stageNum;
                bool found      = currentRoom.SupplyBox.TryGetValue("SupplyNum" + stageNum, out SupplyFind);
                if (found == false)
                {
                    User.SupplyTemp = stageNum;
                    currentRoom.SupplyBox.Add("SupplyNum" + stageNum, stageNum);
                    currentRoom.PowSupply++;
                }
            }
            if (currentRoom.Players.Count == currentRoom.PowSupply)
            {
                foreach (virtualUser Player in currentRoom.Players)
                {
                    string[] SnowWeapons = new string[] { "DF36", "DC34", "DF65", "DC93" };

                    string WeaponName = "";

                    Random random = new Random(); //1877

                    int    event_weapon = random.Next(4);
                    string ItemCode     = SnowWeapons[event_weapon];

                    switch (ItemCode)
                    {
                    case "DF36": WeaponName = "MP7A1_Snow_Camo"; break;

                    case "DC34": WeaponName = "FAMAS_Snow_Camo"; break;

                    case "DF65": WeaponName = "K1_Snow_Camo"; break;

                    case "DC93": WeaponName = "M4A1_Snow_Camo"; break;
                    }

                    int InventorySlot = -1;
                    for (int I = 0; I < 30; I++)
                    {
                        if (Player.Inventory[I] == null)
                        {
                            InventorySlot = I; break;
                        }
                    }

                    Player.AddOutBoxItem(ItemCode, 7, 1);
                    Player.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Room_ToAll, "SYSTEM >> Congratulations! You achieved 50 kills by the Snow Kill Event!", 999, "NULL"));

                    if (InventorySlot <= 0)
                    {
                        Player.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Room_ToAll, "SYSTEM >> Your inventory is full!", 999, "NULL"));
                        Player.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Room_ToAll, "SYSTEM >> Please delete a weapon and play again.", 999, "NULL"));
                    }
                    else
                    {
                        Player.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Room_ToAll, "SYSTEM >> You got '" + WeaponName + "' for 7 days.", 999, "NULL"));
                        Player.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Room_ToAll, "SYSTEM >> Please relog.", 999, "NULL"));
                    }

                    User.send(new PACKET_SUPPLY_EVENT(User, currentRoom, ItemCode));
                    currentRoom.PowSupply = 0;
                    currentRoom.SupplyBox.Clear();
                    User.SupplyTemp = -1;
                }
            }
        }
Пример #23
0
        public override void Handle(virtualUser User)
        {
            int num1 = int.Parse(this.getBlock(0));

            HANDLE_GUN_SMITH.Type type = (HANDLE_GUN_SMITH.Type) int.Parse(this.getBlock(1));
            if (type == HANDLE_GUN_SMITH.Type.Ticket && !User.hasItem("CZ75"))
            {
                return;
            }
            string[] GunSmithArray = DB.runReadRow("SELECT gameid, item, rare, required_items, lose_items, required_materials, cost FROM gunsmith WHERE gameid='" + num1 + "'");
            if (GunSmithArray.Length <= 0)
            {
                return;
            }
            string ItemCode = GunSmithArray[1];
            int    num2     = int.Parse(GunSmithArray[6]);
            string str      = GunSmithArray[2];
            int    eaItems1 = User.getEAItems("CZ83");
            int    eaItems2 = User.getEAItems("CZ84");
            int    eaItems3 = User.getEAItems("CZ85");

            string[] strArray2 = (GunSmithArray[5]).ToString().Split(',');
            if (type == HANDLE_GUN_SMITH.Type.Ticket)
            {
                num2 = 0;
            }
            if (num2 == -1)
            {
                return;
            }
            int[] numArray = new int[strArray2.Length];
            for (int index = 0; index < numArray.Length; ++index)
            {
                int.TryParse(strArray2[index], out numArray[index]);
            }
            if (numArray[0] > eaItems3 || numArray[1] > eaItems2 || numArray[2] > eaItems1)
            {
                return;
            }
            string[] strArray3 = (GunSmithArray[3]).ToString().Split(',');
            if (!User.hasItem(strArray3[0]) || !User.hasItem(strArray3[1]) || !User.hasItem(strArray3[2]))
            {
                return;
            }
            User.DeleteItem(strArray3[0], 0);
            User.DeleteItem(strArray3[1], 0);
            User.DeleteItem(strArray3[2], 0);
            string[] strArray4 = (GunSmithArray[4]).ToString().Split(',');
            int      num3      = new Random().Next(0, 50);

            if (type == HANDLE_GUN_SMITH.Type.Ticket)
            {
                num3 += 10;
            }
            int index1 = new Random().Next(0, strArray4.Length);
            int Days   = 30;

            if (type == HANDLE_GUN_SMITH.Type.Dinar)
            {
                User.Dinar -= num2;
            }
            else
            {
                User.DeleteItem("CZ75", 1);
            }
            User.DeleteItem("CZ83", numArray[0]);
            User.DeleteItem("CZ84", numArray[1]);
            User.DeleteItem("CZ85", numArray[2]);
            int calcPerc = (type == Type.Dinar ? 10 : 25);

            if (num3 == 17)
            {
                ItemCode = str;
                User.send((Packet) new PACKET_GUN_SMITH(User, ItemCode, PACKET_GUN_SMITH.WonType.Rare));
            }
            else if (num3 > calcPerc)
            {
                User.send((Packet) new PACKET_GUN_SMITH(User, ItemCode, PACKET_GUN_SMITH.WonType.Normal));
            }
            else
            {
                ItemCode = strArray4[index1];
                Days     = new Random().Next(1, 15);
                User.send((Packet) new PACKET_GUN_SMITH(User, ItemCode, PACKET_GUN_SMITH.WonType.Lose));
            }
            User.AddOutBoxItem(ItemCode, Days, 1);
        }
Пример #24
0
        public static void SetMemberRank(virtualUser User, string Nickname, string Rank)
        {
            bool UserFound = true;

            // Set a user to leader / operator / member
            foreach (virtualUser Client in UserManager.getAllUsers())
            {
                if (Client.Nickname.ToLower().Equals(Nickname.ToLower()) || Client.Username.ToLower().Equals(Nickname.ToLower()))
                {
                    if (Client.UserID == User.UserID || User.ClanID == -1 && User.ClanRank != 2)
                    {
                        return;
                    }
                    if (Client.ClanID != User.ClanID) // If user is the same
                    {
                        User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> " + Client.Nickname + " is not in your clan!", User.SessionID, User.Nickname));
                    }
                    else if (Client.ClanID == User.ClanID && User.ClanRank == 2) // If client has same clan of the user
                    {
                        if (Rank == "leutnant")                                  // Check if there exist another leutnant
                        {
                            string[] CheckData = DB.runReadRow("SELECT nickname FROM users WHERE clanid='" + User.ClanID + "' AND clanrank='13'");
                            if (CheckData.Length > 0)
                            {
                                User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> " + CheckData[0] + " is leader of the clan, leaders cannot be more than one!", User.SessionID, User.Nickname));
                                return;
                            }
                        }
                        else if (Rank == "operator")
                        {
                            int[] operatorLength = DB.runReadColumn("SELECT nickname FROM users WHERE clanid='" + User.ClanID + "' AND clanrank='15'", 0, null);
                            if (operatorLength.Length >= 5)
                            {
                                User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> There are already 5 (max) operators!", User.SessionID, User.Nickname));
                                return;
                            }
                        }
                        /*Calculate rank*/
                        int ClanRank = 1;
                        if (Rank == "leutnant")
                        {
                            ClanRank = 13;
                        }
                        else if (Rank == "operator")
                        {
                            ClanRank = 15;
                        }
                        else if (Rank == "member")
                        {
                            ClanRank = 1;
                        }
                        else
                        {
                            User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> Invalid rank! Please choose one of those: member, operator, leutnant!", User.SessionID, User.Nickname));
                            return;
                        }

                        if (Client.ClanRank == ClanRank)
                        {
                            User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> " + Client.Nickname + " has already this clan rank!", User.SessionID, User.Nickname));
                            return;
                        }

                        Rank = char.ToUpper(Rank[0]) + Rank.Substring(1);

                        foreach (virtualUser ClanUser in getClanUsers(User.ClanID))
                        {
                            ClanUser.send(new PACKET_CHAT("ClanSystem", PACKET_CHAT.ChatType.Clan, "ClanSystem >> " + Client.Nickname + " rank has been changed to " + Rank + " :)!", User.ClanID, "NULL"));
                        }
                        Client.ClanRank = ClanRank;
                        DB.runQuery("UPDATE users SET clanrank='" + ClanRank + "' WHERE id='" + Client.UserID + "'");
                        return;
                    }
                }
                else
                {
                    UserFound = false;
                }
            }
            if (UserFound == false)
            {
                User.send(new PACKET_CHAT("SYSTEM", PACKET_CHAT.ChatType.Whisper, "SYSTEM >> The user " + Nickname + " isn't online or doesn't exist!", User.SessionID, User.Nickname));
            }
        }