public void Request(Session session, Packet packet) { string playerName; try { playerName = packet.GetString(); } catch (Exception) { ReplyError(session, packet, Error.Unexpected); return; } if (session.Player.Tribesman == null) { ReplyError(session, packet, Error.TribeIsNull); return; } uint playerId; if (!world.FindPlayerId(playerName, out playerId)) { ReplyError(session, packet, Error.PlayerNotFound); return; } Dictionary <uint, IPlayer> players; ITribe tribe = session.Player.Tribesman.Tribe; locker.Lock(out players, playerId, tribe.Owner.PlayerId).Do(() => { if (!tribe.HasRight(session.Player.PlayerId, TribePermission.Invite)) { ReplyError(session, packet, Error.TribesmanNotAuthorized); return; } if (players[playerId].Tribesman != null) { ReplyError(session, packet, Error.TribesmanAlreadyInTribe); return; } if (players[playerId].TribeRequest != 0) { ReplyError(session, packet, Error.TribesmanPendingRequest); return; } players[playerId].TribeRequest = tribe.Id; dbManager.Save(players[playerId]); ReplySuccess(session, packet); }); }
public void SetRank(Session session, Packet packet) { uint playerId; byte rank; try { playerId = packet.GetUInt32(); rank = packet.GetByte(); } catch (Exception) { ReplyError(session, packet, Error.Unexpected); return; } if (session.Player.Tribesman == null) { ReplyError(session, packet, Error.TribeIsNull); return; } Dictionary <uint, IPlayer> players; locker.Lock(out players, playerId, session.Player.Tribesman.Tribe.Owner.PlayerId).Do(() => { ITribe tribe = session.Player.Tribesman.Tribe; if (!tribe.HasRight(session.Player.PlayerId, TribePermission.SetRank)) { ReplyError(session, packet, Error.TribesmanNotAuthorized); return; } var error = tribe.SetRank(playerId, rank); if (error == Error.Ok) { ReplySuccess(session, packet); } else { ReplyError(session, packet, error); } }); }
public void Remove(Session session, Packet packet) { uint playerId; try { playerId = packet.GetUInt32(); } catch (Exception) { ReplyError(session, packet, Error.Unexpected); return; } IPlayer playerToBeRemoved; if (!world.TryGetObjects(playerId, out playerToBeRemoved)) { ReplyError(session, packet, Error.PlayerNotFound); return; } CallbackLock.CallbackLockHandler lockHandler = delegate { var tribe = session.Player.IsInTribe ? session.Player.Tribesman.Tribe : null; if (tribe == null) { return(new ILockable[] {}); } var locks = strongholdManager.StrongholdsForTribe(tribe) .SelectMany(stronghold => stronghold.LockList()) .ToList(); locks.Add(tribe); return(locks.ToArray()); }; locker.Lock(lockHandler, new object[] {}, session.Player, playerToBeRemoved).Do(() => { if (!session.Player.IsInTribe || !playerToBeRemoved.IsInTribe || playerToBeRemoved.Tribesman.Tribe != session.Player.Tribesman.Tribe) { ReplyError(session, packet, Error.TribeIsNull); return; } ITribe tribe = session.Player.Tribesman.Tribe; if (!tribe.HasRight(session.Player.PlayerId, TribePermission.Kick)) { ReplyError(session, packet, Error.TribesmanNotAuthorized); return; } if (tribe.IsOwner(playerToBeRemoved)) { ReplyError(session, packet, Error.TribesmanIsOwner); return; } var result = session.Player.Tribesman.Tribe.KickTribesman(playerToBeRemoved, session.Player); ReplyWithResult(session, packet, result); }); }