Ejemplo n.º 1
0
        public static void FriendInvite(WorldClient pClient, Packet pPacket)
        {
            string sender, receiver;
            if (!pPacket.TryReadString(out sender, 16) ||
                !pPacket.TryReadString(out receiver, 16))
            {
                Log.WriteLine(LogLevel.Warn, "Error reading friend invite.");
                return;
            }

            WorldCharacter inviter = pClient.Character;
            WorldClient invitee = ClientManager.Instance.GetClientByCharname(receiver);
            if (invitee == null)
            {
                //character not found
                using (var pack = new Packet(SH21Type.FriendInviteResponse))
                {
                    pack.WriteString(sender, 16);
                    pack.WriteString(receiver, 16);
                    pack.WriteUShort(0x0946);	// Cannot find ${Target}

                    pClient.SendPacket(pack);
                }
            }
            else if (receiver == sender)
            {
                using (var pack = new Packet(SH21Type.FriendInviteResponse))
                {
                    pack.WriteString(sender, 16);
                    pack.WriteString(receiver, 16);
                    pack.WriteUShort(0x0942);	// You cannot add yourself to your Buddy List.

                    pClient.SendPacket(pack);
                }
            }
            else if (inviter.Friends.Find(f => f.Name == receiver) != null)
            {
                using (var pack = new Packet(SH21Type.FriendInviteResponse))
                {
                    pack.WriteString(sender, 16);
                    pack.WriteString(receiver, 16);
                    pack.WriteUShort(0x0945);	// {Target} is already registered in the friends list.
                    pClient.SendPacket(pack);
                }
            }
            else
            {
                using (var pack = new Packet(SH21Type.FriendInviteRequest))
                {
                    pack.WriteString(receiver, 16);
                    pack.WriteString(sender, 16);

                    invitee.SendPacket(pack);
                }
            }
        }
Ejemplo n.º 2
0
        public static void ChangeFromGuildAcademyToResponse(WorldClient client, Packet packet)
        {
            string GuildName;
              string RequestName;
              bool answer;
              if (!packet.TryReadString(out GuildName, 16) || !packet.TryReadString(out RequestName, 16)|| (!packet.TryReadBool(out answer) || !client.Character.IsInGuildAcademy))
                  return;
             if (answer)
            {
                GuildAcademyMember pMember = client.Character.GuildAcademy.Members.Find(m => m.Character.Character.Name == RequestName);
                if (pMember == null)
                    return;
                pMember.Character.IsInGuildAcademy = false;
                pMember.Academy.RemoveMember(pMember);
               pMember.Character.GuildAcademy.Guild.AddMember(pMember.Character, GuildRank.Member, Program.DatabaseManager.GetClient().GetConnection(), true, true);

                pMember.Character.Guild = pMember.Character.GuildAcademy.Guild;
                pMember.Character.IsInGuild = true;
             using (var pack = new Packet(SH38Type.SendJoinGuildFromAcademy))
             {
                 //this packet remove character from academy List and added to GuildList
                 pack.WriteString(RequestName, 16);
                 pack.WriteString(client.Character.Character.Name, 16);
                 pack.WriteByte(6);//rank
                 pack.WriteInt(0);//unk
                 pack.WriteUShort(0);//korp
                 pack.Fill(64, 0x00);//unk
                 pack.WriteByte(true ? (byte)0x95 : (byte)0x00);// (this.isOnline ? (byte)0x95 : (byte)0x00);
                 pack.Fill(3, 0x00);//unk
                 pack.WriteByte(pMember.Character.Character.Job);
                 pack.WriteByte(pMember.Character.Character.CharLevel);
                 pack.Fill(13, 0x00);//unk
                 client.Character.GuildAcademy.Guild.Broadcast(pack);
                 client.Character.GuildAcademy.Broadcast(pack);
                 }
             }
             using (var p2 = new Packet(SH4Type.CharacterGuildinfo))
             {
                 client.Character.Guild.WriteGuildInfo(packet);
                 client.SendPacket(p2);
             }
             using (var pack = new Packet(SH29Type.GuildMemberJoined))
             {
                 pack.WriteString(client.Character.Character.Name, 16);
                 client.Character.GuildAcademy.Guild.Broadcast(pack);
                 client.Character.GuildAcademy.Broadcast(pack);

             }
             using (var pack = new Packet(SH29Type.ChangeResponse))
             {
                 pack.WriteUShort(3137);//unk
                 pack.WriteByte(3);
                 pack.Fill(2, 0x00);//unk
                 client.SendPacket(pack);
             }
        }
Ejemplo n.º 3
0
 public static void MasterRequest(WorldClient client, Packet packet)
 {
     string playername = string.Empty;
     string target = string.Empty;
     if (!packet.TryReadString(out playername, 16))
         return;
     if (!packet.TryReadString(out target, 16))
         return;
     MasterManager.Instance.AddMasterRequest(client, target);
 }
Ejemplo n.º 4
0
 public static void Wisper(WorldClient client, Packet packet)
 {
     string toname;
     byte messagelenght;
     if (packet.TryReadString(out toname, 16) && packet.TryReadByte(out messagelenght))
     {
         string message;
         if (!packet.TryReadString(out message, messagelenght))
         {
             return;
         }
         WorldClient toChar = ClientManager.Instance.GetClientByCharname(toname);
         if (toChar != null)
         {
             using (var frompacket = new Packet(SH8Type.WisperFrom))
             {
                 frompacket.WriteString(client.Character.Character.Name, 16);
                 if (!toChar.Character.BlocketUser.Contains(client.Character.Character.Name))
                 {
                     frompacket.WriteByte(0);
                 }
                 else
                 {
                     frompacket.WriteByte(12);//blocket notdisplay message
                 }
                 frompacket.WriteByte(messagelenght);
                 frompacket.WriteString(message, messagelenght);
                 toChar.SendPacket(frompacket);
             }
             using (var pack = new Packet(SH8Type.WisperTo))
             {
                 pack.WriteString(toname, 16);
                 pack.WriteByte(messagelenght);
                 pack.WriteString(message, messagelenght);
                 client.SendPacket(pack);
             }
         }
         else
         {
             //target not found
             using (var pp = new Packet(SH8Type.WisperTargetNotfound))
             {
                 pp.WriteUShort(3945);//unk
                 pp.WriteString(toname, 16);
                 client.SendPacket(pp);
             }
         }
     }
 }
Ejemplo n.º 5
0
 public static void MasterRemove(WorldClient client, Packet packet)
 {
     string removename;
     if(!packet.TryReadString(out removename,16))
         return;
     MasterManager.Instance.RemoveMasterMember(client.Character, removename);
 }
Ejemplo n.º 6
0
        public static void FriendInviteResponse(WorldClient pClient, Packet pPacket)
        {
            string target, sender;
            bool response;
            if (!pPacket.TryReadString(out target, 16) ||
                !pPacket.TryReadString(out sender, 16) ||
                !pPacket.TryReadBool(out response))
            {
                Log.WriteLine(LogLevel.Warn, "Could not reat friend invite response.");
                return;
            }
            WorldClient sendchar = ClientManager.Instance.GetClientByCharname(sender);
            if (sendchar == null)
            {
                Log.WriteLine(LogLevel.Warn, "Invalid friend reject received.");
                return;
            }
            if (response)
            {
                Friend sendfriend = sendchar.Character.AddFriend(pClient.Character);
                if (sendfriend != null)
                {
                    using (var packet = new Packet(SH21Type.FriendInviteResponse))
                    {
                        packet.WriteString(sender, 16);
                        packet.WriteString(target, 16);
                        packet.WriteByte(0);
                        sendchar.SendPacket(packet);
                    }

                    using (var packet = new Packet(SH21Type.FriendExtraInformation))
                    {
                        sendfriend.WritePacket(packet);
                        sendchar.SendPacket(packet);
                    }
                }
            }
            else
            {
                using (var packet = new Packet(SH21Type.FriendInviteReject))
                {
                    packet.WriteString(target, 16);
                    sendchar.SendPacket(packet);
                }
            }
        }
Ejemplo n.º 7
0
 public static void AcceptParty(WorldClient client, Packet packet)
 {
     string inviteChar;
     if (packet.TryReadString(out inviteChar, 16))
     {
         GroupManager.Instance.AcceptInvite(client, inviteChar);
     }
 }
Ejemplo n.º 8
0
 public static void FileHash(LoginClient pClient, Packet pPacket)
 {
     string hash;
     if (!pPacket.TryReadString(out hash)) {
     Log.WriteLine(LogLevel.Warn, "Empty filehash received.");
     SendFailedLogin(pClient, ServerError.Exception);
     } else
     AllowFiles(pClient, true);
 }
Ejemplo n.º 9
0
        public static void ChangePartyMaster(WorldClient client, Packet packet)
        {
            string mastername;
            if (packet.TryReadString(out mastername, 16))
            {
                if(client.Character.Group.Master.Name != client.Character.Character.Name)
                    return;

                GroupManager.Instance.ChangeMaster(client, mastername);
            }
        }
Ejemplo n.º 10
0
        public static void KickPartyMember(WorldClient client, Packet packet)
        {
            string removeName;
            if (packet.TryReadString(out removeName, 16))
            {
                if(!client.Character.Group.HasMember(removeName))
                    return;

                GroupManager.Instance.KickMember(client, removeName);
            }
        }
Ejemplo n.º 11
0
        public static void MasterRequestResponse(WorldClient client, Packet packet)
        {
            string requester = string.Empty;
            string target = string.Empty;
            byte response;
            if (!packet.TryReadString(out requester, 16))
                return;
            if (!packet.TryReadString(out target, 16))
                return;

            if (!packet.TryReadByte(out response))
                return;
            if (response == 0)
            {
                MasterManager.Instance.RemoveMasterRequest(client);
            }
            else if(response == 1)
            {
                MasterManager.Instance.MasterRequestAccept(requester, target);
            }
        }
Ejemplo n.º 12
0
        public static void CreateCharHandler(WorldClient client, Packet packet)
        {
            string name;
            byte slot, jobGender, hair, color, style;
            if (!packet.TryReadByte(out slot) || !packet.TryReadString(out name, 20) ||
                !packet.TryReadByte(out jobGender) || !packet.TryReadByte(out hair) ||
                !packet.TryReadByte(out color) || !packet.TryReadByte(out style))
            {
                Log.WriteLine(LogLevel.Warn, "Error reading create char for {0}", client.Username);
                return;
            }

            if (DatabaseChecks.IsCharNameUsed(name))
            {
                SendCharCreationError(client, CreateCharError.NameTaken);
                return;
            }
            else if (DataProvider.Instance.IsBadName(name))
            {
                SendCharCreationError(client, CreateCharError.NameInUse);
                return;
            }

            byte isMaleByte = (byte)((jobGender >> 7) & 0x01);
            byte classIDByte = (byte)((jobGender >> 2) & 0x1F);
            Job job = (Job)classIDByte;
            switch (job)
            {
                case Job.Archer:
                case Job.Cleric:
                case Job.Fighter:
                case Job.Mage:
                case Job.Trickster:
                   //create character here
                    try
                    {
                        WorldCharacter wchar = client.CreateCharacter(name, slot, hair, color, style, job, Convert.ToBoolean(isMaleByte));
                        SendCharOKResponse(client, wchar);
                    }
                    catch (Exception ex)
                    {
                        Log.WriteLine(LogLevel.Exception, "Error creating character for {0}: {1}", client.Username, ex.InnerException.ToString());
                        SendCharCreationError(client, CreateCharError.FailedToCreate);
                        return;
                    }
                    break;
                default:
                    SendCharCreationError(client, CreateCharError.WrongClass);
                    Log.WriteLine(LogLevel.Warn, "Invalid job ID at char creation from {0}", client.Username);
                    break;
            }
        }
Ejemplo n.º 13
0
        public static void PartyChat(WorldClient client, Packet packet)
        {
            if (client.Character.Group == null)
                return;

            byte msgLen;
            string msg = string.Empty;

            if (!packet.TryReadByte(out msgLen) || !packet.TryReadString(out msg, msgLen))
                return;

            client.Character.Group.Chat(client, msg);
        }
Ejemplo n.º 14
0
 public static void ChangeCharNameHandler(WorldClient client, Packet packet)
 {
     byte Character_slot;
     string charname;
     if (!packet.TryReadByte(out Character_slot) || !packet.TryReadString(out charname, 16))
         return;
     using (var pack = new Packet(SH5Type.SendCharacterChangeNewName))
     {
         pack.WriteByte(Character_slot);
         pack.WriteString(charname,16);
         pack.WriteUShort(208);//Responsecode?
     }
     //Todo ChangeinDatabase
 }
Ejemplo n.º 15
0
 public static void AddBlock(WorldClient client, Packet packet)
 {
     string AddBlockname;
     if (packet.TryReadString(out AddBlockname, 16))
     {
         client.Character.BlocketUser.Add(AddBlockname);
         using (var pp = new Packet(SH42Type.AddToBlockList))
         {
             pp.WriteUShort(7168);//unk
             pp.WriteString(AddBlockname, 16);
             pp.WriteUShort(0);//unk
             client.SendPacket(pp);
         }
         Program.DatabaseManager.GetClient().ExecuteQuery("INSERT INTO BlockUser (CharID,BlockCharname) VALUES ('" + client.Character.ID + "','" + AddBlockname + "')");
     }
 }
Ejemplo n.º 16
0
 public static void RemoveFromBlockList(WorldClient client, Packet packet)
 {
     string removename;
     if (packet.TryReadString(out removename, 16))
     {
         if (client.Character.BlocketUser.Contains(removename))
         {
             using (var pack = new Packet(SH42Type.RemoveFromBlockList))
             {
                 pack.WriteUShort(7184);//unk
                 pack.WriteString(removename, 16);
                 client.SendPacket(pack);
             }
             Program.DatabaseManager.GetClient().ExecuteQuery("DELETE FROM BlockUser WHERE CharID = '" + client.Character.ID + "' AND BlockCharname= '" + removename + "'");
             client.Character.BlocketUser.Remove(removename);
         }
     }
 }
Ejemplo n.º 17
0
        public static void TransferKey(WorldClient client, Packet packet)
        {
            string key;
            if (!packet.ReadSkip(18) || !packet.TryReadString(out key, 32))
            {
                Log.WriteLine(LogLevel.Warn, "Invalid connection request.");
                client.Disconnect();
                return;
            }
            ClientTransfer transfer = ClientManager.Instance.GetTransfer(key);
            if (transfer != null)
            {
                // Check if client does not connect from localhost or LAN,
                // and if it's connecting from the correct IP.
                // When this check is not done, people can remote hack someone.
                if (!client.Host.StartsWith("127.0") && !client.Host.StartsWith("192.") && transfer.HostIP != client.Host)
                {
                    Log.WriteLine(LogLevel.Warn, "Remotehack from {0}", client.Host);
                    SendError(client, ServerError.InvalidCredentials);
                }
                else
                {
                    if (ClientManager.Instance.RemoveTransfer(transfer.Hash) && (!Program.Maintenance || transfer.Admin > 0)) //admins can still login
                    {
                        client.Authenticated = true;
                        client.AccountID = transfer.AccountID;
                        client.Admin = transfer.Admin;
                        client.Username = transfer.Username;
                        client.lastPing = DateTime.Now; //this is so pongthread can start checking him
                        client.Pong = true;
                        client.RandomID = MathUtils.RandomizeUShort(ushort.MaxValue);

                        Log.WriteLine(LogLevel.Debug, "{0} authenticated.", client.Username);
                        SendCharacterList(client);
                    }
                }
            }
            else
            {
                Log.WriteLine(LogLevel.Warn, "Invalid client authentication from {0}", client.Host);
                SendError(client, ServerError.InvalidCredentials);
            }
        }
Ejemplo n.º 18
0
        public static void On_GameClient_UpdateGuildMessage(WorldClient Client, Packet Packet)
        {
            ushort length;
            string message;
            if (Client.Character.Guild == null
                || !Packet.TryReadUShort(out length)
                || !Packet.TryReadString(out message, length))
            {
                return;
            }

            //response packets
            using (var packet = new Packet(SH29Type.UnkMessageChange))
            {
                packet.WriteHexAsBytes("68 1B 00 92 AD F8 4F 2E 00 00 00 2B 00 00 00 17 00 00 00 07 00 00 00 06 00 00 00 70 00 00 00 06 00 00 00 BC 00 00 00 01 00 00 00 00 00");

                Client.SendPacket(packet);
            }
            using (var packet = new Packet(SH29Type.ClearGuildDetailsMessage))
            {
                packet.WriteUShort(3137);
                packet.WriteLong(0);

                Client.SendPacket(packet);
            }
            using (var packet = new Packet(SH29Type.UpdateGuildMessageResponse))
            {
                packet.WriteUShort(3137);
                Client.SendPacket(packet);
            }

            //update guild
            lock (Client.Character.Guild.ThreadLocker)
            {
                Client.Character.Guild.Message = message;
                Client.Character.Guild.MessageCreater = Client.Character;
                Client.Character.Guild.MessageCreateTime = Program.CurrentTime;

                Client.Character.Guild.Save();

                //broadcast packet to all guild members
                using (var packet = new Packet(SH29Type.SendUpdateGuildDetails))
                {
                    packet.Fill(4, 0x00);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Second);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Minute);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Hour);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Day);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Month - 1);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Year - 1900);
                    packet.WriteInt(0);
                    packet.WriteLong(0);
                    packet.WriteString(Client.Character.Character.Name, 16);
                    packet.WriteUShort(length);
                    packet.WriteString(message, length);

                    Client.Character.Guild.Broadcast(packet);
                }

                //send packet to zone that guild message changed
                using (var packet = new InterPacket(InterHeader.ZONE_GuildMessageUpdate))
                {
                    packet.WriteInt(Client.Character.Guild.ID);
                    packet.WriteInt(Client.Character.ID);
                    packet.WriteDateTime(Client.Character.Guild.MessageCreateTime);

                    packet.WriteUShort(length);
                    packet.WriteString(message, length);
                    ZoneManager.Instance.Broadcast(packet);
                }
            }
        }
Ejemplo n.º 19
0
        public static void On_GameClient_JoinAcademy(WorldClient Client, Packet Packet)
        {
            string guildName;
            if (!Packet.TryReadString(out guildName, 16))
            {
                return;
            }

            Guild guild;
            if (!GuildManager.GetGuildByName(guildName, out guild))
            {
                Handlers.Handler38.SendAcademyResponse(Client, guildName, GuildAcademyResponse.AcademyNotFound);
                return;
            }

            guild.Academy.AddMember(Client.Character, GuildAcademyRank.Member);
        }
Ejemplo n.º 20
0
        public static void On_GameClient_GuildInviteResponse(WorldClient Client, Packet pPacket)
        {
            string guildName;
            bool joinGuild;
            if (!pPacket.TryReadString(out guildName, 16)
                || !pPacket.TryReadBool(out joinGuild))
            {
                return;
            }

            //get guild
            Guild guild;
            if (GetGuildByName(guildName, out guild))
            {
                guild.AddMember(Client.Character, GuildRank.Member, null, true, true);
            }
        }
Ejemplo n.º 21
0
        public static void On_GameClient_UpdateGuildMemberRank(WorldClient Client, Packet Packet)
        {
            string targetName;
            byte newRankByte;
            if (!Packet.TryReadString(out targetName, 16)
                || !Packet.TryReadByte(out newRankByte))
            {
                return;
            }

            var newRank = (GuildRank)newRankByte;
            GuildMember member;
            GuildMember target;
            if (Client.Character.Guild != null
                && Client.Character.Guild.GetMember(Client.Character.Character.Name, out member)
                && Client.Character.Guild.GetMember(targetName, out target))
            {
                switch (member.Rank)
                {
                    case GuildRank.Master:

                        if (newRank == GuildRank.Master)
                        {
                            Client.Character.Guild.UpdateMemberRank(member, GuildRank.Member);
                        }

                        Client.Character.Guild.UpdateMemberRank(target, newRank);

                        using (var packet = new Packet(SH29Type.UpdateGuildMemberRankResponse))
                        {
                            packet.WriteString(targetName, 16);
                            packet.WriteByte(newRankByte);
                            packet.WriteUShort(3137); // ok response

                            Client.SendPacket(packet);
                        }

                        break;

                    case GuildRank.Admin:
                    case GuildRank.Advice:
                    case GuildRank.Commander:
                    case GuildRank.Default:
                    case GuildRank.Guard:
                    case GuildRank.Member:
                        return;
                }
            }
        }
Ejemplo n.º 22
0
        public static void On_GameClient_GuildChat(WorldClient Client, Packet pPacket)
        {
            byte len;
            string msg;
            if (Client.Character == null
                || !pPacket.TryReadByte(out len)
                || !pPacket.TryReadString(out msg, len))
            {
                return;
            }

            len = (byte)(len + 2);

            if (Client.Character.Guild != null)
            {
                using (var packet = new Packet(SH29Type.GuildChat))
                {
                    packet.WriteInt(Client.Character.Guild.ID);
                    packet.WriteString(Client.Character.Character.Name, 16);

                    packet.WriteByte(len);
                    packet.WriteString(msg, len);

                    Client.Character.Guild.Broadcast(packet);
                }
            }
        }
Ejemplo n.º 23
0
        public static void On_GameClient_GuildInviteRequest(WorldClient Client, Packet Packet)
        {
            string targetName;
            if (Client.Character == null
                || Client.Character.Guild == null // cheating ?
                || !Packet.TryReadString(out targetName, 16))
            {
                return;
            }

            //get target
            WorldCharacter target;
            if (!CharacterManager.GetLoggedInCharacter(targetName, out target)
                || !target.IsOnline)
            {
                return;
            }

            //todo: check for academy, too
            if (target.Guild != null)
            {
                SendGuildInviteError(Client, targetName, GuildInviteError.TargetHasAlreadyGuild);
                return;
            }

            //send invite to target
            using (var packet = new Packet(SH29Type.GuildInviteRequest))
            {
                packet.WriteString(Client.Character.Guild.Name, 16);
                packet.WriteString(Client.Character.Character.Name, 16);

                target.Client.SendPacket(packet);
            }
        }
Ejemplo n.º 24
0
        public static void TransferKeyHandler(ZoneClient client, Packet packet)
        {
            ushort randomID;
            string characterName, checksums; //TODO: check in securityclient
            if (!packet.TryReadUShort(out randomID) || !packet.TryReadString(out characterName, 16) ||
                !packet.TryReadString(out checksums, 832))
            {
                Log.WriteLine(LogLevel.Warn, "Invalid game transfer.");
                return;
            }
            ClientTransfer transfer = ClientManager.Instance.GetTransfer(characterName);
            if (transfer == null || transfer.HostIP != client.Host || transfer.RandID != randomID)
            {
                Log.WriteLine(LogLevel.Warn, "{0} tried to login without a valid client transfer.", client.Host);
                //Handler3.SendError(client, ServerError.INVALID_CREDENTIALS);
                Handler4.SendConnectError(client, ConnectErrors.RequestedCharacterIDNotMatching);
                return;
            }

            try
            {
               ClientManager.Instance.RemoveTransfer(characterName);

                 ZoneCharacter zonecharacter = new ZoneCharacter(transfer.CharID);
                if (zonecharacter.Character.AccountID != transfer.AccountID)
                {
                    Log.WriteLine(LogLevel.Warn, "Character is logging in with wrong account ID.");
                    Handler4.SendConnectError(client, ConnectErrors.RequestedCharacterIDNotMatching);
                    //Handler3.SendError(client, ServerError.INVALID_CREDENTIALS);
                    return;
                }

                client.Authenticated = true;
                client.Admin = transfer.Admin;
                client.AccountID = transfer.AccountID;
                client.Username = transfer.Username;
                client.Character = zonecharacter;
                zonecharacter.Client = client;
                //Zonecharacter.Client. = ;

                if (ClientManager.Instance.AddClient(client))
                {
                    zonecharacter.SendGetIngameChunk(); //TODO: interserver packet?
                    Log.WriteLine(LogLevel.Debug, "{0} logged in successfully!", zonecharacter.Name);
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine(LogLevel.Exception, "Error loading character {0}: {1} - {2}", characterName, ex.ToString(), ex.StackTrace);
                Handler4.SendConnectError(client, ConnectErrors.ErrorInCharacterInfo);
            }
        }
Ejemplo n.º 25
0
        public static void On_GameClient_CreateGuild(WorldClient Client, Packet Packet)
        {
            string name, password;
            bool allowGuildWar;
            if (!Packet.TryReadString(out name, 16)
                || !Packet.TryReadString(out password, 8)
                || !Packet.ReadSkip(4) // unk ?
                || !Packet.TryReadBool(out allowGuildWar))
            {
                return;
            }

            GuildCreateResponse response;

            if (Client.Character.Character.CharLevel < 20)
            {
                response = GuildCreateResponse.LevelTooLow;
            }
            else if (Client.Character.Character.Money < Guild.Price)
            {
                response = GuildCreateResponse.MoneyTooLow;
            }
            else
            {
                //encrypt guild pw
               var pwData = Encoding.UTF8.GetBytes(password);
            //                InterCrypto.Encrypt(ref pwData, 0, pwData.Length);

                Guild guild;

                //try to create guild
                lock (ThreadLocker)
                {
                    int result;
                    int guildID;
                    var createTime = Program.CurrentTime;

                    using (var con = Program.DatabaseManager.GetClient().GetConnection())
                    {
                        //insert guild in db
                        using (var cmd = con.CreateCommand())
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.CommandText = "Guild_Create";

                            cmd.Parameters.Add(new MySqlParameter("@pName", name));
                            cmd.Parameters.Add(new MySqlParameter("@pPassword", pwData));
                            cmd.Parameters.Add(new MySqlParameter("@pAllowGuildWar", allowGuildWar));
                            cmd.Parameters.Add(new MySqlParameter("@pCreaterID", Client.Character.ID));
                            cmd.Parameters.Add(new MySqlParameter("@pCreateTime", createTime));

                            var idParam = cmd.Parameters.Add(new MySqlParameter("@pID", SqlDbType.Int)
                                {
                                    Direction = ParameterDirection.Output
                                });
                            result = Convert.ToInt32(cmd.ExecuteScalar());
                            guildID = (int)idParam.Value;
                        }

                        switch (result)
                        {
                            case -1:
                                //guild name already exists (ToDo: get response code)

                                SendGuildCreateResponse(Client, name, password, allowGuildWar, GuildCreateResponse.AlredyExist);
                                return;

                            case -2: //database error @ insert guild (ToDo: get response code)
                                SendGuildCreateResponse(Client, name, password, allowGuildWar, GuildCreateResponse.Failed);
                                return;
                            case -3: //database error @ insert guild academy (ToDo: get response code)
                                SendGuildCreateResponse(Client, name, password, allowGuildWar, GuildCreateResponse.Failed);
                                return;

                            case 0:

                                //create guild
                                guild = new Guild(con, guildID, name, pwData, allowGuildWar, Client.Character, createTime);
                            //insert guild master (character will get updated)
                                guild.AddMember(Client.Character, GuildRank.Master, con, false, false);
                                //add to loaded guilds
                                LoadedGuilds.Add(guild);

                                break;

                            default:
                                return;
                        }
                    }
                }

                Client.Character.
                //revoke money
               Client.Character.ChangeMoney(Client.Character.Character.Money - Guild.Price);

                //let character broadcast guild name packet
                using (var packet = new Packet(SH29Type.GuildNameResult))
                {
                    packet.WriteInt(guild.ID);
                    packet.WriteString(guild.Name, 16);

                    BroadcastManager.Instance.BroadcastInRange(Client.Character, packet, true);
                }

                //let zone know that a guild has been loaded
                using (var packet = new InterPacket(InterHeader.ZONE_GuildCreated))
                {
                    packet.WriteInt(guild.ID);
                    packet.WriteInt(Client.Character.ID);

                    ZoneManager.Instance.Broadcast(packet);
                }

                //set response to success
                response = GuildCreateResponse.Success;
            }

            SendGuildCreateResponse(Client, name, password, allowGuildWar, response);
        }
Ejemplo n.º 26
0
        public static void ShoutHandler(ZoneClient client, Packet packet)
        {
            ZoneCharacter character = client.Character;
            byte len;
            string message;
            if (!packet.TryReadByte(out len) ||
                !packet.TryReadString(out message, len))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read shout from {0}.", character.Name);
                return;
            }

            int shoutcheck = character.ShoutCheck();
            if (shoutcheck > 0)
            {
                Handler2.SendChatBlock(character, shoutcheck);
            }
            else
            {
                ChatLog.Instance.LogChat(client.Character.Name, message, true);
                using (var broad = Shout(character.Name, message))
                {
                    character.Map.Broadcast(broad);
                }
            }
        }
Ejemplo n.º 27
0
        public static void JumpToMember(WorldClient client, Packet packet)
        {
            string pMemberName;
              if (!packet.TryReadString(out pMemberName, 16))
                  return;

              if (!client.Character.IsInGuildAcademy)
                  return;
              GuildAcademyMember pMember = client.Character.GuildAcademy.Members.Find(m => m.Character.Character.Name == pMemberName);
              if (pMember != null)
              {
                  int oldmap = client.Character.Character.PositionInfo.Map;
                  client.Character.Character.PositionInfo.Map = pMember.Character.Character.PositionInfo.Map;
                  client.Character.Character.PositionInfo.XPos = pMember.Character.Character.PositionInfo.XPos;
                  client.Character.Character.PositionInfo.YPos = pMember.Character.Character.PositionInfo.YPos;
                  client.Character.ChangeMap(oldmap);
              }
        }
Ejemplo n.º 28
0
        public static void On_GameClient_AcademyChat(WorldClient Client, Packet Packet)
        {
            byte len;
            string msg;
            if (!Packet.TryReadByte(out len)
                || !Packet.TryReadString(out msg, len))
            {
                return;
            }

            if (Client.Character.IsInGuildAcademy
                || Client.Character.IsInGuild)
            {
                if (Client.Character.IsInGuildAcademy
                    && Client.Character.GuildAcademyMember.IsChatBlocked)
                {
                    using (var packet = new Packet(SH38Type.AcademyChatBlocked))
                    {
                        packet.WriteUShort(6140);

                        Client.SendPacket(packet);
                    }

                    return;
                }

                using (var packet = new Packet(SH38Type.AcademyChat))
                {
                    packet.WriteInt(Client.Character.Guild.ID);
                    packet.WriteString(Client.Character.Character.Name, 16);
                    packet.WriteByte(len);
                    packet.WriteString(msg, len);

                    Client.Character.Guild.Broadcast(packet);

                    Client.Character.GuildAcademy.Broadcast(packet);
                }
            }
        }
Ejemplo n.º 29
0
 public static void GuildAcademyChatBlock(WorldClient client, Packet packet)
 {
     if (!client.Character.IsInGuildAcademy)
         return;
     string Blockname;
     if (!packet.TryReadString(out Blockname, 16))
         return;
     GuildAcademyMember pMember =   client.Character.GuildAcademy.Members.Find(m => m.Character.Character.Name == Blockname);
     if (pMember == null)
     return;
     pMember.IsChatBlocked = true;
     pMember.Save(Program.DatabaseManager.GetClient().GetConnection());
     using (var pack = new Packet(SH38Type.AcademyChatBlockResponse))
     {
     pack.WriteString(client.Character.Character.Name, 16);
     pack.WriteString(Blockname, 16);
     client.Character.GuildAcademy.Guild.Broadcast(pack);
     client.Character.Guild.Broadcast(pack);
     }
 }
Ejemplo n.º 30
0
        public static void On_GameClient_UpdateDetails(WorldClient Client, Packet Packet)
        {
            ushort lenght;
            string message;
            if (!Packet.TryReadUShort(out lenght))
                return;

            if (!Packet.TryReadString(out message, lenght))
                return;
            using (var pack = new Packet(SH38Type.SendChangeDetailsResponse))
            {
                pack.WriteUShort(6016);//code for ok
                Client.SendPacket(pack);
            }
            if(Client.Character.Guild != null)
            {
                Client.Character.Guild.Academy.Message = message;
                Client.Character.Guild.Academy.Save();
                using (var pack = new Packet(SH38Type.SendChangeDetails))
                {
                    pack.WriteUShort(lenght);
                    pack.WriteString(message,message.Length);
                    Client.Character.Guild.Broadcast(pack);
                    Client.Character.Guild.Academy.Broadcast(pack);
                }
            }
            else if (Client.Character.GuildAcademy != null)
            {
                Client.Character.GuildAcademy.Message = message;
                Client.Character.GuildAcademy.Save();
                using (var pack = new Packet(SH38Type.SendChangeDetails))
                {
                    pack.WriteUShort(lenght);
                    pack.WriteString(message, message.Length);
                    Client.Character.GuildAcademy.Broadcast(pack);
                }
            }
        }