public void SendGuildQuery(ClientClass client, uint guildId) { if (guildId == 0L) { return; } // WARNING: This opcode is used also in character enum, so there must not be used any references to CharacterObject, only ClientClass // DONE: Load the guild if it doesn't exist in the memory if (GuilDs.ContainsKey(guildId) == false) { var tmpGuild = new Guild(guildId); GuilDs.Add(guildId, tmpGuild); } var response = new PacketClass(Opcodes.SMSG_GUILD_QUERY_RESPONSE); response.AddUInt32(guildId); response.AddString(GuilDs[guildId].Name); for (var i = 0; i <= 9; i++) { response.AddString(GuilDs[guildId].Ranks[i]); } response.AddInt32(GuilDs[guildId].EmblemStyle); response.AddInt32(GuilDs[guildId].EmblemColor); response.AddInt32(GuilDs[guildId].BorderStyle); response.AddInt32(GuilDs[guildId].BorderColor); response.AddInt32(GuilDs[guildId].BackgroundColor); response.AddInt32(0); client.Send(response); response.Dispose(); }
public void On_CMSG_GMTICKET_GETTICKET(PacketClass packet, ClientClass client) { _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GMTICKET_GETTICKET", client.IP, client.Port); var smsgGmticketGetticket = new PacketClass(Opcodes.SMSG_GMTICKET_GETTICKET); var mySqlResult = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query(string.Format("SELECT * FROM characters_tickets WHERE char_guid = {0};", client.Character.Guid), ref mySqlResult); if (mySqlResult.Rows.Count > 0) { smsgGmticketGetticket.AddInt32((int)GmTicketGetResult.GMTICKET_AVAILABLE); smsgGmticketGetticket.AddString(Conversions.ToString(mySqlResult.Rows[0]["ticket_text"])); } else { smsgGmticketGetticket.AddInt32((int)GmTicketGetResult.GMTICKET_NOTICKET); } client.Send(smsgGmticketGetticket); smsgGmticketGetticket.Dispose(); var smsgQueryTimeResponse = new PacketClass(Opcodes.SMSG_QUERY_TIME_RESPONSE); smsgQueryTimeResponse.AddInt32(_clusterServiceLocator.NativeMethods.timeGetTime("")); // GetTimestamp(Now)) client.Send(smsgQueryTimeResponse); smsgQueryTimeResponse.Dispose(); }
public void On_CMSG_GUILD_LEAVE(PacketClass packet, ClientClass client) { // packet.GetInt16() _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GUILD_LEAVE", client.IP, client.Port); // DONE: Checks if (!client.Character.IsInGuild) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD); return; } if (client.Character.IsGuildLeader) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_QUIT_S, GuildError.GUILD_LEADER_LEAVE); return; } _clusterServiceLocator.WcGuild.RemoveCharacterFromGuild(client.Character); _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_QUIT_S, GuildError.GUILD_PLAYER_NO_MORE_IN_GUILD, client.Character.Name); var response = new PacketClass(Opcodes.SMSG_GUILD_EVENT); response.AddInt8((byte)GuildEvent.LEFT); response.AddInt8(1); response.AddString(client.Character.Name); var argnotTo = 0UL; _clusterServiceLocator.WcGuild.BroadcastToGuild(response, client.Character.Guild, notTo: argnotTo); response.Dispose(); }
public void SendGroupList() { var groupCount = GetMembersCount(); for (byte i = 0, loopTo = (byte)(Members.Length - 1); i <= loopTo; i++) { if (Members[i] is object) { var packet = new PacketClass(Opcodes.SMSG_GROUP_LIST); packet.AddInt8((byte)Type); // GroupType 0:Party 1:Raid var memberFlags = (byte)(i / _clusterServiceLocator.GlobalConstants.GROUP_SUBGROUPSIZE); // If Members(i).GroupAssistant Then MemberFlags = MemberFlags Or &H1 packet.AddInt8(memberFlags); packet.AddInt32(groupCount - 1); for (byte j = 0, loopTo1 = (byte)(Members.Length - 1); j <= loopTo1; j++) { if (Members[j] is object && !ReferenceEquals(Members[j], Members[i])) { packet.AddString(Members[j].Name); packet.AddUInt64(Members[j].Guid); if (Members[j].IsInWorld) { packet.AddInt8(1); // CharOnline? } else { packet.AddInt8(0); } // CharOnline? memberFlags = (byte)(j / _clusterServiceLocator.GlobalConstants.GROUP_SUBGROUPSIZE); // If Members(j).GroupAssistant Then MemberFlags = MemberFlags Or &H1 packet.AddInt8(memberFlags); } } packet.AddUInt64(Members[Leader].Guid); packet.AddInt8((byte)LootMethod); if (_lootMaster != 255) { packet.AddUInt64(Members[_lootMaster].Guid); } else { packet.AddUInt64(0UL); } packet.AddInt8((byte)LootThreshold); packet.AddInt16(0); if (Members[i].Client is object) { Members[i].Client.Send(packet); } packet.Dispose(); } } }
public void SendGuildResult(ClientClass client, GuildCommand command, GuildError result, string text = "") { var response = new PacketClass(Opcodes.SMSG_GUILD_COMMAND_RESULT); response.AddInt32((int)command); response.AddString(text); response.AddInt32((int)result); client.Send(response); response.Dispose(); }
public void SendPartyResult(ClientClass objCharacter, string name, PartyCommand operation, PartyCommandResult result) { var response = new PacketClass(Opcodes.SMSG_PARTY_COMMAND_RESULT); response.AddInt32((byte)operation); response.AddString(name); response.AddInt32((byte)result); objCharacter.Send(response); response.Dispose(); }
public void On_CMSG_GUILD_DECLINE(PacketClass packet, ClientClass client) { client.Character.GuildInvited = 0U; if (_clusterServiceLocator.WorldCluster.CharacteRs.ContainsKey((ulong)Conversions.ToLong(client.Character.GuildInvitedBy))) { var response = new PacketClass(Opcodes.SMSG_GUILD_DECLINE); response.AddString(client.Character.Name); _clusterServiceLocator.WorldCluster.CharacteRs[(ulong)Conversions.ToLong(client.Character.GuildInvitedBy)].Client.Send(response); response.Dispose(); } }
public void On_CMSG_WHOIS(PacketClass packet, ClientClass client) { packet.GetInt16(); var name = packet.GetString(); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_WHOIS [{2}]", client.IP, client.Port, name); var response = new PacketClass(Opcodes.SMSG_WHOIS); response.AddString("This feature is not available yet."); client.Send(response); response.Dispose(); }
public void On_CMSG_GROUP_DECLINE(PacketClass packet, ClientClass client) { _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GROUP_DECLINE", client.IP, client.Port); if (client.Character.GroupInvitedFlag) { var response = new PacketClass(Opcodes.SMSG_GROUP_DECLINE); response.AddString(client.Character.Name); client.Character.Group.GetLeader().Client.Send(response); response.Dispose(); client.Character.Group.CheckMembers(); client.Character.Group = null; client.Character.GroupInvitedFlag = false; } }
// Members Options public void SendGuildMotd(WcHandlerCharacter.CharacterObject objCharacter) { if (objCharacter.IsInGuild) { if (!string.IsNullOrEmpty(objCharacter.Guild.Motd)) { var response = new PacketClass(Opcodes.SMSG_GUILD_EVENT); response.AddInt8((byte)GuildEvent.MOTD); response.AddInt8(1); response.AddString(objCharacter.Guild.Motd); objCharacter.Client.Send(response); response.Dispose(); } } }
public void NotifyGuildStatus(WcHandlerCharacter.CharacterObject objCharacter, GuildEvent status) { if (objCharacter.Guild is null) { return; } var statuspacket = new PacketClass(Opcodes.SMSG_GUILD_EVENT); statuspacket.AddInt8((byte)status); statuspacket.AddInt8(1); statuspacket.AddString(objCharacter.Name); statuspacket.AddInt8(0); statuspacket.AddInt8(0); statuspacket.AddInt8(0); BroadcastToGuild(statuspacket, objCharacter.Guild, objCharacter.Guid); statuspacket.Dispose(); }
public void NewLeader(WcHandlerCharacter.CharacterObject leaver = null) { byte chosenMember = 255; var newLootMaster = false; for (byte i = 0, loopTo = (byte)(Members.Length - 1); i <= loopTo; i++) { if (Members[i] is object && Members[i].Client is object) { if (leaver is object && ReferenceEquals(leaver, Members[i])) { if (i == _lootMaster) { newLootMaster = true; } if (chosenMember != 255) { break; } } else if (Members[i].GroupAssistant && chosenMember == 255) { chosenMember = i; } else if (chosenMember == 255) { chosenMember = i; } } } if (chosenMember != 255) { Leader = chosenMember; if (newLootMaster) { _lootMaster = Leader; } var response = new PacketClass(Opcodes.SMSG_GROUP_SET_LEADER); response.AddString(Members[Leader].Name); Broadcast(response); response.Dispose(); _clusterServiceLocator.WcNetwork.WorldServer.GroupSendUpdate(Id); } }
public void SetLeader(WcHandlerCharacter.CharacterObject objCharacter) { for (byte i = 0, loopTo = (byte)Members.Length; i <= loopTo; i++) { if (ReferenceEquals(Members[i], objCharacter)) { Leader = i; break; } } var packet = new PacketClass(Opcodes.SMSG_GROUP_SET_LEADER); packet.AddString(objCharacter.Name); Broadcast(packet); packet.Dispose(); _clusterServiceLocator.WcNetwork.WorldServer.GroupSendUpdate(Id); SendGroupList(); }
public void On_CMSG_GUILD_ACCEPT(PacketClass packet, ClientClass client) { if (client.Character.GuildInvited == 0L) { throw new ApplicationException("Character accepting guild invitation whihtout being invited."); } _clusterServiceLocator.WcGuild.AddCharacterToGuild(client.Character, (int)client.Character.GuildInvited); client.Character.GuildInvited = 0U; var response = new PacketClass(Opcodes.SMSG_GUILD_EVENT); response.AddInt8((byte)GuildEvent.JOINED); response.AddInt8(1); response.AddString(client.Character.Name); var argnotTo = 0UL; _clusterServiceLocator.WcGuild.BroadcastToGuild(response, client.Character.Guild, notTo: argnotTo); response.Dispose(); _clusterServiceLocator.WcGuild.SendGuildRoster(client.Character); _clusterServiceLocator.WcGuild.SendGuildMotd(client.Character); }
public void On_CMSG_GUILD_MOTD(PacketClass packet, ClientClass client) { // Isn't the client even sending a null terminator for the motd if it's empty? if (packet.Data.Length - 1 < 6) { return; } packet.GetInt16(); var motd = ""; if (packet.Length != 4) { motd = packet.GetString().Replace("\"", "_").Replace("'", "_"); } _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GUILD_MOTD", client.IP, client.Port); if (!client.Character.IsInGuild) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD); return; } if (!client.Character.IsGuildRightSet(GuildRankRights.GR_RIGHT_SETMOTD)) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PERMISSIONS); return; } client.Character.Guild.Motd = motd; _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Update(string.Format("UPDATE guilds SET guild_MOTD = '{1}' WHERE guild_id = '{0}';", client.Character.Guild.Id, motd)); var response = new PacketClass(Opcodes.SMSG_GUILD_EVENT); response.AddInt8((byte)GuildEvent.MOTD); response.AddInt8(1); response.AddString(motd); // DONE: Send message to everyone in the guild var argnotTo = 0UL; _clusterServiceLocator.WcGuild.BroadcastToGuild(response, client.Character.Guild, notTo: argnotTo); response.Dispose(); }
public void On_CMSG_GUILD_INFO(PacketClass packet, ClientClass client) { packet.GetInt16(); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GUILD_INFO", client.IP, client.Port); if (!client.Character.IsInGuild) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD); return; } var response = new PacketClass(Opcodes.SMSG_GUILD_INFO); response.AddString(client.Character.Guild.Name); response.AddInt32(client.Character.Guild.CDay); response.AddInt32(client.Character.Guild.CMonth); response.AddInt32(client.Character.Guild.CYear); response.AddInt32(0); response.AddInt32(0); client.Send(response); response.Dispose(); }
public void On_CMSG_NAME_QUERY(PacketClass packet, ClientClass client) { if (packet.Data.Length - 1 < 13) { return; } packet.GetInt16(); var guid = packet.GetUInt64(); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_NAME_QUERY [GUID={2:X}]", client.IP, client.Port, guid); if (_clusterServiceLocator.CommonGlobalFunctions.GuidIsPlayer(guid) && _clusterServiceLocator.WorldCluster.CharacteRs.ContainsKey(guid)) { var smsgNameQueryResponse = new PacketClass(Opcodes.SMSG_NAME_QUERY_RESPONSE); smsgNameQueryResponse.AddUInt64(guid); smsgNameQueryResponse.AddString(_clusterServiceLocator.WorldCluster.CharacteRs[guid].Name); smsgNameQueryResponse.AddInt32((byte)_clusterServiceLocator.WorldCluster.CharacteRs[guid].Race); smsgNameQueryResponse.AddInt32(_clusterServiceLocator.WorldCluster.CharacteRs[guid].Gender); smsgNameQueryResponse.AddInt32((byte)_clusterServiceLocator.WorldCluster.CharacteRs[guid].Classe); smsgNameQueryResponse.AddInt8(0); client.Send(smsgNameQueryResponse); smsgNameQueryResponse.Dispose(); } else { // DONE: Send it to the world server if it wasn't found in the cluster try { client.Character.GetWorld.ClientPacket(client.Index, packet.Data); } catch { _clusterServiceLocator.WcNetwork.WorldServer.Disconnect("NULL", new List <uint> { client.Character.Map }); } } }
public void On_CMSG_GROUP_INVITE(PacketClass packet, ClientClass client) { if (packet.Data.Length - 1 < 6) { return; } packet.GetInt16(); var name = _clusterServiceLocator.Functions.CapitalizeName(packet.GetString()); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GROUP_INVITE [{2}]", client.IP, client.Port, name); var guid = 0UL; _clusterServiceLocator.WorldCluster.CharacteRsLock.AcquireReaderLock(_clusterServiceLocator.GlobalConstants.DEFAULT_LOCK_TIMEOUT); foreach (var character in _clusterServiceLocator.WorldCluster.CharacteRs) { if (_clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(character.Value.Name) == _clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(name)) { guid = character.Value.Guid; break; } } _clusterServiceLocator.WorldCluster.CharacteRsLock.ReleaseReaderLock(); var errCode = PartyCommandResult.INVITE_OK; // TODO: InBattlegrounds: INVITE_RESTRICTED if (guid == 0m) { errCode = PartyCommandResult.INVITE_NOT_FOUND; } else if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].IsInWorld == false) { errCode = PartyCommandResult.INVITE_NOT_FOUND; } else if (_clusterServiceLocator.Functions.GetCharacterSide((byte)_clusterServiceLocator.WorldCluster.CharacteRs[guid].Race) != _clusterServiceLocator.Functions.GetCharacterSide((byte)client.Character.Race)) { errCode = PartyCommandResult.INVITE_NOT_SAME_SIDE; } else if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].IsInGroup) { errCode = PartyCommandResult.INVITE_ALREADY_IN_GROUP; var denied = new PacketClass(Opcodes.SMSG_GROUP_INVITE); denied.AddInt8(0); denied.AddString(client.Character.Name); _clusterServiceLocator.WorldCluster.CharacteRs[guid].Client.Send(denied); denied.Dispose(); } else if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].IgnoreList.Contains(client.Character.Guid)) { errCode = PartyCommandResult.INVITE_IGNORED; } else if (!client.Character.IsInGroup) { var newGroup = new Group(client.Character, _clusterServiceLocator); // TODO: Need to do fully test this _clusterServiceLocator.WorldCluster.CharacteRs[guid].Group = newGroup; _clusterServiceLocator.WorldCluster.CharacteRs[guid].GroupInvitedFlag = true; } else if (client.Character.Group.IsFull) { errCode = PartyCommandResult.INVITE_PARTY_FULL; } else if (client.Character.IsGroupLeader == false && client.Character.GroupAssistant == false) { errCode = PartyCommandResult.INVITE_NOT_LEADER; } else { _clusterServiceLocator.WorldCluster.CharacteRs[guid].Group = client.Character.Group; _clusterServiceLocator.WorldCluster.CharacteRs[guid].GroupInvitedFlag = true; } SendPartyResult(client, name, PartyCommand.PARTY_OP_INVITE, errCode); if (errCode == PartyCommandResult.INVITE_OK) { var invited = new PacketClass(Opcodes.SMSG_GROUP_INVITE); invited.AddInt8(1); invited.AddString(client.Character.Name); _clusterServiceLocator.WorldCluster.CharacteRs[guid].Client.Send(invited); invited.Dispose(); } }
public void SendGuildRoster(WcHandlerCharacter.CharacterObject objCharacter) { if (!objCharacter.IsInGuild) { return; } // DONE: Count the ranks byte guildRanksCount = 0; for (var i = 0; i <= 9; i++) { if (!string.IsNullOrEmpty(objCharacter.Guild.Ranks[i])) { guildRanksCount = (byte)(guildRanksCount + 1); } } // DONE: Count the members var members = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query("SELECT char_online, char_guid, char_name, char_class, char_level, char_zone_id, char_logouttime, char_guildRank, char_guildPNote, char_guildOffNote FROM characters WHERE char_guildId = " + objCharacter.Guild.Id + ";", ref members); var response = new PacketClass(Opcodes.SMSG_GUILD_ROSTER); response.AddInt32(members.Rows.Count); response.AddString(objCharacter.Guild.Motd); response.AddString(objCharacter.Guild.Info); response.AddInt32(guildRanksCount); for (var i = 0; i <= 9; i++) { if (!string.IsNullOrEmpty(objCharacter.Guild.Ranks[i])) { response.AddUInt32(objCharacter.Guild.RankRights[i]); } } var officer = objCharacter.IsGuildRightSet(GuildRankRights.GR_RIGHT_VIEWOFFNOTE); for (int i = 0, loopTo = members.Rows.Count - 1; i <= loopTo; i++) { if (members.Rows[i].As <byte>("char_online") == 1) { response.AddUInt64(members.Rows[i].As <ulong>("char_guid")); response.AddInt8(1); // OnlineFlag response.AddString(members.Rows[i].As <string>("char_name")); response.AddInt32(members.Rows[i].As <int>("char_guildRank")); response.AddInt8(members.Rows[i].As <byte>("char_level")); response.AddInt8(members.Rows[i].As <byte>("char_class")); response.AddInt32(members.Rows[i].As <int>("char_zone_id")); response.AddString(members.Rows[i].As <string>("char_guildPNote")); if (officer) { response.AddString(members.Rows[i].As <string>("char_guildOffNote")); } else { response.AddInt8(0); } } else { response.AddUInt64(members.Rows[i].As <ulong>("char_guid")); response.AddInt8(0); // OfflineFlag response.AddString(members.Rows[i].As <string>("char_name")); response.AddInt32(members.Rows[i].As <int>("char_guildRank")); response.AddInt8(members.Rows[i].As <byte>("char_level")); response.AddInt8(members.Rows[i].As <byte>("char_class")); response.AddInt32(members.Rows[i].As <int>("char_zone_id")); // 0 = < 1 hour / 0.1 = 2.4 hours / 1 = 24 hours (1 day) // (Time logged out / 86400) = Days offline var daysOffline = (float)((_clusterServiceLocator.Functions.GetTimestamp(DateAndTime.Now) - members.Rows[i].As <uint>("char_logouttime")) / (double)DateInterval.Day); response.AddSingle(daysOffline); // Days offline response.AddString(members.Rows[i].As <string>("char_guildPNote")); if (officer) { response.AddString(members.Rows[i].As <string>("char_guildOffNote")); } else { response.AddInt8(0); } } } objCharacter.Client.Send(response); response.Dispose(); }
public void On_CMSG_GUILD_LEADER(PacketClass packet, ClientClass client) { if (packet.Data.Length - 1 < 6) { return; } packet.GetInt16(); var playerName = packet.GetString(); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GUILD_LEADER [{2}]", client.IP, client.Port, playerName); if (playerName.Length < 2) { return; } playerName = _clusterServiceLocator.Functions.CapitalizeName(playerName); if (!client.Character.IsInGuild) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD); return; } if (!client.Character.IsGuildLeader) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PERMISSIONS); return; } // DONE: Find new leader's GUID var mySqlQuery = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query("SELECT char_guid, char_guildId, char_guildrank FROM characters WHERE char_name = '" + playerName + "';", ref mySqlQuery); if (mySqlQuery.Rows.Count == 0) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_PLAYER_NOT_FOUND, playerName); return; } if (mySqlQuery.Rows[0].As <uint>("char_guildId") != client.Character.Guild.Id) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD_S, playerName); return; } var playerGuid = mySqlQuery.Rows[0].As <ulong>("char_guid"); client.Character.GuildRank = 1; // Officer client.Character.SendGuildUpdate(); if (_clusterServiceLocator.WorldCluster.CharacteRs.ContainsKey(playerGuid)) { _clusterServiceLocator.WorldCluster.CharacteRs[playerGuid].GuildRank = 0; _clusterServiceLocator.WorldCluster.CharacteRs[playerGuid].SendGuildUpdate(); } client.Character.Guild.Leader = playerGuid; _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Update(string.Format("UPDATE guilds SET guild_leader = \"{1}\" WHERE guild_id = {0};", client.Character.Guild.Id, playerGuid)); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Update(string.Format("UPDATE characters SET char_guildRank = {0} WHERE char_guid = {1};", 0, playerGuid)); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Update(string.Format("UPDATE characters SET char_guildRank = {0} WHERE char_guid = {1};", client.Character.GuildRank, client.Character.Guid)); // DONE: Send notify message var response = new PacketClass(Opcodes.SMSG_GUILD_EVENT); response.AddInt8((byte)GuildEvent.LEADER_CHANGED); response.AddInt8(2); response.AddString(client.Character.Name); response.AddString(playerName); var argnotTo = 0UL; _clusterServiceLocator.WcGuild.BroadcastToGuild(response, client.Character.Guild, notTo: argnotTo); response.Dispose(); }
public void On_CMSG_MESSAGECHAT(PacketClass packet, ClientClass client) { if (packet.Data.Length - 1 < 14) { return; } packet.GetInt16(); var msgType = (ChatMsg)packet.GetInt32(); var msgLanguage = (LANGUAGES)packet.GetInt32(); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_MESSAGECHAT [{2}:{3}]", client.IP, client.Port, msgType, msgLanguage); switch (msgType) { case var @case when @case == ChatMsg.CHAT_MSG_CHANNEL: { var channel = packet.GetString(); if (packet.Data.Length - 1 < 14 + channel.Length) { return; } var message = packet.GetString(); // DONE: Broadcast to all if (_clusterServiceLocator.WsHandlerChannels.ChatChanneLs.ContainsKey(channel)) { _clusterServiceLocator.WsHandlerChannels.ChatChanneLs[channel].Say(message, (int)msgLanguage, client.Character); } return; } case var case1 when case1 == ChatMsg.CHAT_MSG_WHISPER: { var argname = packet.GetString(); var toUser = _clusterServiceLocator.Functions.CapitalizeName(argname); if (packet.Data.Length - 1 < 14 + toUser.Length) { return; } var message = packet.GetString(); // DONE: Handle admin/gm commands // If ToUser = "******" AndAlso client.Character.Access > 0 Then // client.Character.GetWorld.ClientPacket(Client.Index, packet.Data) // Exit Sub // End If // DONE: Send whisper MSG to receiver var guid = 0UL; _clusterServiceLocator.WorldCluster.CharacteRsLock.AcquireReaderLock(_clusterServiceLocator.GlobalConstants.DEFAULT_LOCK_TIMEOUT); foreach (var character in _clusterServiceLocator.WorldCluster.CharacteRs) { if (_clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(character.Value.Name) == _clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(toUser)) { guid = character.Value.Guid; break; } } _clusterServiceLocator.WorldCluster.CharacteRsLock.ReleaseReaderLock(); if (guid > 0m && _clusterServiceLocator.WorldCluster.CharacteRs.ContainsKey(guid)) { // DONE: Check if ignoring if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].IgnoreList.Contains(client.Character.Guid) && client.Character.Access < AccessLevel.GameMaster) { // Client.Character.SystemMessage(String.Format("{0} is ignoring you.", ToUser)) client.Character.SendChatMessage(guid, "", ChatMsg.CHAT_MSG_IGNORED, (int)LANGUAGES.LANG_UNIVERSAL, ""); } else { // To message client.Character.SendChatMessage(guid, message, ChatMsg.CHAT_MSG_WHISPER_INFORM, (int)msgLanguage, ""); if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].Dnd == false || client.Character.Access >= AccessLevel.GameMaster) { // From message _clusterServiceLocator.WorldCluster.CharacteRs[guid].SendChatMessage(client.Character.Guid, message, ChatMsg.CHAT_MSG_WHISPER, (int)msgLanguage, ""); } else { // DONE: Send the DND message client.Character.SendChatMessage(guid, _clusterServiceLocator.WorldCluster.CharacteRs[guid].AfkMessage, ChatMsg.CHAT_MSG_DND, (int)msgLanguage, ""); } // DONE: Send the AFK message if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].Afk) { client.Character.SendChatMessage(guid, _clusterServiceLocator.WorldCluster.CharacteRs[guid].AfkMessage, ChatMsg.CHAT_MSG_AFK, (int)msgLanguage, ""); } } } else { var smsgChatPlayerNotFound = new PacketClass(Opcodes.SMSG_CHAT_PLAYER_NOT_FOUND); smsgChatPlayerNotFound.AddString(toUser); client.Send(smsgChatPlayerNotFound); smsgChatPlayerNotFound.Dispose(); } break; } case var case2 when case2 == ChatMsg.CHAT_MSG_PARTY: case var case3 when case3 == ChatMsg.CHAT_MSG_RAID: case var case4 when case4 == ChatMsg.CHAT_MSG_RAID_LEADER: case var case5 when case5 == ChatMsg.CHAT_MSG_RAID_WARNING: { var message = packet.GetString(); // DONE: Check in group if (!client.Character.IsInGroup) { break; } // DONE: Broadcast to party client.Character.Group.SendChatMessage(client.Character, message, msgLanguage, msgType); break; } case var case6 when case6 == ChatMsg.CHAT_MSG_AFK: { var message = packet.GetString(); // TODO: Can not be used while in combat! if (string.IsNullOrEmpty(message) || client.Character.Afk == false) { if (client.Character.Afk == false) { if (string.IsNullOrEmpty(message)) { message = "Away From Keyboard"; } client.Character.AfkMessage = message; } client.Character.Afk = !client.Character.Afk; if (client.Character.Afk && client.Character.Dnd) { client.Character.Dnd = false; } if (client.Character.Afk) { client.Character.ChatFlag = ChatFlag.FLAGS_AFK; } else { client.Character.ChatFlag = ChatFlag.FLAGS_NONE; } // DONE: Pass the packet to the world server so it also knows about it client.Character.GetWorld.ClientPacket(client.Index, packet.Data); } break; } case var case7 when case7 == ChatMsg.CHAT_MSG_DND: { var message = packet.GetString(); if (string.IsNullOrEmpty(message) || client.Character.Dnd == false) { if (client.Character.Dnd == false) { if (string.IsNullOrEmpty(message)) { message = "Do Not Disturb"; } client.Character.AfkMessage = message; } client.Character.Dnd = !client.Character.Dnd; if (client.Character.Dnd && client.Character.Afk) { client.Character.Afk = false; } if (client.Character.Dnd) { client.Character.ChatFlag = ChatFlag.FLAGS_DND; } else { client.Character.ChatFlag = ChatFlag.FLAGS_NONE; } // DONE: Pass the packet to the world server so it also knows about it client.Character.GetWorld.ClientPacket(client.Index, packet.Data); } break; } case var case8 when case8 == ChatMsg.CHAT_MSG_SAY: case var case9 when case9 == ChatMsg.CHAT_MSG_YELL: case var case10 when case10 == ChatMsg.CHAT_MSG_EMOTE: { client.Character.GetWorld.ClientPacket(client.Index, packet.Data); break; } case var case11 when case11 == ChatMsg.CHAT_MSG_GUILD: { var message = packet.GetString(); // DONE: Broadcast to guild _clusterServiceLocator.WcGuild.BroadcastChatMessageGuild(client.Character, message, msgLanguage, (int)client.Character.Guild.Id); break; } case var case12 when case12 == ChatMsg.CHAT_MSG_OFFICER: { var message = packet.GetString(); // DONE: Broadcast to officer chat _clusterServiceLocator.WcGuild.BroadcastChatMessageOfficer(client.Character, message, msgLanguage, (int)client.Character.Guild.Id); break; } default: { _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.FAILED, "[{0}:{1}] Unknown chat message [msgType={2}, msgLanguage={3}]", client.IP, client.Port, msgType, msgLanguage); _clusterServiceLocator.Packets.DumpPacket(packet.Data, client); break; } } }
// User Options public void On_CMSG_GUILD_INVITE(PacketClass packet, ClientClass client) { if (packet.Data.Length - 1 < 6) { return; } packet.GetInt16(); var playerName = packet.GetString(); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GUILD_INVITE [{2}]", client.IP, client.Port, playerName); // DONE: Inviter checks if (!client.Character.IsInGuild) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD); return; } if (!client.Character.IsGuildRightSet(GuildRankRights.GR_RIGHT_INVITE)) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PERMISSIONS); return; } // DONE: Find invited player's guid var q = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query("SELECT char_guid FROM characters WHERE char_name = '" + playerName.Replace("'", "_") + "';", ref q); // DONE: Invited checks if (q.Rows.Count == 0) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_NAME_INVALID); return; } if (!_clusterServiceLocator.WorldCluster.CharacteRs.ContainsKey(q.Rows[0].As <ulong>("char_guid"))) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_PLAYER_NOT_FOUND, playerName); return; } var objCharacter = _clusterServiceLocator.WorldCluster.CharacteRs[q.Rows[0].As <ulong>("char_guid")]; if (objCharacter.IsInGuild) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.ALREADY_IN_GUILD, playerName); return; } if (objCharacter.Side != client.Character.Side) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_NOT_ALLIED, playerName); return; } if (objCharacter.GuildInvited != 0L) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.ALREADY_INVITED_TO_GUILD, playerName); return; } var response = new PacketClass(Opcodes.SMSG_GUILD_INVITE); response.AddString(client.Character.Name); response.AddString(client.Character.Guild.Name); objCharacter.Client.Send(response); response.Dispose(); objCharacter.GuildInvited = client.Character.Guild.Id; objCharacter.GuildInvitedBy = client.Character.Guid; }
public void On_CMSG_ADD_FRIEND(PacketClass packet, ClientClass client) { if (packet.Data.Length - 1 < 6) { return; } packet.GetInt16(); var response = new PacketClass(Opcodes.SMSG_FRIEND_STATUS); var name = packet.GetString(); var guid = 0UL; _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_ADD_FRIEND [{2}]", client.IP, client.Port, name); // DONE: Get GUID from DB var q = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query(string.Format("SELECT char_guid, char_race FROM characters WHERE char_name = \"{0}\";", name), ref q); if (q.Rows.Count > 0) { guid = (ulong)q.Rows[0].As <long>("char_guid"); var friendSide = _clusterServiceLocator.Functions.GetCharacterSide(q.Rows[0].As <byte>("char_race")); q.Clear(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query(string.Format("SELECT flags FROM character_social WHERE flags = {0}", Conversions.ToByte(SocialFlag.SOCIAL_FLAG_FRIEND)), ref q); var numberOfFriends = q.Rows.Count; q.Clear(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query(string.Format("SELECT flags FROM character_social WHERE guid = {0} AND friend = {1} AND flags = {2};", client.Character.Guid, guid, Conversions.ToByte(SocialFlag.SOCIAL_FLAG_FRIEND)), ref q); if (guid == client.Character.Guid) { response.AddInt8((byte)FriendResult.FRIEND_SELF); response.AddUInt64(guid); } else if (q.Rows.Count > 0) { response.AddInt8((byte)FriendResult.FRIEND_ALREADY); response.AddUInt64(guid); } else if (numberOfFriends >= (int)SocialList.MAX_FRIENDS_ON_LIST) { response.AddInt8((byte)FriendResult.FRIEND_LIST_FULL); response.AddUInt64(guid); } else if (_clusterServiceLocator.Functions.GetCharacterSide((byte)client.Character.Race) != friendSide) { response.AddInt8((byte)FriendResult.FRIEND_ENEMY); response.AddUInt64(guid); } else if (_clusterServiceLocator.WorldCluster.CharacteRs.ContainsKey(guid)) { response.AddInt8((byte)FriendResult.FRIEND_ADDED_ONLINE); response.AddUInt64(guid); response.AddString(name); if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].Dnd) { response.AddInt8((byte)FriendStatus.FRIEND_STATUS_DND); } else if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].Afk) { response.AddInt8((byte)FriendStatus.FRIEND_STATUS_AFK); } else { response.AddInt8((byte)FriendStatus.FRIEND_STATUS_ONLINE); } response.AddInt32((int)_clusterServiceLocator.WorldCluster.CharacteRs[guid].Zone); response.AddInt32(_clusterServiceLocator.WorldCluster.CharacteRs[guid].Level); response.AddInt32((int)_clusterServiceLocator.WorldCluster.CharacteRs[guid].Classe); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Update(string.Format("INSERT INTO character_social (guid, friend, flags) VALUES ({0}, {1}, {2});", client.Character.Guid, guid, Conversions.ToByte(SocialFlag.SOCIAL_FLAG_FRIEND))); } else { response.AddInt8((byte)FriendResult.FRIEND_ADDED_OFFLINE); response.AddUInt64(guid); response.AddString(name); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Update(string.Format("INSERT INTO character_social (guid, friend, flags) VALUES ({0}, {1}, {2});", client.Character.Guid, guid, Conversions.ToByte(SocialFlag.SOCIAL_FLAG_FRIEND))); } } else { response.AddInt8((byte)FriendResult.FRIEND_NOT_FOUND); response.AddUInt64(guid); } client.Send(response); response.Dispose(); q.Dispose(); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] SMSG_FRIEND_STATUS", client.IP, client.Port); }
/* TODO ERROR: Skipped EndRegionDirectiveTrivia */ /* TODO ERROR: Skipped RegionDirectiveTrivia */ public void On_CMSG_WHO(PacketClass packet, ClientClass client) { packet.GetInt16(); var levelMinimum = packet.GetUInt32(); // 0 var levelMaximum = packet.GetUInt32(); // 100 var namePlayer = _clusterServiceLocator.Functions.EscapeString(packet.GetString()); var nameGuild = _clusterServiceLocator.Functions.EscapeString(packet.GetString()); var maskRace = packet.GetUInt32(); var maskClass = packet.GetUInt32(); var zonesCount = packet.GetUInt32(); // Limited to 10 if (zonesCount > 10L) { return; } var zones = new List <uint>(); for (int i = 1, loopTo = (int)zonesCount; i <= loopTo; i++) { zones.Add(packet.GetUInt32()); } var stringsCount = packet.GetUInt32(); // Limited to 4 if (stringsCount > 4L) { return; } var strings = new List <string>(); for (int i = 1, loopTo1 = (int)stringsCount; i <= loopTo1; i++) { strings.Add(_clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(_clusterServiceLocator.Functions.EscapeString(packet.GetString()))); } _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_WHO [P:'{2}' G:'{3}' L:{4}-{5} C:{6:X} R:{7:X}]", client.IP, client.Port, namePlayer, nameGuild, levelMinimum, levelMaximum, maskClass, maskRace); // TODO: Don't show GMs? var results = new List <ulong>(); _clusterServiceLocator.WorldCluster.CharacteRsLock.AcquireReaderLock(_clusterServiceLocator.GlobalConstants.DEFAULT_LOCK_TIMEOUT); foreach (var objCharacter in _clusterServiceLocator.WorldCluster.CharacteRs) { if (!objCharacter.Value.IsInWorld) { continue; } if (_clusterServiceLocator.Functions.GetCharacterSide((byte)objCharacter.Value.Race) != _clusterServiceLocator.Functions.GetCharacterSide((byte)client.Character.Race) && client.Character.Access < AccessLevel.GameMaster) { continue; } if (!string.IsNullOrEmpty(namePlayer) && _clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(objCharacter.Value.Name).IndexOf(_clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(namePlayer), StringComparison.Ordinal) == -1) { continue; } if (!string.IsNullOrEmpty(nameGuild) && (objCharacter.Value.Guild is null || _clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(objCharacter.Value.Guild.Name).IndexOf(_clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(nameGuild), StringComparison.Ordinal) == -1)) { continue; } if (objCharacter.Value.Level < levelMinimum) { continue; } if (objCharacter.Value.Level > levelMaximum) { continue; } if (zonesCount > 0L && zones.Contains(objCharacter.Value.Zone) == false) { continue; } if (stringsCount > 0L) { var passedStrings = true; foreach (var stringValue in strings) { if (_clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(objCharacter.Value.Name).IndexOf(stringValue, StringComparison.Ordinal) != -1) { continue; } if (_clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(_clusterServiceLocator.Functions.GetRaceName((int)objCharacter.Value.Race)) == stringValue) { continue; } if (_clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(_clusterServiceLocator.Functions.GetClassName((int)objCharacter.Value.Classe)) == stringValue) { continue; } if (objCharacter.Value.Guild is object && _clusterServiceLocator.CommonFunctions.UppercaseFirstLetter(objCharacter.Value.Guild.Name).IndexOf(stringValue, StringComparison.Ordinal) != -1) { continue; } // TODO: Look for zone name passedStrings = false; break; } if (passedStrings == false) { continue; } } // DONE: List first 49 _WorldCluster.CHARACTERs (like original) if (results.Count > 49) { break; } results.Add(objCharacter.Value.Guid); } var response = new PacketClass(Opcodes.SMSG_WHO); response.AddInt32(results.Count); response.AddInt32(results.Count); foreach (var guid in results) { response.AddString(_clusterServiceLocator.WorldCluster.CharacteRs[guid].Name); // Name if (_clusterServiceLocator.WorldCluster.CharacteRs[guid].Guild is object) { response.AddString(_clusterServiceLocator.WorldCluster.CharacteRs[guid].Guild.Name); // Guild Name } else { response.AddString(""); } // Guild Name response.AddInt32(_clusterServiceLocator.WorldCluster.CharacteRs[guid].Level); // Level response.AddInt32((int)_clusterServiceLocator.WorldCluster.CharacteRs[guid].Classe); // Class response.AddInt32((int)_clusterServiceLocator.WorldCluster.CharacteRs[guid].Race); // Race response.AddInt32((int)_clusterServiceLocator.WorldCluster.CharacteRs[guid].Zone); // Zone ID } _clusterServiceLocator.WorldCluster.CharacteRsLock.ReleaseReaderLock(); client.Send(response); response.Dispose(); }
public void On_CMSG_GUILD_REMOVE(PacketClass packet, ClientClass client) { if (packet.Data.Length - 1 < 6) { return; } packet.GetInt16(); var playerName = packet.GetString().Replace("'", "_").Replace("\"", "_"); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GUILD_REMOVE [{2}]", client.IP, client.Port, playerName); if (playerName.Length < 2) { return; } playerName = _clusterServiceLocator.Functions.CapitalizeName(playerName); // DONE: Player1 checks if (!client.Character.IsInGuild) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD); return; } if (!client.Character.IsGuildRightSet(GuildRankRights.GR_RIGHT_REMOVE)) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PERMISSIONS); return; } // DONE: Find player2's guid var q = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query("SELECT char_guid FROM characters WHERE char_name = '" + playerName + "';", ref q); // DONE: Removed checks if (q.Rows.Count == 0) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_PLAYER_NOT_FOUND, playerName); return; } if (!_clusterServiceLocator.WorldCluster.CharacteRs.ContainsKey(q.Rows[0].As <ulong>("char_guid"))) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_PLAYER_NOT_FOUND, playerName); return; } var objCharacter = _clusterServiceLocator.WorldCluster.CharacteRs[q.Rows[0].As <ulong>("char_guid")]; if (objCharacter.IsGuildLeader) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_QUIT_S, GuildError.GUILD_LEADER_LEAVE); return; } // DONE: Send guild event var response = new PacketClass(Opcodes.SMSG_GUILD_EVENT); response.AddInt8((byte)GuildEvent.REMOVED); response.AddInt8(2); response.AddString(playerName); response.AddString(objCharacter.Name); var argnotTo = 0UL; _clusterServiceLocator.WcGuild.BroadcastToGuild(response, client.Character.Guild, notTo: argnotTo); response.Dispose(); _clusterServiceLocator.WcGuild.RemoveCharacterFromGuild(objCharacter); }
public void On_CMSG_CHAR_ENUM(PacketClass packet, ClientClass client) { _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_CHAR_ENUM", client.IP, client.Port); // DONE: Query _WorldCluster.CHARACTERs DB var response = new PacketClass(Opcodes.SMSG_CHAR_ENUM); var mySqlQuery = new DataTable(); int accountId; try { _clusterServiceLocator.WorldCluster.GetAccountDatabase().Query(string.Format("SELECT id FROM account WHERE username = '******';", client.Account), ref mySqlQuery); accountId = mySqlQuery.Rows[0].As <int>("id"); mySqlQuery.Clear(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query(string.Format("SELECT * FROM characters WHERE account_id = '{0}' ORDER BY char_guid;", accountId), ref mySqlQuery); // DONE: Make The Packet response.AddInt8((byte)mySqlQuery.Rows.Count); for (int i = 0, loopTo = mySqlQuery.Rows.Count - 1; i <= loopTo; i++) { var dead = false; var deadMySqlQuery = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query(string.Format("SELECT COUNT(*) FROM corpse WHERE player = {0};", mySqlQuery.Rows[i]["char_guid"]), ref deadMySqlQuery); if (deadMySqlQuery.Rows[0].As <int>(0) > 0) { dead = true; } var petQuery = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query(string.Format("SELECT modelid, level, entry FROM character_pet WHERE owner = '{0}';", mySqlQuery.Rows[i]["char_guid"]), ref petQuery); response.AddInt64(mySqlQuery.Rows[i].As <long>("char_guid")); response.AddString(mySqlQuery.Rows[i].As <string>("char_name")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_race")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_class")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_gender")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_skin")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_face")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_hairStyle")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_hairColor")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_facialHair")); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_level")); response.AddInt32(mySqlQuery.Rows[i].As <int>("char_zone_id")); response.AddInt32(mySqlQuery.Rows[i].As <int>("char_map_id")); response.AddSingle(mySqlQuery.Rows[i].As <float>("char_positionX")); response.AddSingle(mySqlQuery.Rows[i].As <float>("char_positionY")); response.AddSingle(mySqlQuery.Rows[i].As <float>("char_positionZ")); response.AddInt32(mySqlQuery.Rows[i].As <int>("char_guildId")); var playerState = (uint)CharacterFlagState.CHARACTER_FLAG_NONE; var forceRestrictions = mySqlQuery.Rows[i].As <uint>("force_restrictions"); if ((forceRestrictions & (uint)ForceRestrictionFlags.RESTRICT_TRANSFER) != 0) { playerState += (uint)CharacterFlagState.CHARACTER_FLAG_LOCKED_FOR_TRANSFER; } if ((forceRestrictions & (uint)ForceRestrictionFlags.RESTRICT_BILLING) != 0) { playerState += (uint)CharacterFlagState.CHARACTER_FLAG_LOCKED_BY_BILLING; } if ((forceRestrictions & (uint)ForceRestrictionFlags.RESTRICT_RENAME) != 0) { playerState += (uint)CharacterFlagState.CHARACTER_FLAG_RENAME; } if (dead) { playerState += (uint)CharacterFlagState.CHARACTER_FLAG_GHOST; } response.AddUInt32(playerState); response.AddInt8(mySqlQuery.Rows[i].As <byte>("char_restState")); var petModel = 0; var petLevel = 0; var petFamily = 0; if (petQuery.Rows.Count > 0) { petModel = petQuery.Rows[0].As <int>("modelid"); petLevel = petQuery.Rows[0].As <int>("level"); var petFamilyQuery = new DataTable(); _clusterServiceLocator.WorldCluster.GetWorldDatabase().Query(string.Format("SELECT family FROM creature_template WHERE entry = '{0}'", petQuery.Rows[0]["entry"]), ref petFamilyQuery); petFamily = petFamilyQuery.Rows[0].As <int>("family"); } response.AddInt32(petModel); response.AddInt32(petLevel); response.AddInt32(petFamily); // DONE: Get items var guid = mySqlQuery.Rows[i].As <long>("char_guid"); var itemsMySqlQuery = new DataTable(); var characterDb = _clusterServiceLocator.WorldCluster.GetCharacterDatabase().SQLDBName; var worldDb = _clusterServiceLocator.WorldCluster.GetWorldDatabase().SQLDBName; _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query(string.Format("SELECT item_slot, displayid, inventorytype FROM " + characterDb + ".characters_inventory, " + worldDb + ".item_template WHERE item_bag = {0} AND item_slot <> 255 AND entry = item_id ORDER BY item_slot;", guid), ref itemsMySqlQuery); var e = itemsMySqlQuery.Rows.GetEnumerator(); e.Reset(); e.MoveNext(); var row = (DataRow)e.Current; // DONE: Add model info for (byte slot = 0, loopTo1 = (byte)EquipmentSlots.EQUIPMENT_SLOT_END; slot <= loopTo1; slot++) // - 1 { if (row is null || row.As <int>("item_slot") != slot) { // No equiped item in this slot response.AddInt32(0); // Item Model response.AddInt8(0); // Item Slot } else { // DONE: Do not show helmet or cloak if (((forceRestrictions & (uint)ForceRestrictionFlags.RESTRICT_HIDECLOAK) != 0) && (EquipmentSlots)row.As <byte>("item_slot") == EquipmentSlots.EQUIPMENT_SLOT_BACK || ((forceRestrictions & (uint)ForceRestrictionFlags.RESTRICT_HIDEHELM) != 0) && (EquipmentSlots)row.As <byte>("item_slot") == EquipmentSlots.EQUIPMENT_SLOT_HEAD) { response.AddInt32(0); // Item Model response.AddInt8(0); // Item Slot } else { response.AddInt32(row.As <int>("displayid")); // Item Model response.AddInt8(row.As <byte>("inventorytype")); } // Item Slot e.MoveNext(); row = (DataRow)e.Current; } }
public void On_CMSG_GUILD_DEMOTE(PacketClass packet, ClientClass client) { if (packet.Data.Length - 1 < 6) { return; } packet.GetInt16(); var playerName = _clusterServiceLocator.Functions.CapitalizeName(packet.GetString()); _clusterServiceLocator.WorldCluster.Log.WriteLine(LogType.DEBUG, "[{0}:{1}] CMSG_GUILD_DEMOTE [{2}]", client.IP, client.Port, playerName); if (!client.Character.IsInGuild) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD); return; } if (!client.Character.IsGuildRightSet(GuildRankRights.GR_RIGHT_PROMOTE)) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_CREATE_S, GuildError.GUILD_PERMISSIONS); return; } // DONE: Find demoted player's guid var q = new DataTable(); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Query("SELECT char_guid FROM characters WHERE char_name = '" + playerName.Replace("'", "_") + "';", ref q); // DONE: Demoted checks if (q.Rows.Count == 0) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_NAME_INVALID); return; } if (!_clusterServiceLocator.WorldCluster.CharacteRs.ContainsKey(q.Rows[0].As <ulong>("char_guid"))) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_PLAYER_NOT_FOUND, playerName); return; } var objCharacter = _clusterServiceLocator.WorldCluster.CharacteRs[q.Rows[0].As <ulong>("char_guid")]; if (objCharacter.Guild.Id != client.Character.Guild.Id) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_PLAYER_NOT_IN_GUILD_S, playerName); return; } if (objCharacter.GuildRank <= client.Character.GuildRank) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_PERMISSIONS); return; } if (objCharacter.GuildRank == _clusterServiceLocator.GlobalConstants.GUILD_RANK_MAX) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_INTERNAL); return; } // DONE: Max defined rank check if (string.IsNullOrEmpty(Strings.Trim(client.Character.Guild.Ranks[objCharacter.GuildRank + 1]))) { _clusterServiceLocator.WcGuild.SendGuildResult(client, GuildCommand.GUILD_INVITE_S, GuildError.GUILD_INTERNAL); return; } // DONE: Do the real update objCharacter.GuildRank = (byte)(objCharacter.GuildRank + 1); _clusterServiceLocator.WorldCluster.GetCharacterDatabase().Update(string.Format("UPDATE characters SET char_guildRank = {0} WHERE char_guid = {1};", objCharacter.GuildRank, objCharacter.Guid)); objCharacter.SendGuildUpdate(); // DONE: Send event to guild var response = new PacketClass(Opcodes.SMSG_GUILD_EVENT); response.AddInt8((byte)GuildEvent.DEMOTION); response.AddInt8(3); response.AddString(objCharacter.Name); response.AddString(playerName); response.AddString(client.Character.Guild.Ranks[objCharacter.GuildRank]); var argnotTo = 0UL; _clusterServiceLocator.WcGuild.BroadcastToGuild(response, client.Character.Guild, notTo: argnotTo); response.Dispose(); }