本文整理汇总了C#中Server.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Server.SendMessage方法的具体用法?C# Server.SendMessage怎么用?C# Server.SendMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.SendMessage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Ban
public bool Ban(Server server, int sourceClientId, int targetClientId, string reason)
{
if (!server.PlayerHasPrivilege(sourceClientId, ServerClientMisc.Privilege.ban))
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandInsufficientPrivileges"), server.colorError));
return false;
}
if (!reason.Equals(""))
{
reason = server.language.Get("Server_CommandKickBanReason") + reason + ".";
}
ClientOnServer targetClient = server.GetClient(targetClientId);
if (targetClient != null)
{
if (targetClient.clientGroup.IsSuperior(server.GetClient(sourceClientId).clientGroup) || targetClient.clientGroup.EqualLevel(server.GetClient(sourceClientId).clientGroup))
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandTargetUserSuperior"), server.colorError));
return false;
}
string targetName = targetClient.playername;
string sourceName = server.GetClient(sourceClientId).playername;
string targetNameColored = targetClient.ColoredPlayername(server.colorImportant);
string sourceNameColored = server.GetClient(sourceClientId).ColoredPlayername(server.colorImportant);
server.banlist.BanPlayer(targetName, sourceName, reason);
SaveBanlist(server);
server.SendMessageToAll(string.Format(server.language.Get("Server_CommandBanMessage"), server.colorImportant, targetNameColored, sourceNameColored, reason));
server.ServerEventLog(string.Format("{0} bans {1}.{2}", sourceName, targetName, reason));
server.SendPacket(targetClientId, ServerPackets.DisconnectPlayer(string.Format(server.language.Get("Server_CommandBanNotification"), reason)));
server.KillPlayer(targetClientId);
return true;
}
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandNonexistantID"), server.colorError, targetClientId));
return false;
}
示例2: RestartMods
public bool RestartMods(Server server, int sourceClientId)
{
if (!server.PlayerHasPrivilege(sourceClientId, ServerClientMisc.Privilege.restart))
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandInsufficientPrivileges"), server.colorError));
return false;
}
server.SendMessageToAll(string.Format(server.language.Get("Server_CommandRestartModsSuccess"), server.colorImportant, server.GetClient(sourceClientId).ColoredPlayername(server.colorImportant)));
server.ServerEventLog(string.Format("{0} restarts mods.", server.GetClient(sourceClientId).playername));
server.modEventHandlers = new ModEventHandlers();
for (int i = 0; i < server.systemsCount; i++)
{
if (server.systems[i] == null) { continue; }
server.systems[i].OnRestart(server);
}
LoadMods(server, true);
return true;
}
示例3: Unban
public bool Unban(Server server, int sourceClientId, string type, string target)
{
if (!server.PlayerHasPrivilege(sourceClientId, ServerClientMisc.Privilege.unban))
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandInsufficientPrivileges"), server.colorError));
return false;
}
// unban a playername
if (type.Equals("-p"))
{
// case insensitive
bool exists = server.banlist.UnbanPlayer(target);
SaveBanlist(server);
if (!exists)
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandPlayerNotFound"), server.colorError, target));
}
else
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandUnbanSuccess"), server.colorSuccess, target));
server.ServerEventLog(string.Format("{0} unbans player {1}.", server.GetClient(sourceClientId).playername, target));
}
return true;
}
// unban an IP
else if (type.Equals("-ip"))
{
bool exists = server.banlist.UnbanIP(target);
SaveBanlist(server);
if (!exists)
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandUnbanIPNotFound"), server.colorError, target));
}
else
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandUnbanIPSuccess"), server.colorSuccess, target));
server.ServerEventLog(string.Format("{0} unbans IP {1}.", server.GetClient(sourceClientId).playername, target));
}
return true;
}
server.SendMessage(sourceClientId, string.Format("{0}Invalid type: {1}", server.colorError, type));
return false;
}
示例4: OnCommand
public override bool OnCommand(Server server, int sourceClientId, string command, string argument)
{
string[] ss;
int id;
int duration;
Language language = server.language;
string colorError = server.colorError;
switch (command)
{
case "banip_id":
ss = argument.Split(new[] { ' ' });
if (!Int32.TryParse(ss[0], out id))
{
server.SendMessage(sourceClientId, colorError + language.Get("Server_CommandInvalidArgs"));
return true;
}
if (ss.Length >= 2)
{
BanIP(server, sourceClientId, id, string.Join(" ", ss, 1, ss.Length - 1));
return true;
}
BanIP(server, sourceClientId, id);
return true;
case "banip":
ss = argument.Split(new[] { ' ' });
if (ss.Length >= 2)
{
BanIP(server, sourceClientId, ss[0], string.Join(" ", ss, 1, ss.Length - 1));
return true;
}
BanIP(server, sourceClientId, argument);
return true;
case "ban_id":
ss = argument.Split(new[] { ' ' });
if (!Int32.TryParse(ss[0], out id))
{
server.SendMessage(sourceClientId, colorError + language.Get("Server_CommandInvalidArgs"));
return true;
}
if (ss.Length >= 2)
{
Ban(server, sourceClientId, id, string.Join(" ", ss, 1, ss.Length - 1));
return true;
}
Ban(server, sourceClientId, id);
return true;
case "ban":
ss = argument.Split(new[] { ' ' });
if (ss.Length >= 2)
{
Ban(server, sourceClientId, ss[0], string.Join(" ", ss, 1, ss.Length - 1));
return true;
}
Ban(server, sourceClientId, argument);
return true;
case "timebanip_id": //Format: /timebanip_id <player_id> <duration> [reason]
ss = argument.Split(new[] { ' ' });
if (ss.Length < 2)
{
server.SendMessage(sourceClientId, colorError + language.Get("Server_CommandInvalidArgs"));
return true;
}
if (!Int32.TryParse(ss[0], out id))
{
server.SendMessage(sourceClientId, colorError + language.Get("Server_CommandInvalidArgs"));
return true;
}
if (!Int32.TryParse(ss[1], out duration))
{
server.SendMessage(sourceClientId, colorError + language.Get("Server_CommandInvalidArgs"));
return true;
}
if (duration <= 0)
{
server.SendMessage(sourceClientId, colorError + language.Get("Server_CommandTimeBanInvalidValue"));
return true;
}
if (ss.Length >= 3)
{
this.TimeBanIP(server, sourceClientId, id, string.Join(" ", ss, 2, ss.Length - 2), duration);
return true;
}
this.TimeBanIP(server, sourceClientId, id, duration);
return true;
case "timebanip": //Format: /timebanip <playername> <duration> [reason]
ss = argument.Split(new[] { ' ' });
if (ss.Length < 2)
{
server.SendMessage(sourceClientId, colorError + language.Get("Server_CommandInvalidArgs"));
return true;
}
if (!Int32.TryParse(ss[1], out duration))
{
server.SendMessage(sourceClientId, colorError + language.Get("Server_CommandInvalidArgs"));
return true;
}
if (duration <= 0)
{
//.........这里部分代码省略.........
示例5: BanOffline
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;
}