Exemplo n.º 1
0
 public PartyMember(int i, string n, bool l)
 {
     id     = i;
     name   = n;
     leader = l;
     door   = DoorInformation.DefaultNoDoor;
 }
Exemplo n.º 2
0
        public static Packet UpdateDoor(DoorInformation door, byte ownerIdIdx)
        {
            Program.MainForm.LogDebug("Updating door at index: " + ownerIdIdx);
            Packet pw = new Packet(ServerMessages.PARTY_RESULT);

            pw.WriteByte((byte)PartyFunction.TOWN_PORTAL_CHANGED);
            pw.WriteByte(ownerIdIdx);
            pw.WriteInt(door.DstMap);
            pw.WriteInt(door.SrcMap);
            pw.WriteShort(door.X);
            pw.WriteShort(door.Y);
            return(pw);
        }
Exemplo n.º 3
0
        public void UpdateDoor(DoorInformation newDoor, int charId)
        {
            Program.MainForm.LogDebug("UPDATING DOOR: " + charId);
            var member = GetById(charId);

            if (member != null)
            {
                member.door = newDoor;
                int idx = GetCharacterSlot(member);
                ForAllMembers(m => { if (m.GetChannel() == member.GetChannel())
                                     {
                                         m.SendPacket(PartyPacket.UpdateDoor(newDoor, (byte)idx));
                                     }
                              });
            }
        }
Exemplo n.º 4
0
        private void HandleGamePacket(ISClientMessages opcode, Packet packet)
        {
            switch (opcode)
            {
                #region Messenger


            case ISClientMessages.MessengerJoin:
                Messenger.JoinMessenger(packet);
                break;

            case ISClientMessages.MessengerLeave:
                Messenger.LeaveMessenger(packet.ReadInt());
                break;

            case ISClientMessages.MessengerInvite:
                Messenger.SendInvite(packet.ReadInt(), packet.ReadString());
                break;

            case ISClientMessages.MessengerBlocked:
                Messenger.Block(packet);
                break;

            case ISClientMessages.MessengerAvatar:
                Messenger.OnAvatar(packet);
                break;

            case ISClientMessages.MessengerChat:
                Messenger.Chat(packet.ReadInt(), packet.ReadString());
                break;

                #endregion

                #region Party

            case ISClientMessages.PartyCreate:
            {
                int       fuker  = packet.ReadInt();
                Character f****r = CenterServer.Instance.FindCharacter(fuker);
                Party.CreateParty(f****r);
                break;
            }

            case ISClientMessages.PartyInvite:
            {
                int       fuker1  = packet.ReadInt();
                int       fuker2  = packet.ReadInt();
                Character fucker1 = CenterServer.Instance.FindCharacter(fuker1);
                if (fucker1 != null && Party.Parties.TryGetValue(fucker1.PartyID, out Party party))
                {
                    party.Invite(fuker1, fuker2);
                }
                break;
            }

            case ISClientMessages.PartyAccept:
            {
                int       AcceptorID = packet.ReadInt();
                Character fucker1    = CenterServer.Instance.FindCharacter(AcceptorID);

                if (fucker1 != null && Party.Invites.TryGetValue(AcceptorID, out Party party))
                {
                    party.TryJoin(fucker1);
                }

                break;
            }

            case ISClientMessages.PartyLeave:
            {
                int       LeaverID = packet.ReadInt();
                Character f****r   = CenterServer.Instance.FindCharacter(LeaverID);

                if (f****r != null && Party.Parties.TryGetValue(f****r.PartyID, out Party party))
                {
                    party.Leave(f****r);
                }

                break;
            }

            case ISClientMessages.PartyExpel:
            {
                int       leader            = packet.ReadInt();
                int       expelledCharacter = packet.ReadInt();
                Character f****r            = CenterServer.Instance.FindCharacter(leader);
                if (f****r != null && Party.Parties.TryGetValue(f****r.PartyID, out Party party))
                {
                    party.Expel(leader, expelledCharacter);
                }

                break;
            }

            case ISClientMessages.PartyDecline:
            {
                int       decliner     = packet.ReadInt();
                String    declinerName = packet.ReadString();
                Character chr          = CenterServer.Instance.FindCharacter(decliner);
                if (chr != null && Party.Invites.TryGetValue(decliner, out Party party))
                {
                    party.DeclineInvite(chr);
                }
                break;
            }

            case ISClientMessages.PartyChat:
            {
                int       chatter = packet.ReadInt();
                string    msg     = packet.ReadString();
                Character chr     = CenterServer.Instance.FindCharacter(chatter);
                if (chr != null && Party.Parties.TryGetValue(chr.PartyID, out Party party))
                {
                    party.Chat(chatter, msg);
                }
                break;
            }

            case ISClientMessages.PlayerUpdateMap:
            {
                int       id     = packet.ReadInt();
                int       map    = packet.ReadInt();
                Character f****r = CenterServer.Instance.FindCharacter(id);

                if (f****r != null)
                {
                    f****r.MapID = map;
                    if (Party.Parties.TryGetValue(f****r.PartyID, out Party party))
                    {
                        party.SilentUpdate(id);
                    }
                }

                break;
            }

            case ISClientMessages.PartyDoorChanged:
            {
                int chrid = packet.ReadInt();
                var door  = new DoorInformation(packet.ReadInt(), packet.ReadInt(), packet.ReadShort(), packet.ReadShort(), chrid);

                var chr = CenterServer.Instance.FindCharacter(chrid);
                if (chr != null && Party.Parties.TryGetValue(chr.PartyID, out var party))
                {
                    party.UpdateDoor(door, chrid);
                }

                break;
            }
                #endregion

                #region Buddy

            case ISClientMessages.BuddyInvite:
            {
                int    inviterId    = packet.ReadInt();
                String inviterName  = packet.ReadString();
                String toInviteName = packet.ReadString();

                Character inviter  = CenterServer.Instance.FindCharacter(inviterName);
                Character toInvite = CenterServer.Instance.FindCharacter(toInviteName, false);
                if (inviter == null)
                {
                    return;
                }

                if (inviter.FriendsList.IsFull())
                {
                    inviter.FriendsList.SendRequestError(12);
                    return;
                }

                if (toInvite == null)
                {
                    //How to get id from name? O.o
                    try
                    {
                        var namedata = CenterServer.Instance.CharacterDatabase.RunQuery("SELECT c.`ID`, u.admin, c.buddylist_size, (SELECT COUNT(*) FROM buddylist WHERE charid = c.ID) AS `current_buddylist_size` FROM characters c JOIN users u ON u.id = c.userid WHERE c.name = @name", "@name", toInviteName) as MySqlDataReader;
                        if (namedata.Read())
                        {
                            int  invitedid        = namedata.GetInt32("ID");
                            int  maxBuddyListSize = namedata.GetInt32("buddylist_size");
                            int  buddyListSize    = namedata.GetInt32("current_buddylist_size");
                            bool isGM             = namedata.GetByte("admin") > 0;
                            namedata.Close();

                            if (isGM && inviter.IsGM == false)
                            {
                                inviter.FriendsList.SendRequestError(14);
                                return;
                            }

                            if (maxBuddyListSize <= buddyListSize)
                            {
                                // buddylist is full
                                inviter.FriendsList.SendRequestError(12);
                                return;
                            }

                            inviter.FriendsList.Add(new BuddyData(invitedid, toInviteName));
                            // No update?

                            CenterServer.Instance.CharacterDatabase.RunQuery(
                                "DELETE FROM buddylist_pending WHERE charid = @toinviteid AND inviter_charid = @inviterid",
                                "@toinviteid", invitedid,
                                "@inviterid", inviterId
                                );

                            CenterServer.Instance.CharacterDatabase.RunQuery(
                                "INSERT INTO buddylist_pending (charid, inviter_charid, inviter_charname) VALUES (@toinviteid, @inviterid, @invitername)",
                                "@toinviteid", invitedid,
                                "@inviterid", inviterId,
                                "@invitername", inviterName
                                );
                        }
                        else
                        {
                            namedata.Close();
                            inviter.FriendsList.SendRequestError(15);
                        }
                    }
                    catch (Exception e)
                    {
                        BuddyList.log.Error($"Offline buddy request failed for {inviterId} {inviterName} {toInviteName}", e);
                    }
                }
                else
                {
                    toInvite.FriendsList.Request(inviter.FriendsList.Owner);
                }
                break;
            }

            case ISClientMessages.BuddyUpdate:
            {
                int       id       = packet.ReadInt();
                string    name     = packet.ReadString();
                Character toUpdate = CenterServer.Instance.FindCharacter(id);
                toUpdate.FriendsList.OnOnlineCC(true, false);
                break;
            }

            case ISClientMessages.BuddyInviteAnswer:
            {
                int       id       = packet.ReadInt();
                String    name     = packet.ReadString();
                Character toAccept = CenterServer.Instance.FindCharacter(id);
                toAccept.FriendsList.AcceptRequest();
                break;
            }

            case ISClientMessages.BuddyListExpand:
            {
                CenterServer.Instance.FindCharacter(packet.ReadInt()).FriendsList.IncreaseCapacity();
                break;
            }

            case ISClientMessages.BuddyChat:
            {
                int    fWho           = packet.ReadInt();
                string Who            = packet.ReadString();
                string what           = packet.ReadString();
                int    recipientCount = packet.ReadByte();
                int[]  recipients     = new int[recipientCount];
                for (var i = 0; i < recipientCount; i++)
                {
                    recipients[i] = packet.ReadInt();
                }

                Character pWho = CenterServer.Instance.FindCharacter(fWho);

                pWho?.FriendsList.BuddyChat(what, recipients);
                break;
            }

            case ISClientMessages.BuddyDecline:
            {
                Character Who      = CenterServer.Instance.FindCharacter(packet.ReadInt());
                int       victimId = packet.ReadInt();
                Character Victim   = CenterServer.Instance.FindCharacter(victimId);
                Who.FriendsList.RemoveBuddyOrRequest(Victim, victimId);
                break;
            }
                #endregion

            case ISClientMessages.PlayerUsingSuperMegaphone:
            {
                Packet pw = new Packet(ISServerMessages.PlayerSuperMegaphone);
                pw.WriteString(packet.ReadString());
                pw.WriteBool(packet.ReadBool());
                pw.WriteByte(packet.ReadByte());
                World.SendPacketToEveryGameserver(pw);
                break;
            }

            case ISClientMessages.PlayerWhisperOrFindOperation:     // WhisperOrFind
            {
                int       sender     = packet.ReadInt();
                Character senderChar = CenterServer.Instance.FindCharacter(sender);
                if (senderChar == null)
                {
                    return;
                }

                bool      whisper      = packet.ReadBool();
                string    receiver     = packet.ReadString();
                Character receiverChar = CenterServer.Instance.FindCharacter(receiver);

                if (whisper)
                {
                    string message = packet.ReadString();
                    if ((receiverChar == null ||
                         !World.GameServers.ContainsKey(receiverChar.ChannelID)) ||
                        (receiverChar.IsGM && !senderChar.IsGM))
                    {
                        Packet pw = new Packet(ISServerMessages.PlayerWhisperOrFindOperationResult);
                        pw.WriteBool(true);         // Whisper
                        pw.WriteBool(false);        // Not found.
                        pw.WriteInt(sender);
                        pw.WriteString(receiver);
                        SendPacket(pw);
                    }
                    else
                    {
                        Packet pw = new Packet(ISServerMessages.PlayerWhisperOrFindOperationResult);
                        pw.WriteBool(false);        // Find
                        pw.WriteBool(true);         // Found.
                        pw.WriteInt(sender);
                        pw.WriteString(receiver);
                        pw.WriteSByte(-1);
                        pw.WriteSByte(-1);
                        SendPacket(pw);

                        pw = new Packet(ISServerMessages.PlayerWhisperOrFindOperationResult);
                        pw.WriteBool(true);         // Whisper
                        pw.WriteBool(true);         // Found.
                        pw.WriteInt(receiverChar.ID);
                        pw.WriteString(senderChar.Name);
                        pw.WriteByte(senderChar.ChannelID);
                        pw.WriteString(message);
                        pw.WriteBool(false);         // false is '>>'
                        LocalServer victimChannel = World.GameServers[receiverChar.ChannelID];
                        victimChannel.Connection.SendPacket(pw);
                    }
                }
                else
                {
                    if (receiverChar == null ||
                        !World.GameServers.ContainsKey(receiverChar.ChannelID) ||
                        (receiverChar.IsGM && !senderChar.IsGM))
                    {
                        Packet pw = new Packet(ISServerMessages.PlayerWhisperOrFindOperationResult);
                        pw.WriteBool(false);         // Find
                        pw.WriteBool(false);         // Not found.
                        pw.WriteInt(sender);
                        pw.WriteString(receiver);
                        SendPacket(pw);
                    }
                    else
                    {
                        Packet pw = new Packet(ISServerMessages.PlayerWhisperOrFindOperationResult);
                        pw.WriteBool(false);        // Find
                        pw.WriteBool(true);         // Found.
                        pw.WriteInt(senderChar.ID);
                        pw.WriteString(receiverChar.Name);
                        // Cashshop
                        if (receiverChar.InCashShop)
                        {
                            pw.WriteSByte(-2);
                        }
                        else
                        {
                            pw.WriteByte(receiverChar.ChannelID);
                        }
                        pw.WriteSByte(0);
                        SendPacket(pw);
                    }
                }
                break;
            }

            case ISClientMessages.UpdatePlayerJobLevel:
            {
                int charId    = packet.ReadInt();
                var character = CenterServer.Instance.FindCharacter(charId);
                if (character == null)
                {
                    return;
                }

                character.Job   = packet.ReadShort();
                character.Level = packet.ReadByte();
                break;
            }


            case ISClientMessages.AdminMessage:
            {
                Packet pw = new Packet(ISServerMessages.AdminMessage);
                pw.WriteString(packet.ReadString());
                pw.WriteByte(packet.ReadByte());
                World.SendPacketToEveryGameserver(pw);
                break;
            }

            case ISClientMessages.KickPlayer:
            {
                int userId = packet.ReadInt();
                Program.MainForm.LogAppend("Globally kicking user " + userId);
                Packet pw = new Packet(ISServerMessages.KickPlayerResult);
                pw.WriteInt(userId);
                World.SendPacketToEveryGameserver(pw);
                break;
            }

            case ISClientMessages.ReloadEvents:
                CenterServer.Instance.ReloadEvents();
                break;
            }
        }