public bool BanOffline(Server server, int sourceClientId, string target, string reason) { if (!server.PlayerHasPrivilege(sourceClientId, ServerClientMisc.Privilege.ban_offline)) { server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandInsufficientPrivileges"), server.colorError)); return(false); } if (!reason.Equals("")) { reason = server.language.Get("Server_CommandKickBanReason") + reason; } if (server.GetClient(target) != null) { server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandBanOfflineTargetOnline"), server.colorError, target)); return(false); } // Target is at the moment not online. Check if there is an entry in ServerClient // Get related client from config file ManicDigger.Client targetClient = server.serverClient.Clients.Find( delegate(ManicDigger.Client client) { return(client.Name.Equals(target, StringComparison.InvariantCultureIgnoreCase)); } ); // Entry exists. if (targetClient != null) { // Get target's group. ManicDigger.Group targetGroup = server.serverClient.Groups.Find( delegate(ManicDigger.Group grp) { return(grp.Name.Equals(targetClient.Group)); } ); if (targetGroup == null) { server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandInvalidGroup"), server.colorError)); return(false); } // Check if target's group is superior. if (targetGroup.IsSuperior(server.GetClient(sourceClientId).clientGroup) || targetGroup.EqualLevel(server.GetClient(sourceClientId).clientGroup)) { server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandTargetUserSuperior"), server.colorError)); return(false); } // Remove target's entry. server.serverClient.Clients.Remove(targetClient); server.serverClientNeedsSaving = true; } // Finally ban user. server.banlist.BanPlayer(target, server.GetClient(sourceClientId).playername, reason); SaveBanlist(server); server.SendMessageToAll(string.Format(server.language.Get("Server_CommandBanOfflineMessage"), server.colorImportant, target, server.GetClient(sourceClientId).ColoredPlayername(server.colorImportant), reason)); server.ServerEventLog(string.Format("{0} bans {1}.{2}", server.GetClient(sourceClientId).playername, target, reason)); return(true); }
public bool SetSpawnPosition(int sourceClientId, int x, int y, int? z) { if (!PlayerHasPrivilege(sourceClientId, ServerClientMisc.Privilege.set_home)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandInsufficientPrivileges"), colorError)); return false; } Console.WriteLine(x + " " + y + " " + z); // Validate spawn position. int rZ = 0; if (z == null) { if (!MapUtil.IsValidPos(d_Map, x, y)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandSetSpawnInvalidCoordinates"), colorError)); return false; } rZ = MapUtil.blockheight(d_Map, 0, x, y); } else { rZ = z.Value; } if (!MapUtil.IsValidPos(d_Map, x, y, rZ)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandSetSpawnInvalidCoordinates"), colorError)); return false; } // Get related client entry. ManicDigger.Client clientEntry = serverClient.Clients.Find( delegate(ManicDigger.Client client) { return client.Name.Equals(GetClient(sourceClientId).playername, StringComparison.InvariantCultureIgnoreCase); } ); // TODO: When guests have "set_home" privilege, count of client entries can quickly grow. if (clientEntry == null) { clientEntry = new ManicDigger.Client(); clientEntry.Name = GetClient(sourceClientId).playername; clientEntry.Group = GetClient(sourceClientId).clientGroup.Name; serverClient.Clients.Add(clientEntry); } // Change or add spawn entry of client. clientEntry.Spawn = new ManicDigger.Spawn() { x = x, y = y, z = z, }; serverClientNeedsSaving = true; // Send player new spawn position. this.SendPlayerSpawnPosition(sourceClientId, x, y, rZ); return true; }
public bool ChangeGroupOffline(int sourceClientId, string target, string newGroupName) { if (!PlayerHasPrivilege(sourceClientId, ServerClientMisc.Privilege.chgrp_offline)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandInsufficientPrivileges"), colorError)); return false; } // Get related group from config file. ManicDigger.Group newGroup = serverClient.Groups.Find( delegate(ManicDigger.Group grp) { return grp.Name.Equals(newGroupName, StringComparison.InvariantCultureIgnoreCase); } ); if (newGroup == null) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandGroupNotFound"), colorError, newGroupName)); return false; } // Forbid to assign groups with levels higher then the source's client group level. if (newGroup.IsSuperior(GetClient(sourceClientId).clientGroup)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandTargetGroupSuperior"), colorError)); return false; } // Get related client from config file. ManicDigger.Client clientConfig = serverClient.Clients.Find( delegate(ManicDigger.Client client) { return client.Name.Equals(target, StringComparison.InvariantCultureIgnoreCase); } ); // Get related client. ClientOnServer targetClient = GetClient(target); if (targetClient != null) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandOpTargetOnline"), colorError, target)); return false; } // Target is at the moment not online. Create or change a entry in ServerClient. if (clientConfig == null) { clientConfig = new ManicDigger.Client(); clientConfig.Name = target; clientConfig.Group = newGroup.Name; serverClient.Clients.Add(clientConfig); } else { // Check if target's current group is superior. ManicDigger.Group oldGroup = serverClient.Groups.Find( delegate(ManicDigger.Group grp) { return grp.Name.Equals(clientConfig.Group); } ); if (oldGroup == null) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandInvalidGroup"), colorError)); return false; } if (oldGroup.IsSuperior(GetClient(sourceClientId).clientGroup) || oldGroup.EqualLevel(GetClient(sourceClientId).clientGroup)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandTargetUserSuperior"), colorError)); return false; } clientConfig.Group = newGroup.Name; } serverClientNeedsSaving = true; SendMessageToAll(string.Format(language.Get("Server_CommandSetOfflineGroupTo"), colorSuccess, GetClient(sourceClientId).ColoredPlayername(colorSuccess), target, newGroup.GroupColorString() + newGroupName)); ServerEventLog(String.Format("{0} sets group of {1} to {2} (offline).", GetClient(sourceClientId).playername, target, newGroupName)); return true; }
public bool ChangeGroup(int sourceClientId, string target, string newGroupName) { if (!PlayerHasPrivilege(sourceClientId, ServerClientMisc.Privilege.chgrp)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandInsufficientPrivileges"), colorError)); return false; } // Get related group from config file. ManicDigger.Group newGroup = serverClient.Groups.Find( delegate(ManicDigger.Group grp) { return grp.Name.Equals(newGroupName, StringComparison.InvariantCultureIgnoreCase); } ); if (newGroup == null) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandGroupNotFound"), colorError, newGroupName)); return false; } // Forbid to assign groups with levels higher then the source's client group level. if (newGroup.IsSuperior(GetClient(sourceClientId).clientGroup)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandTargetGroupSuperior"), colorError)); return false; } // Get related client from config file ManicDigger.Client clientConfig = serverClient.Clients.Find( delegate(ManicDigger.Client client) { return client.Name.Equals(target, StringComparison.InvariantCultureIgnoreCase); } ); // Get related client. ClientOnServer targetClient = GetClient(target); if (targetClient != null) { if (targetClient.clientGroup.IsSuperior(GetClient(sourceClientId).clientGroup) || targetClient.clientGroup.EqualLevel(GetClient(sourceClientId).clientGroup)) { SendMessage(sourceClientId, string.Format(language.Get("Server_CommandTargetUserSuperior"), colorError)); return false; } // Add or change group membership in config file. // Client is not yet in config file. Create a new entry. if (clientConfig == null) { clientConfig = new ManicDigger.Client(); clientConfig.Name = targetClient.playername; clientConfig.Group = newGroup.Name; serverClient.Clients.Add(clientConfig); } else { clientConfig.Group = newGroup.Name; } serverClientNeedsSaving = true; SendMessageToAll(string.Format(language.Get("Server_CommandSetGroupTo"), colorSuccess, GetClient(sourceClientId).ColoredPlayername(colorSuccess), targetClient.ColoredPlayername(colorSuccess), newGroup.GroupColorString() + newGroupName)); ServerEventLog(String.Format("{0} sets group of {1} to {2}.", GetClient(sourceClientId).playername, targetClient.playername, newGroupName)); targetClient.AssignGroup(newGroup); SendFreemoveState(targetClient.Id, targetClient.privileges.Contains(ServerClientMisc.Privilege.freemove)); SetFillAreaLimit(targetClient.Id); return true; } // Target is at the moment not online. SendMessage(sourceClientId, string.Format(language.Get("Server_CommandOpTargetOffline"), colorError, target)); return false; }