public bool InsertPlayerData(TPPlayer player) { PlayerData playerData = player.PlayerData; if (!player.IsLoggedIn) return false; if (!GetPlayerData(player, player.UserID).exists) { try { database.Query("INSERT INTO Inventory (Account, MaxHealth, Inventory) VALUES (@0, @1, @2);", player.UserID, playerData.maxHealth, NetItem.ToString(playerData.inventory)); return true; } catch (Exception ex) { Log.Error(ex.ToString()); } } else { try { database.Query("UPDATE Inventory SET MaxHealth = @0, Inventory = @1 WHERE Account = @2;", playerData.maxHealth, NetItem.ToString(playerData.inventory), player.UserID); return true; } catch (Exception ex) { Log.Error(ex.ToString()); } } return false; }
/// <summary> /// Kicks a player from the server.. /// </summary> /// <param name="ply">int player</param> /// <param name="reason">string reason</param> /// <param name="force">bool force (default: false)</param> /// <param name="silent">bool silent (default: false)</param> /// <param name="adminUserName">string adminUserName (default: null)</param> /// <param name="saveSSI">bool saveSSI (default: false)</param> public bool Kick(TPPlayer player, string reason, bool force = false, bool silent = false, string adminUserName = null, bool saveSSI = false) { if (!player.ConnectionAlive) { return(true); } if (force || !player.Group.HasPermission(Permissions.immunetokick)) { string playerName = player.Name; player.SilentKickInProgress = silent; if (player.IsLoggedIn && saveSSI) { player.SaveServerInventory(); } player.Disconnect(string.Format("Kicked: {0}", reason)); Log.ConsoleInfo(string.Format("Kicked {0} for : {1}", playerName, reason)); string verb = force ? "force " : ""; if (!silent) { if (string.IsNullOrWhiteSpace(adminUserName)) { Utils.Broadcast(string.Format("{0} was {1}kicked for {2}", playerName, verb, reason.ToLower()), Color.Green); } else { Utils.Broadcast(string.Format("{0} {1}kicked {2} for {3}", adminUserName, verb, playerName, reason.ToLower()), Color.Green); } } return(true); } return(false); }
public bool CanBuild(int x, int y, TPPlayer ply) { if (!ply.Group.HasPermission(Permissions.canbuild)) { return(false); } Region top = null; for (int i = 0; i < Regions.Count; i++) { if (Regions[i].InArea(x, y)) { if (top == null) { top = Regions[i]; } else { if (Regions[i].Z > top.Z) { top = Regions[i]; } } } } return(top == null || top.HasPermissionToBuildInRegion(ply)); }
private void MessageAllCommand(CommandArgs args) { TPPlayer player = args.Player; if (player.IsLoggedIn) { FriendList fl = FriendsList.GetListByUserID(player.UserID); if (fl != null) { string message = ""; for (int i = 0; i < args.Parameters.Count; i++) { message += args.Parameters[i] + " "; } foreach (FUser fu in fl.Friends) { TPPlayer pdest = GetOnlinePlayerById(fu.ID); if (pdest != null) { pdest.SendMessage(String.Format("{0}: {1}", player.UserAccountName, message), TextColor); } } player.SendMessage(String.Format("{0}: {1}", "To All", message), TextColor); } } else { player.SendErrorMessage("Friends: You're not logged in!"); } }
protected void ChannelMessage(CommandArgs args) { TPPlayer player = args.Player; Channel pChannel = null; foreach (Channel c in Channels) { if (c.ContainsPlayer(player)) { pChannel = c; break; } } if (pChannel == null) { player.SendErrorMessage("Channels: You're not in a channel!"); } else { string message = ""; for (int i = 0; i < args.Parameters.Count; i++) { message += args.Parameters[i] + " "; } pChannel.Send(player, message); } }
public void Join(TPPlayer player) { if (!Players.Contains(player)) { BroadcastMessage(String.Format("{0} has join", player.Name)); Players.Add(player); } }
public void Leave(TPPlayer player) { if (Players.Contains(player)) { Players.Remove(player); BroadcastMessage(String.Format("{0} has left", player.Name)); } }
public bool ItemIsBanned(string name, TPPlayer ply) { if (ItemBans.Contains(new ItemBan(name))) { ItemBan b = GetItemBanByName(name); return(!b.HasPermissionToUseItem(ply)); } return(false); }
public bool HasPermissionToUseItem(TPPlayer ply) { if (ply == null) { return(false); } return(AllowedGroups.Contains(ply.Group.Name)); // could add in the other permissions in this class instead of a giant if switch. }
protected void AssignPlayerTeam(CommandArgs args) { if (args.Player.Group.ContainsGroup("superadmin")) { if (args.Parameters.Count != 2) { args.Player.SendInfoMessage("Arena: you must specify a player name and a team id"); args.Player.SendInfoMessage("Arena: /aassign [player] [1|2] "); } else { string pname = args.Parameters[0]; int teamid = int.MinValue; int.TryParse(args.Parameters[1], out teamid); TPPlayer tp = tPulse.GetPlayerByName(pname); if (tp == null) { args.Player.SendErrorMessage(String.Format("Arena: {0} not found!", pname)); } else { if (IsInTeam(tp)) { args.Player.SendErrorMessage(String.Format("Arena: {0} is already assigned to a team!", pname)); return; } if (teamid == 1) { Team1.Add(tp); args.Player.SendInfoMessage(String.Format("Arena: {0} added to the team 1", pname)); } else if (teamid == 2) { Team2.Add(tp); args.Player.SendInfoMessage(String.Format("Arena: {0} added to the team 2", pname)); } else { args.Player.SendErrorMessage("Arena: invalid team id!"); } } } } else { args.Player.SendErrorMessage("Only superadmin can use this command!"); } }
public void Send(TPPlayer from, string message) { if (Players.Contains(from)) { String fmessage = String.Format("{0}: {1}", from.Name, message); foreach (TPPlayer player in Players) { player.SendMessage(fmessage, TextColor); } ChannelLog.Write(fmessage); } }
protected void LeaveCommand(CommandArgs args) { TPPlayer player = args.Player; foreach (Channel c in Channels) { if (c.ContainsPlayer(player)) { c.Leave(player); player.SendInfoMessage("Channels: Channel left"); return; } } player.SendErrorMessage("Channels: You're not in any channel!"); }
public List <TPPlayer> FindPlayer(string plr) { var found = new List <TPPlayer>(); // Avoid errors caused by null search if (plr == null) { return(found); } byte plrID; if (byte.TryParse(plr, out plrID)) { TPPlayer player = tPulse.Players[plrID]; if (player != null && player.Active) { return(new List <TPPlayer> { player }); } } string plrLower = plr.ToLower(); foreach (TPPlayer player in tPulse.Players) { if (player != null) { // Must be an EXACT match if (player.Name == plr) { return new List <TPPlayer> { player } } ; if (player.Name.ToLower().StartsWith(plrLower)) { found.Add(player); } } } return(found); } }
public bool HasPermissionToBuildInRegion(TPPlayer ply) { if (!ply.IsLoggedIn) { if (!ply.HasBeenNaggedAboutLoggingIn) { ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red); ply.HasBeenNaggedAboutLoggingIn = true; } return(false); } if (!DisableBuild) { return(true); } return(AllowedIDs.Contains(ply.UserID) || AllowedGroups.Contains(ply.Group.Name) || Owner == ply.UserAccountName || ply.Group.HasPermission("manageregion")); }
private void PlayerLogin(PlayerLoginEventArgs args) { FriendList fl = FriendsList.GetListByUserID(args.Player.UserID); if (fl == null) { return; } foreach (FUser fu in fl.Friends) { if (IsUserOnline(fu.ID)) { TPPlayer dplayer = GetOnlinePlayerById(fu.ID); if (dplayer != null) { dplayer.SendMessage(String.Format("{0} just logged in!", args.Player.UserAccountName), TextColor); } } } }
protected void JoinCommand(CommandArgs args) { TPPlayer player = args.Player; if (args.Parameters.Count == 1) { string cname = args.Parameters[0]; if (Manager.Contains(cname)) { foreach (Channel c in Channels) { if (c.ContainsPlayer(player)) { c.Leave(player); } } foreach (Channel c in Channels) { if (c.Name == cname) { c.Join(player); player.SendInfoMessage(String.Format("Channels: You've entered {0} channel", cname)); break; } } } else { player.SendErrorMessage(String.Format("Channels: {0} doesn't exists!", cname)); } } else { player.SendErrorMessage("Channels: Missing or too much arguments!"); } }
public bool InsertPlayerData(TPPlayer player) { PlayerData playerData = player.PlayerData; if (!player.IsLoggedIn) { return(false); } if (!GetPlayerData(player, player.UserID).exists) { try { database.Query("INSERT INTO Inventory (Account, MaxHealth, Inventory) VALUES (@0, @1, @2);", player.UserID, playerData.maxHealth, NetItem.ToString(playerData.inventory)); return(true); } catch (Exception ex) { Log.Error(ex.ToString()); } } else { try { database.Query("UPDATE Inventory SET MaxHealth = @0, Inventory = @1 WHERE Account = @2;", playerData.maxHealth, NetItem.ToString(playerData.inventory), player.UserID); return(true); } catch (Exception ex) { Log.Error(ex.ToString()); } } return(false); }
public PlayerData GetPlayerData(TPPlayer player, int acctid) { PlayerData playerData = new PlayerData(player); try { using (var reader = database.QueryReader("SELECT * FROM Inventory WHERE Account=@0", acctid)) { if (reader.Read()) { playerData.exists = true; playerData.maxHealth = reader.Get<int>("MaxHealth"); playerData.inventory = NetItem.Parse(reader.Get<string>("Inventory")); return playerData; } } } catch (Exception ex) { Log.Error(ex.ToString()); } return playerData; }
public PlayerData GetPlayerData(TPPlayer player, int acctid) { PlayerData playerData = new PlayerData(player); try { using (var reader = database.QueryReader("SELECT * FROM Inventory WHERE Account=@0", acctid)) { if (reader.Read()) { playerData.exists = true; playerData.maxHealth = reader.Get <int>("MaxHealth"); playerData.inventory = NetItem.Parse(reader.Get <string>("Inventory")); return(playerData); } } } catch (Exception ex) { Log.Error(ex.ToString()); } return(playerData); }
private void SendHelp(TPPlayer player) { player.SendMessage("Friends: /friend cmd [args]", TextColor); player.SendMessage("Friends: Available commands", TextColor); player.SendMessage("Friends: add, del, list, help", TextColor); }
public PlayerConnectionEventArgs(TPPlayer player, PlayerConnectionAction action) { Player = player; Action = action; }
public bool Kick(TPPlayer player, string reason, string adminUserName) { return(Kick(player, reason, false, false, adminUserName)); }
private void NetHooks_GetData(GetDataEventArgs e) { switch (e.MsgID) { case PacketTypes.ChestGetContents: if (!e.Handled) { using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)) { var reader = new BinaryReader(data); int x = reader.ReadInt32(); int y = reader.ReadInt32(); reader.Close(); int id = Terraria.Chest.FindChest(x, y); CPlayer player = Players[e.Msg.whoAmI]; TPPlayer tplayer = tPulse.Players[e.Msg.whoAmI]; if (id != -1) { Chest chest = ChestManager.GetChest(id); bool naggedAboutLock = false; switch (player.GetState()) { case SettingState.Setting: if (chest.HasOwner()) { if (chest.IsOwnerConvert(player)) { player.SendMessage("You already own this chest!", Color.Red); } else { player.SendMessage("This chest is already owned by someone!", Color.Red); naggedAboutLock = true; } } else { chest.SetID(id); chest.SetPosition(x, y); chest.SetOwner(player); chest.Lock(); player.SendMessage("This chest is now yours, and yours only.", Color.Red); } //end player setting player.SetState(SettingState.None); break; case SettingState.RegionSetting: if (chest.HasOwner()) { if (chest.IsOwnerConvert(player)) { if (chest.IsRegionLocked()) { chest.regionLock(false); player.SendMessage( "Region share disabled. This chest is now only yours. To fully remove protection use \"cunset\".", Color.Red); } else if (tPulse.Regions.InArea(x, y)) { chest.regionLock(true); player.SendMessage( "This chest is now shared between region users. Use this command again to disable it.", Color.Red); } else { player.SendMessage( "You can region share chest only if the chest is inside region!", Color.Red); } } else { player.SendMessage("This chest isn't yours!", Color.Red); naggedAboutLock = true; } } else if (tPulse.Regions.InArea(x, y)) { chest.SetID(id); chest.SetPosition(x, y); chest.SetOwner(player); chest.Lock(); chest.regionLock(true); player.SendMessage( "This chest is now shared between region users with you as owner. Use this command again to disable region sharing (You will still be owner).", Color.Red); } else { player.SendMessage( "You can region share chest only if the chest is inside region!", Color.Red); } //end player setting player.SetState(SettingState.None); break; case SettingState.PublicSetting: if (chest.HasOwner()) { if (chest.IsOwnerConvert(player)) { if (chest.IsLocked()) { chest.UnLock(); player.SendMessage( "This chest is now public! Use \"/cpset\" to set it private.", Color.Red); } else { chest.Lock(); player.SendMessage( "This chest is now private! Use \"/cpset\" to set it public.", Color.Red); } } else { player.SendMessage("This chest isn't yours!", Color.Red); naggedAboutLock = true; } } else { chest.SetID(id); chest.SetPosition(x, y); chest.SetOwner(player); player.SendMessage( "This chest is now yours. This chest is public. Use \"/cpset\" to set it private.", Color.Red); } break; case SettingState.Deleting: if (chest.HasOwner()) { if (chest.IsOwnerConvert(player) || tplayer.Group.HasPermission("removechestprotection")) { chest.Reset(); player.SendMessage("This chest is no longer yours!", Color.Red); } else { player.SendMessage("This chest isn't yours!", Color.Red); naggedAboutLock = true; } } else { player.SendMessage("This chest is not protected!", Color.Red); } //end player setting player.SetState(SettingState.None); break; case SettingState.PasswordSetting: if (chest.HasOwner()) { if (chest.IsOwnerConvert(player)) { chest.SetPassword(player.PasswordForChest); player.SendMessage("This chest is now protected with password.", Color.Red); } else { player.SendMessage("This chest isn't yours!", Color.Red); naggedAboutLock = true; } } else { chest.SetID(id); chest.SetPosition(x, y); chest.SetOwner(player); chest.Lock(); chest.SetPassword(player.PasswordForChest); player.SendMessage( "This chest is now protected with password, with you as owner.", Color.Red); } //end player setting player.SetState(SettingState.None); break; case SettingState.PasswordUnSetting: if (chest.HasOwner()) { if (chest.IsOwnerConvert(player)) { chest.SetPassword(""); player.SendMessage("This chest password has been removed.", Color.Red); } else { player.SendMessage("This chest isn't yours!", Color.Red); naggedAboutLock = true; } } else { player.SendMessage("This chest is not protected!", Color.Red); } //end player setting player.SetState(SettingState.None); break; case SettingState.RefillSetting: if (chest.HasOwner()) { if (chest.IsOwnerConvert(player)) { chest.SetRefill(true); player.SendMessage("This chest is will now always refill with items.", Color.Red); } else { player.SendMessage("This chest isn't yours!", Color.Red); naggedAboutLock = true; } } else { chest.SetID(id); chest.SetPosition(x, y); chest.SetOwner(player); chest.SetRefill(true); player.SendMessage( "This chest is will now always refill with items, with you as owner.", Color.Red); } //end player setting player.SetState(SettingState.None); break; case SettingState.RefillUnSetting: if (chest.IsRefill()) { if (chest.HasOwner()) { if (chest.IsOwnerConvert(player)) { chest.SetRefill(false); player.SendMessage( "This chest is will no longer refill with items.", Color.Red); } else { player.SendMessage("This chest isn't yours!", Color.Red); naggedAboutLock = true; } } else { chest.SetID(id); chest.SetPosition(x, y); chest.SetOwner(player); chest.SetRefill(false); player.SendMessage("This chest is will no longer refill with items", Color.Red); } } else { player.SendMessage("This chest is not refilling!", Color.Red); } //end player setting player.SetState(SettingState.None); break; case SettingState.UnLocking: if (chest.HasOwner()) { if (chest.IsLocked()) { if (chest.GetPassword() == "") { player.SendMessage("This chest can't be unlocked with password!", Color.Red); naggedAboutLock = true; } else if (chest.IsOwnerConvert(player)) { player.SendMessage( "You are owner of this chest, you dont need to unlock it. If you want to remove password use \"/lockchest remove\".", Color.Red); } else if (player.HasAccessToChest(chest.GetID())) { player.SendMessage("You already have access to this chest!", Color.Red); } else if (chest.CheckPassword(player.PasswordForChest)) { player.UnlockedChest(chest.GetID()); player.SendMessage( "Chest unlocked! When you leave game you must unlock it again.", Color.Red); } else { player.SendMessage("Wrong password for chest!", Color.Red); naggedAboutLock = true; } } else { player.SendMessage("This chest is not locked!", Color.Red); } } else { player.SendMessage("This chest is not protected!", Color.Red); } //end player setting player.SetState(SettingState.None); break; } if (tplayer.Group.HasPermission("showchestinfo")) //if player should see chest info { player.SendMessage( string.Format( "Chest Owner: {0} || Public: {1} || RegionShare: {2} || Password: {3} || Refill: {4}", chest.GetOwner() == "" ? "-None-" : chest.GetOwner(), chest.IsLocked() ? "No" : "Yes", chest.IsRegionLocked() ? "Yes" : "No", chest.GetPassword() == "" ? "No" : "Yes", chest.IsRefill() ? "Yes" : "No"), Color.Yellow); } if (!tplayer.Group.HasPermission("openallchests") && !chest.IsOpenFor(player)) //if player doesnt has permission to see inside chest, then break and message { e.Handled = true; if (!naggedAboutLock) { player.SendMessage( chest.GetPassword() != "" ? "This chest is magically locked with password. ( Use \"/cunlock PASSWORD\" to unlock it. )" : "This chest is magically locked.", Color.IndianRed); } return; } } if (player.GetState() != SettingState.None) { //if player is still setting something - end his setting player.SetState(SettingState.None); } } } break; case PacketTypes.TileKill: case PacketTypes.Tile: using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)) try { var reader = new BinaryReader(data); if (e.MsgID == PacketTypes.Tile) { byte type = reader.ReadByte(); if (!(type == 0 || type == 4)) { return; } } int x = reader.ReadInt32(); int y = reader.ReadInt32(); reader.Close(); if (Chest.TileIsChest(x, y)) //if is Chest { int id = Terraria.Chest.FindChest(x, y); CPlayer player = Players[e.Msg.whoAmI]; TPPlayer tplayer = tPulse.Players[e.Msg.whoAmI]; //dirty fix for finding chest, try to find chest point around if (id == -1) { try { id = Terraria.Chest.FindChest(x - 1, y); //search one tile left if (id == -1) { id = Terraria.Chest.FindChest(x - 1, y - 1); //search one tile left and one tile up if (id == -1) { id = Terraria.Chest.FindChest(x, y - 1); //search one tile up } } } catch (Exception ex) { Log.Write(ex.ToString(), LogLevel.Error); } } if (id != -1) //if have found chest { Chest chest = ChestManager.GetChest(id); if (chest.HasOwner()) //if owned stop removing { if (tplayer.Group.HasPermission("removechestprotection") || chest.IsOwnerConvert(player)) { //display more verbose info to player who has permission to remove protection on this chest player.SendMessage( "This chest is protected. To remove it, first remove protection using \"/cunset\" command.", Color.Red); } else { player.SendMessage("This chest is protected!", Color.Red); } player.SendTileSquare(x, y); e.Handled = true; } } } } catch (Exception ex) { Log.Write(ex.ToString(), LogLevel.Error); } break; case PacketTypes.ChestItem: using (var data = new MemoryStream(e.Msg.readBuffer, e.Index, e.Length)) { var reader = new BinaryReader(data); short id = reader.ReadInt16(); byte slot = reader.ReadByte(); byte stack = reader.ReadByte(); byte prefix = reader.ReadByte(); short type = reader.ReadByte(); if (id != -1) { Chest chest = ChestManager.GetChest(id); if (chest.IsRefill()) { e.Handled = true; } if (!e.Handled) { var item = Main.chest[id].item[slot]; var newitem = new Item(); newitem.netDefaults(type); newitem.Prefix(prefix); newitem.AffixName(); Log.Write(string.Format("{0}({1}) in slot {2} in chest at {3}x{4} was modified to {5}({6}) by {7}", item.name, item.stack, slot, Main.chest[id].x, Main.chest[id].y, newitem.name, stack, tPulse.Players[e.Msg.whoAmI].UserAccountName), LogLevel.Info, false); } } } break; } }
public bool ContainsPlayer(TPPlayer player) { return(Players.Contains(player)); }
public void ForceKick(TPPlayer player, string reason, bool silent = false, bool saveSSI = false) { Kick(player, reason, true, silent, null, saveSSI); }
public bool IsInTeam(TPPlayer player) { return(Team1.Contains(player) || Team2.Contains(player)); }
public bool Kick(TPPlayer player, string reason, string adminUserName) { return Kick(player, reason, false, false, adminUserName); }
public PlayerLoginEventArgs(TPPlayer player) { Player = player; }
protected void ChannelCommand(CommandArgs args) { TPPlayer player = args.Player; if (args.Parameters.Count > 1) { if ((player.Group.ContainsGroup("admin") || player.Group.ContainsGroup("superadmin")) && player.IsLoggedIn) { string pram = args.Parameters[0]; if (pram == "add") { //adding channel string cname = args.Parameters[1]; if (Manager.Contains(cname)) { player.SendErrorMessage(String.Format("Channels: {0} already exists!")); } else { Channel c; if (args.Parameters.Count == 5) { //with custom color byte r = 0; byte g = 0; byte b = 0; byte.TryParse(args.Parameters[2], out r); byte.TryParse(args.Parameters[3], out g); byte.TryParse(args.Parameters[4], out b); c = new Channel(cname, r, g, b); } else { c = new Channel(cname); } Manager.Add(c); Channels.Add(c); player.SendInfoMessage(String.Format("Channels: {0} channel added with success!", cname)); } } else if (pram == "del") { //deleting channel string cname = args.Parameters[1]; Channel c = RemoveChannel(cname); if (c != null) { Manager.Remove(cname); player.SendInfoMessage(String.Format("Channels: {0} channel removed!", cname)); } else { player.SendErrorMessage("Channels: This channel doesn't exists!"); } } else { player.SendErrorMessage("Channels: Invalid command!"); } } else { player.SendErrorMessage("Channels: You don't have the right to do this!"); } } else if (args.Parameters.Count == 1 && args.Parameters[0] == "list") { //listing channels player.SendInfoMessage("Channels: Listing channels"); foreach (Channel c in Channels) { player.SendInfoMessage(String.Format("{0} : {1}", c.Name, c.Count)); } player.SendInfoMessage(String.Format("{0} channel(s)", Channels.Count)); } else { player.SendErrorMessage("Channels: Invalid command"); } }
public bool HasPermissionToBuildInRegion(TPPlayer ply) { if (!ply.IsLoggedIn) { if (!ply.HasBeenNaggedAboutLoggingIn) { ply.SendMessage("You must be logged in to take advantage of protected regions.", Color.Red); ply.HasBeenNaggedAboutLoggingIn = true; } return false; } if (!DisableBuild) { return true; } return AllowedIDs.Contains(ply.UserID) || AllowedGroups.Contains(ply.Group.Name) || Owner == ply.UserAccountName || ply.Group.HasPermission("manageregion"); }
/// <summary> /// Kicks a player from the server.. /// </summary> /// <param name="ply">int player</param> /// <param name="reason">string reason</param> /// <param name="force">bool force (default: false)</param> /// <param name="silent">bool silent (default: false)</param> /// <param name="adminUserName">string adminUserName (default: null)</param> /// <param name="saveSSI">bool saveSSI (default: false)</param> public bool Kick(TPPlayer player, string reason, bool force = false, bool silent = false, string adminUserName = null, bool saveSSI = false) { if (!player.ConnectionAlive) return true; if (force || !player.Group.HasPermission(Permissions.immunetokick)) { string playerName = player.Name; player.SilentKickInProgress = silent; if (player.IsLoggedIn && saveSSI) player.SaveServerInventory(); player.Disconnect(string.Format("Kicked: {0}", reason)); Log.ConsoleInfo(string.Format("Kicked {0} for : {1}", playerName, reason)); string verb = force ? "force " : ""; if (!silent) { if (string.IsNullOrWhiteSpace(adminUserName)) Utils.Broadcast(string.Format("{0} was {1}kicked for {2}", playerName, verb, reason.ToLower()), Color.Green); else Utils.Broadcast(string.Format("{0} {1}kicked {2} for {3}", adminUserName, verb, playerName, reason.ToLower()), Color.Green); } return true; } return false; }
public bool CanBuild(int x, int y, TPPlayer ply) { if (!ply.Group.HasPermission(Permissions.canbuild)) { return false; } Region top = null; for (int i = 0; i < Regions.Count; i++) { if (Regions[i].InArea(x,y) ) { if (top == null) top = Regions[i]; else { if (Regions[i].Z > top.Z) top = Regions[i]; } } } return top == null || top.HasPermissionToBuildInRegion(ply); }
private void MessageCommand(CommandArgs args) { try { TPPlayer player = args.Player; TPPlayer dest; FriendList fl; if (player.IsLoggedIn) { fl = FriendsList.GetListByUserID(player.UserID); } else { return; } if (args.Parameters.Count >= 1) { string target = args.Parameters[0]; string message = ""; for (int i = 1; i < args.Parameters.Count; i++) { message += args.Parameters[i] + " "; } if (regexNumber.IsMatch(target)) { //Friends number int order = int.Parse(target) - 1; FUser udest = fl.GetUser(order); if (udest != null) { dest = GetOnlinePlayerById(udest.ID); if (dest != null) { dest.SendMessage(String.Format("{0}: {1}", player.UserAccountName, message), TextColor); player.SendMessage(String.Format("To {0}: {1}", dest.UserAccountName, message), TextColor); } else { player.SendMessage("Friends: this friend is not online", TextColor); } } else { player.SendMessage(String.Format("Friends: {0} is not a valid friend id", order.ToString()), TextColor); } } else { string name = args.Parameters[0]; FUser udest = fl.GetUser(name); if (udest != null) { dest = GetOnlinePlayerById(udest.ID); if (dest != null) { dest.SendMessage(String.Format("{0}: {1}", player.UserAccountName, message), TextColor); } else { player.SendMessage("Friends: this friend is not online", TextColor); } } else { player.SendMessage(String.Format("Friends: {0} is not a valid friend", name), TextColor); } } } } catch (Exception ex) { //put this into a log file or just remove it //will see Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.WriteLine(ex.Source); Console.WriteLine(ex.TargetSite); } }
private void FriendCommand(CommandArgs args) { //Sub-command //add : add a friend //del : delete a friend //list : list your friend list //help : Send a help message TPPlayer player = args.Player; if (player != null) { if (player.IsLoggedIn) { if (args.Parameters.Count >= 2) { User cu = tPulse.Users.GetUserByID(player.UserID); FriendList fl = GetListOrCreate(cu); string prams = args.Parameters[0]; prams = prams.ToLower(); if (prams == "add") { //Add string adduser = args.Parameters[1]; User u = tPulse.Users.GetUserByName(adduser); if (u == null) { player.SendMessage(String.Format("Friends: {0} doesn't exists !", adduser), TextColor); return; } if (fl.Contains(u.Name)) { player.SendMessage(String.Format("Friends: {0} is already in your friend list", adduser), TextColor); return; } FUser fu = new FUser(u); fl.Friends.Add(fu); player.SendMessage(String.Format("Friends: {0} added!", adduser), TextColor); } else if (prams == "del") { //Delete string remuser = args.Parameters[1]; if (fl.Contains(remuser)) { fl.RemoveUserByName(remuser); player.SendMessage(String.Format("Friends: {0} deleted!", remuser), TextColor); } else { player.SendMessage(String.Format("Friends: {0} is not in your friends list", remuser), TextColor); } } } else if (args.Parameters.Count == 1) { string prams = args.Parameters[0]; if (prams == "help") { SendHelp(player); } else if (prams == "list") { User cu = tPulse.Users.GetUserByID(player.UserID); FriendList fl = GetListOrCreate(cu); player.SendMessage(String.Format("Friends: {0} friend(s) in your list", fl.Friends.Count.ToString()), TextColor); int i = 1; foreach (FUser fu in fl.Friends) { string status = IsUserOnline(fu.ID) ? "Online" : "Offline"; player.SendMessage(String.Format("{0} : {1} : {2}", i.ToString(), fu.Name, status), TextColor); i++; } } } else { player.SendMessage("Friends: Missing arguments", TextColor); } } else { player.SendMessage("Friends: You can't use friend list, because you're not logged!", TextColor); } } }