TryReadString() public méthode

public TryReadString ( string &pValue ) : bool
pValue string
Résultat bool
        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);
             }
        }
Exemple #2
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);
                }
            }
        }
Exemple #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);
 }
Exemple #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);
             }
         }
     }
 }
Exemple #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);
 }
Exemple #6
0
        public static void sendPartyMessage(WorldClient client, Packet packet)
        {
            string mess;
            byte len;
            if (!packet.TryReadByte(out len) || !packet.TryReadString(out mess, len))
            {
                Log.WriteLine(LogLevel.Error, "PartyChat :: Can not parse party chat from {0}", client.Character.Character.Name);
                return;
            }

            if(Program.Entity.Parties.Where(c => c.CharNo == client.Character.Character.ID).Count() == 1)
            {
                Party getPartyInfo = Program.Entity.Parties.First(c => c.CharNo == client.Character.Character.ID);
                foreach (Party party in Program.Entity.Parties.Where(c => c.PartyNo == getPartyInfo.PartyNo))
                {
                    Character character = Program.Entity.Characters.First(c => c.ID == party.CharNo);
                    WorldClient wclient = ClientManager.Instance.GetClientByCharname(character.Name);
                    using (var ppacket = new Packet(SH8Type.PartyChat))
                    {
                        ppacket.WriteString(client.Character.Character.Name, 16);
                        ppacket.WriteByte(len);
                        ppacket.WriteString(mess, len);
                        wclient.SendPacket(ppacket);
                    }
                }
            }
            else
            {
                using (var ppacket = new Packet(SH8Type.PartyChatErr))
                {
                    ppacket.WriteUShort(1985);
                    client.SendPacket(ppacket);
                }
            }
        }
Exemple #7
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);
                }
            }
        }
Exemple #8
0
 public static void AcceptParty(WorldClient client, Packet packet)
 {
     string inviteChar;
     if (packet.TryReadString(out inviteChar, 16))
     {
         GroupManager.Instance.AcceptInvite(client, inviteChar);
     }
 }
Exemple #9
0
        public static void Login(LoginClient pClient, Packet pPacket)
        {
            string hash;
            string username;

            if (!pPacket.TryReadString(out username, 18) || !pPacket.TryReadString(out hash, 16))
            {
                Log.WriteLine(LogLevel.Warn, "Could not read user token.");
                SendFailedLogin(pClient, ServerError.EXCEPTION);
                return;
            }

            User user;

            if (Program.Entity.Users.Count() > 0 && Program.Entity.Users.Count(u => u.Username == username) == 1)
            {
                user = Program.Entity.Users.First(u => u.Username == username);
                if (user.Password.ToLower() == hash.ToLower())
                {
                    Log.WriteLine(LogLevel.Debug, "{0} tries to login.", username);
                    if (ClientManager.Instance.IsLoggedIn(user.Username))
                    {
                        Log.WriteLine(LogLevel.Warn, "{0} is trying dual login. Disconnecting.", user.Username);
                        pClient.Disconnect();
                    }
                    else if (user.Banned)
                    {
                        SendFailedLogin(pClient, ServerError.BLOCKED);
                    }
                    else
                    {
                        pClient.IsAuthenticated = true;
                        pClient.Username = user.Username;
                        pClient.AccountID = user.ID;
                        pClient.Admin = user.Admin;
                        AllowFiles(pClient, true);
                        WorldList(pClient, false);
                    }
                }
                else SendFailedLogin(pClient, ServerError.INVALID_CREDENTIALS);
            }
            else SendFailedLogin(pClient, ServerError.INVALID_CREDENTIALS);
        }
Exemple #10
0
        public static void getWhisperMessage(WorldClient client, Packet packet)
        {
            string toChar;
            byte len;
            string mess;
            if (!packet.TryReadString(out toChar, 16) || !packet.TryReadByte(out len) || !packet.TryReadString(out mess, len))
            {
                Log.WriteLine(LogLevel.Error, "WhisperChat :: Can not parse Whisper request from {0}", client.Character.Character.Name);
                return;
            }

            WorldClient wclient = ClientManager.Instance.GetClientByCharname(toChar);

            if (wclient != null)
            {
                using (var ppacket = new Packet(SH8Type.WhisperTo))
                {
                    ppacket.WriteString(toChar, 16);
                    ppacket.WriteByte(len);
                    ppacket.WriteString(mess, len);
                    client.SendPacket(ppacket);
                }

                using (var ppacket = new Packet(SH8Type.WhisperFrom))
                {
                    ppacket.WriteString(client.Character.Character.Name, 16);
                    ppacket.WriteByte(0); // unk
                    ppacket.WriteByte(len);
                    ppacket.WriteString(mess, len);
                    wclient.SendPacket(ppacket);
                }
            }
            else
            {
                using (var ppacket = new Packet(SH8Type.WhisperErrAnswer))
                {
                    ppacket.WriteUShort(3945);
                    ppacket.WriteString(toChar, 16);
                    client.SendPacket(ppacket);
                }
            }
        }
Exemple #11
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);
 }
Exemple #12
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);
            }
        }
Exemple #13
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);
            }
        }
Exemple #14
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, 16) ||
                !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:
                case Job.Crusader:
                   //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;
            }
        }
Exemple #15
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);
            }
        }
Exemple #16
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);
        }
 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 here f***s shit up?
     }
 }
Exemple #18
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
 }
Exemple #19
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 + "')");
     }
 }
Exemple #20
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);
         }
     }
 }
Exemple #21
0
        public static void PartyInviteDecline(WorldClient client, Packet packet)
        {
            string charname;
            if(!packet.TryReadString(out charname, 16))
            {
                Log.WriteLine(LogLevel.Error, "PartySystem :: Got unknown request from Client {0}", client.Character.Character.Name);
            }

            WorldClient otherclient = ClientManager.Instance.GetClientByCharname(charname);
            if (otherclient != null)
            {
                SendPartyInviteDecline(otherclient, client.Character.Character.Name);
            }
            else
            {
                Log.WriteLine(LogLevel.Error, "PartySystem :: Can not finde Client Handler (Offline?) for {0}", charname);
            }
        }
Exemple #22
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.INVALID_CREDENTIALS);
                }
                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.AccountKey = key;
                        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.INVALID_CREDENTIALS);
            }
        }
Exemple #23
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);
                }
            }
        }
Exemple #24
0
 public static void VersionInfo(LoginClient pClient, Packet pPacket)
 {
     string year;
     ushort version;
     if (!pPacket.TryReadString(out year, 20) ||
         !pPacket.TryReadUShort(out version))
     {
         Log.WriteLine(LogLevel.Warn, "Invalid client version.");
         pClient.Disconnect();
         return;
     }
     Log.WriteLine(LogLevel.Debug, "Client version {0}:{1}.", year, version);
     using (Packet response = new Packet(SH3Type.VersionAllowed))
     {
         response.WriteShort(1);
         pClient.SendPacket(response);
     }
 }
 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);
     }
 }
        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);
                }
            }
        }
        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);
        }
        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);
                }
            }
        }
        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);
              }
        }
Exemple #30
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);
            }
        }