public bool KickMember(string moderCharacterID, string login, string characterID, string guildID) { var guild = GetGuild(guildID); if (guild == null) { return(false); } GuildMember moderMember = null; if (!guild.TryGetMember(moderCharacterID, out moderMember)) { return(false); } if (!moderMember.IsAddMemberGranted()) { return(false); } return(RemoveMember(login, characterID, guildID)); }
/// <summary> /// Create guild for character, if guild already exists return false and link to existing guild. If guild don't exists, /// create new guild, initialize it and return reference to newly created guild /// </summary> public bool CreateGuild(GuildMember owner, string name, string description, out Guild newGuild) { newGuild = GetGuild(owner.characterId); if (newGuild != null) { log.Info("Such guild already exists"); return(false); } var player = mApplication.Players.GetExistingPlayer(owner.gameRefId); if (player == null) { log.Info("error creating guild, player don't exists"); return(false); } var playerCharacter = player.Data.GetCharacter(owner.characterId); if (playerCharacter == null) { log.Info("error creating guild, player character don't exists "); return(false); } //if character guild setted and exist such guild than return error //else this is some error and reset character guild to empty if (!string.IsNullOrEmpty(playerCharacter.guildID)) { if (HasGuild(playerCharacter.guildID)) { log.Info("player character already in guild"); return(false); } else { log.InfoFormat("reset character guild to (empty), reason: guild from character don't exists"); playerCharacter.SetGuild(string.Empty); } } int playerLevel = mApplication.leveling.LevelForExp(playerCharacter.Exp); if (playerLevel < 5) { log.Info("player level less than 5"); return(false); } newGuild = new Guild { ownerCharacterId = owner.characterId, rating = 0, members = new Dictionary <string, GuildMember> { { owner.characterId, owner } }, description = description, guildRace = playerCharacter.Race, name = name, depositedPvpPoints = 0, depositedCredits = 0 }; mCache.SetGuild(newGuild); mApplication.Players.SetGuild(owner.gameRefId, owner.characterId, newGuild.ownerCharacterId); mApplication.DB.Guilds.Save(newGuild); mApplication.AddAchievmentVariable(owner.gameRefId, "coalition_member", 1); //send guild update SendGuildUpdateEvent(owner.characterId, newGuild.GetInfo(mApplication)); return(true); }
/// <summary> /// Changing status of member by other member /// </summary> /// <param name="sourceCharacterID">Character ID of member who make changes</param> /// <param name="targetCharacterID">Character ID of membe who will be changed</param> /// <param name="guildID">Target guild id</param> /// <param name="status">New status of member</param> /// <returns></returns> public bool ChangeGuildMemberStatus(string sourceCharacterID, string targetCharacterID, string guildID, int status) { if (sourceCharacterID == targetCharacterID) { log.Info("ChangeGuildMemberStatus - don't allow change self status"); return(false); } DbObjectWrapper <Guild> guild = null; if (!mCache.TryGetGuild(guildID, out guild)) { log.Info("ChangeGuildMemberStatus - guild not found"); return(false); } GuildMember sourceMember = null; if (!guild.Data.TryGetMember(sourceCharacterID, out sourceMember)) { log.Info("ChangeGuildMemberStatus - source member not found"); return(false); } GuildMember targetMember = null; if (!guild.Data.TryGetMember(targetCharacterID, out targetMember)) { log.Info("ChangeGuildMemberStatus - target member not found"); return(false); } GuildMemberStatus newStatus = (GuildMemberStatus)status; if (newStatus == GuildMemberStatus.Moderator) { if (!guild.Data.addingModersAllowed) { log.InfoFormat("ChangeGuildMemberStatus: guild already has maximum count of moderators [green]"); return(false); } } GuildMemberStatus sourceStatus = (GuildMemberStatus)sourceMember.guildStatus; GuildMemberStatus targetStatus = (GuildMemberStatus)targetMember.guildStatus; if (sourceStatus == GuildMemberStatus.Moderator) { if (targetStatus != GuildMemberStatus.Member) { log.Info("ChangeGuildMemberStatus - moderator allow change only members status"); return(false); } if (newStatus != GuildMemberStatus.Moderator) { log.Info("ChangeGuildMemberStatus - moderator allow raise status of member to moderator only"); return(false); } } else if (sourceStatus == GuildMemberStatus.Owner) { if (targetStatus == GuildMemberStatus.Owner) { log.Info("ChangeGuildMemberStatus - Don't allow two owners of guild"); return(false); } if (newStatus == targetStatus) { log.Info("ChangeGuildMemberStatus - New status same as before status"); return(false); } } targetMember.guildStatus = status; guild.Changed = true; if (status == (int)GuildMemberStatus.Moderator) { guild.Data.AddTransaction(CoalitionTransaction.MakeTransaction(CoalitionTransactionType.make_officier, string.Empty, string.Empty, targetMember.characterName, targetMember.characterId)); } SendGuildUpdateEvent(sourceMember.characterId, guild.Data.GetInfo(mApplication)); SendGuildUpdateEvent(targetMember.characterId, guild.Data.GetInfo(mApplication)); if (newStatus == GuildMemberStatus.Moderator) { mApplication.AddAchievmentVariable(targetMember.gameRefId, "coalition_officier", 1); } return(true); }
public bool SendInviteToGuildNotification(string sourceLogin, string sourceCharacterID, string targetLogin, string targetCharacterID, string guildID) { var sourcePlayer = mApplication.Players.GetExistingPlayerByLogin(sourceLogin); var targetPlayer = mApplication.Players.GetExistingPlayerByLogin(targetLogin); if (sourcePlayer == null) { log.Info("don't exists source player"); return(false); } if (targetPlayer == null) { log.Info("don't exists target player"); return(false); } var sourceCharacter = sourcePlayer.Data.GetCharacter(sourceCharacterID); var targetCharacter = targetPlayer.Data.GetCharacter(targetCharacterID); if (sourceCharacter == null) { log.Info("source character not found"); return(false); } if (targetCharacter == null) { log.Info("target character not found"); return(false); } if (targetCharacter.HasGuild()) { log.Info("target character already in some guild"); return(false); } Guild targetGuild = GetGuild(guildID); if (targetGuild == null) { log.Info("guild not found"); return(false); } GuildMember sourceMember = null; if (!targetGuild.TryGetMember(sourceCharacterID, out sourceMember)) { log.Info("source member not found"); return(false); } if (!sourceMember.IsAddMemberGranted()) { log.Info("not granted add members"); return(false); } //string text = string.Format("{0} invited you to group {1}. Do you want accept to group?", sourceLogin, targetGuild.name); Hashtable notificationData = new Hashtable { { (int)SPC.Action, (int)GuildAction.AddMember }, { (int)SPC.Guild, guildID }, { (int)SPC.SourceLogin, sourceLogin }, { (int)SPC.Name, targetGuild.name } }; string uniqueID = sourceCharacterID + sourceLogin + targetCharacterID + targetLogin + guildID + NotificationSourceServiceType.Guild.ToString() + NotificationSubType.InviteToGuild.ToString(); var notification = mApplication.Notifications.Create(uniqueID, "s_note_invite_guild", notificationData, NotficationRespondAction.YesDelete, NotificationSourceServiceType.Guild, NotificationSubType.InviteToGuild); mApplication.Notifications.SetNotificationToCharacter(targetCharacterID, notification); return(true); }
private bool HandleRequestToGuildNotification(string handlerCharacterID, Hashtable notificationData) { string requestedGuildID = notificationData.GetValue <string>((int)SPC.Guild, string.Empty); string targetCharacterID = notificationData.GetValue <string>((int)SPC.CharacterId, string.Empty); string targetLogin = notificationData.GetValue <string>((int)SPC.Login, string.Empty); if (string.IsNullOrEmpty(requestedGuildID) || string.IsNullOrEmpty(targetCharacterID) || string.IsNullOrEmpty(targetLogin)) { log.InfoFormat("HandleRequestToGuildNotification: notfication data invalid [green]"); return(false); } var targetGuild = GetGuild(requestedGuildID); if (targetGuild == null) { log.InfoFormat("HandleRequestToGuildNotification: requested guild is null [green]"); return(false); } if (targetGuild.closed) { log.InfoFormat("HandleRequestToGuildNotification: guild closed [green]"); return(false); } GuildMember handlerMember; if (!targetGuild.TryGetMember(handlerCharacterID, out handlerMember)) { log.InfoFormat("HandleRequestToGuildNotification: privileged user with character id = {0} not founded at guild [green]", handlerCharacterID); return(false); } if (!handlerMember.IsAddMemberGranted()) { log.InfoFormat("HandleRequestToGuildNotification: adding users not granted [green]"); return(false); } var player = mApplication.Players.GetExistingPlayerByLogin(targetLogin); if (player == null) { log.InfoFormat("HandleRequestToGuildNotification: player not founded [green]"); return(false); } var playerCharacter = player.Data.GetCharacter(targetCharacterID); if (playerCharacter == null) { log.InfoFormat("HandleRequestToGuildNotification: target player character not founded [green]"); return(false); } if (playerCharacter.HasGuild()) { log.InfoFormat("HandleRequestToGuildNotification: target player character already at another guild [green]"); return(false); } GuildMember member = new GuildMember { characterId = targetCharacterID, gameRefId = player.Data.GameRefId, guildStatus = (int)GuildMemberStatus.Member, exp = playerCharacter.Exp, login = targetLogin, characterName = playerCharacter.Name, characterIcon = playerCharacter.characterIcon }; if (!AddMember(requestedGuildID, member)) { log.Info("HandleRequestToGuildNotification: some error adding member to guild [green]"); return(false); } mApplication.Players.SetGuild(player.Data.GameRefId, targetCharacterID, requestedGuildID); SendGuildUpdateEvent(handlerCharacterID, targetGuild.GetInfo(mApplication)); SendGuildUpdateEvent(targetCharacterID, targetGuild.GetInfo(mApplication)); mApplication.AddAchievmentVariable(member.gameRefId, "coalition_member", 1); mApplication.AddAchievmentVariable(handlerMember.gameRefId, "coalition_member_accepted", 1); return(true); }
/* * Notification data must be { {SPC.Action, (GuildAction)(int) }, {SPC.Guild, (string)guildID } } */ private bool HandleAddMemberNotification(string memberCharacterID, Hashtable notificationData) { string guildID = (string)notificationData[(int)SPC.Guild]; SelectCharacterClientPeer peer; if (!mApplication.Clients.TryGetPeerForCharacterId(memberCharacterID, out peer)) { log.InfoFormat("character peer not found"); return(false); } var player = mApplication.Players.GetExistingPlayer(peer.id); if (player == null) { log.Info("existing player not founded"); return(false); } var character = player.Data.GetCharacter(peer.characterId); if (character == null) { log.Info("character not founded"); return(false); } if (!string.IsNullOrEmpty(character.guildID)) { log.Info("character already in guild"); return(false); } GuildMember member = new GuildMember { characterId = character.CharacterId, gameRefId = player.Data.GameRefId, guildStatus = (int)GuildMemberStatus.Member, exp = character.Exp, login = player.Data.Login.ToLower(), characterName = character.Name, characterIcon = character.characterIcon }; if (!AddMember(guildID, member)) { log.Info("some error adding member to guild"); return(false); } mApplication.Players.SetGuild(player.Data.GameRefId, memberCharacterID, guildID); var guild = GetGuild(guildID); if (guild != null) { guild.AddTransaction(CoalitionTransaction.MakeTransaction(CoalitionTransactionType.member_added, string.Empty, string.Empty, member.characterName, member.characterId)); SendGuildUpdateEvent(memberCharacterID, guild.GetInfo(mApplication)); } mApplication.AddAchievmentVariable(member.gameRefId, "coalition_member", 1); return(true); }
public bool TryGetMember(string characterId, out GuildMember member) { lock (syncRoot) { return(members.TryGetValue(characterId, out member)); } }