public static void removeInvitation(User sender, User receiver) { Core core = Core.Instance; //sender removes the invitation invites the receiver to his alliance: if (!(sender.allianceId != 0 && Core.Instance.alliances.ContainsKey(sender.allianceId))) { return; } Alliance alliance = Core.Instance.alliances[sender.allianceId]; //teste ob user erlaubt ist invites zu geben if (!alliance.getMemberRight(sender).mayInvite) { return; } //teste das kein invite vorhanden ist if (!(Core.Instance.invitesPerAlliance.ContainsKey(alliance.id) && Core.Instance.invitesPerAlliance[alliance.id].Any(user => user == receiver.id))) { return; } List <Lockable> elementsToLock = new List <Lockable>(2); elementsToLock.Add(alliance); elementsToLock.Add(receiver); if (!LockingManager.lockAllOrSleep(elementsToLock)) { return; } try { //teste das kein invite vorhanden ist if (!(Core.Instance.invitesPerAlliance.ContainsKey(alliance.id) && Core.Instance.invitesPerAlliance[alliance.id].Any(userId => userId == receiver.id))) { LockingManager.unlockAll(elementsToLock); return; } Core.Instance.invitesPerAlliance[alliance.id].RemoveAll(userId => userId == receiver.id); if (Core.Instance.invitesPerUser.ContainsKey(receiver.id)) { Core.Instance.invitesPerUser[receiver.id].RemoveAll(allianceId => allianceId == alliance.id); } Core.Instance.dataConnection.removeInvite(alliance.id, receiver.id); } catch (Exception ex) { core.writeExceptionToLog(ex); } finally { LockingManager.unlockAll(elementsToLock); } }
public static void inviteTo(User sender, User receiver) { Core core = Core.Instance; //sender invites the receiver to his alliance: if (!(sender.allianceId != 0 && Core.Instance.alliances.ContainsKey(sender.allianceId))) { return; } Alliance alliance = Core.Instance.alliances[sender.allianceId]; //teste ob sich beide user kennen: //if (!core.userRelations.hasContact(sender, receiver)) return; //teste ob user erlaubt ist invites zu geben if (!alliance.getMemberRight(sender).mayInvite) { return; } //teste ob schon ein invite vorhanden ist if (core.invitesPerAlliance.ContainsKey(alliance.id) && core.invitesPerAlliance[alliance.id].Any(userId => userId == receiver.id)) { return; } List <Lockable> elementsToLock = new List <Lockable>(2); elementsToLock.Add(alliance); elementsToLock.Add(receiver); if (!LockingManager.lockAllOrSleep(elementsToLock)) { return; } try { //teste ob schon ein invite vorhanden ist if (core.invitesPerAlliance.ContainsKey(alliance.id) && core.invitesPerAlliance[alliance.id].Any(userId => userId == receiver.id)) { LockingManager.unlockAll(elementsToLock); return; } //add into both dicts if (core.invitesPerAlliance.ContainsKey(alliance.id)) { core.invitesPerAlliance[alliance.id].Add(receiver.id); } else { core.invitesPerAlliance.TryAdd(alliance.id, new List <int>()); core.invitesPerAlliance[alliance.id].Add(receiver.id); } if (core.invitesPerUser.ContainsKey(receiver.id)) { core.invitesPerUser[receiver.id].Add(alliance.id); } else { core.invitesPerUser.TryAdd(receiver.id, new List <int>()); core.invitesPerUser[receiver.id].Add(alliance.id); } core.dataConnection.insertInvite(alliance.id, receiver.id); } catch (Exception ex) { core.writeExceptionToLog(ex); } finally { LockingManager.unlockAll(elementsToLock); } }