本文整理汇总了C#中DarkMultiPlayerServer.ClientObject类的典型用法代码示例。如果您正苦于以下问题:C# ClientObject类的具体用法?C# ClientObject怎么用?C# ClientObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientObject类属于DarkMultiPlayerServer命名空间,在下文中一共展示了ClientObject类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: SendDMPModMessageToAll
public static void SendDMPModMessageToAll(ClientObject excludeClient, string modName, byte[] messageData, bool highPriority)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.MOD_DATA;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string>(modName);
mw.Write<byte[]>(messageData);
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToAll(excludeClient, newMessage, highPriority);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:12,代码来源:DMPModInterface.cs
示例2: OnMessageReceived
public override void OnMessageReceived(ClientObject client, ClientMessage message)
{
if (!client.authenticated)
{
//Only handle authenticated messages
return;
}
if (message.type == ClientMessageType.SCENARIO_DATA)
{
HandleScenarioMessage(client, message);
message.handled = true;
}
}
开发者ID:JoshBlake,项目名称:DMPSharedScience,代码行数:14,代码来源:SharedSciencePlugin.cs
示例3: FireOnClientDisconnect
//Fire OnClientDisconnect
public static void FireOnClientDisconnect(ClientObject client)
{
foreach (var plugin in loadedPlugins)
{
try
{
plugin.OnClientDisconnect(client);
}
catch (Exception e)
{
Type type = plugin.GetType();
DarkLog.Debug("Error thrown in OnClientDisconnect event for " + type.FullName + " (" + type.Assembly.FullName + "), Exception: " + e);
}
}
}
开发者ID:JoshBlake,项目名称:DarkMultiPlayer,代码行数:16,代码来源:DMPPluginHandler.cs
示例4: SendCKANFileToClient
private void SendCKANFileToClient(ClientObject client)
{
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>(CKAN_PROTOCOL_VERSION);
if (!File.Exists(ckanFile))
{
mw.Write<bool>(false);
byte[] sendData = mw.GetMessageBytes();
DMPModInterface.SendDMPModMessageToClient(client, "DMPCkanPlugin", sendData, false);
return;
}
mw.Write<bool>(true);
mw.Write<string>(File.ReadAllText(ckanFile));
}
DarkLog.Debug("Sent CKAN file to " + client.playerName);
}
开发者ID:godarklight,项目名称:DMPCkanPlugin,代码行数:17,代码来源:DMPServerPlugin.cs
示例5: OnMessageReceived
public void OnMessageReceived(ClientObject client, ClientMessage message)
{
if (message.type == ClientMessageType.CHAT_MESSAGE)
{
using (MessageReader mr = new MessageReader(message.data, false))
{
ChatMessageType messageType = (ChatMessageType)mr.Read<int>();
string fromPlayer = mr.Read<string>();
if (messageType == ChatMessageType.CHANNEL_MESSAGE)
{
string channel = mr.Read<string>();
string umessage = mr.Read<string>();
ircClient.Channels["#" + channel].SendMessage(String.Format("{0} -> {1}", fromPlayer, umessage));
}
}
}
}
开发者ID:JoshBlake,项目名称:DarkChat,代码行数:17,代码来源:DarkChat.cs
示例6: SendDMPModMessageToClient
public static void SendDMPModMessageToClient(ClientObject client, string modName, byte[] messageData, bool highPriority)
{
if (modName == null)
{
//Now that's just being silly :)
return;
}
if (messageData == null)
{
DarkLog.Debug(modName + " attemped to send a null message");
return;
}
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.MOD_DATA;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string>(modName);
mw.Write<byte[]>(messageData);
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage , highPriority);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:22,代码来源:DMPModInterface.cs
示例7: OnCKANRequest
//Receive message data (PROTOCOL 1):
//int ckan protocol version
//int ckan request type:
//1: CKAN metadata file
//Send message data (PROTOCOL 1):
//int ckan protocol version
//bool ckan available (true/false)
//if ckan available: UTF-8 string (ckan export data)
private void OnCKANRequest(ClientObject client, byte[] messageData)
{
using (MessageReader mr = new MessageReader(messageData))
{
int clientProtocol = mr.Read<int>();
if (clientProtocol != CKAN_PROTOCOL_VERSION)
{
DarkLog.Error("Client " + client.playerName + " connected with CKAN protocol " + clientProtocol + ", server version: " + CKAN_PROTOCOL_VERSION);
return;
}
int requestType = mr.Read<int>();
switch (requestType)
{
case 1:
SendCKANFileToClient(client);
break;
default:
DarkLog.Error("Unknown CKAN request type: " + requestType);
break;
}
}
}
开发者ID:godarklight,项目名称:DMPCkanPlugin,代码行数:30,代码来源:DMPServerPlugin.cs
示例8: FireOnMessageReceived
//Fire OnMessageReceived
public static void FireOnMessageReceived(ClientObject client, ClientMessage message)
{
bool handledByAny = false;
foreach (var plugin in loadedPlugins)
{
try
{
plugin.OnMessageReceived(client, message);
//prevent plugins from unhandling other plugin's handled requests
if (message.handled)
{
handledByAny = true;
}
}
catch (Exception e)
{
Type type = plugin.GetType();
DarkLog.Debug("Error thrown in OnMessageReceived event for " + type.FullName + " (" + type.Assembly.FullName + "), Exception: " + e);
}
}
message.handled = handledByAny;
}
开发者ID:JoshBlake,项目名称:DarkMultiPlayer,代码行数:24,代码来源:DMPPluginHandler.cs
示例9: DisconnectClient
private static void DisconnectClient(ClientObject client)
{
lock (client.disconnectLock)
{
if (client.connectionStatus != ConnectionStatus.DISCONNECTED)
{
DMPPluginHandler.FireOnClientDisconnect(client);
if (client.playerName != null)
{
if (playerChatChannels.ContainsKey(client.playerName))
{
playerChatChannels.Remove(client.playerName);
}
if (playerDownloadedScreenshotIndex.ContainsKey(client.playerName))
{
playerDownloadedScreenshotIndex.Remove(client.playerName);
}
if (playerUploadedScreenshotIndex.ContainsKey(client.playerName))
{
playerUploadedScreenshotIndex.Remove(client.playerName);
}
if (playerWatchScreenshot.ContainsKey(client.playerName))
{
playerWatchScreenshot.Remove(client.playerName);
}
}
client.connectionStatus = ConnectionStatus.DISCONNECTED;
if (client.authenticated)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.PLAYER_DISCONNECT;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string>(client.playerName);
newMessage.data = mw.GetMessageBytes();
}
SendToAll(client, newMessage, true);
lockSystem.ReleasePlayerLocks(client.playerName);
}
deleteClients.Enqueue(client);
try
{
if (client.connection != null)
{
client.connection.GetStream().Close();
client.connection.Close();
}
}
catch (Exception e)
{
DarkLog.Debug("Error closing client connection: " + e.Message);
}
Server.lastPlayerActivity = Server.serverClock.ElapsedMilliseconds;
}
}
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:56,代码来源:ClientHandler.cs
示例10: StartReceivingIncomingMessages
private static void StartReceivingIncomingMessages(ClientObject client)
{
client.lastReceiveTime = Server.serverClock.ElapsedMilliseconds;
//Allocate byte for header
client.receiveMessage = new ClientMessage();
client.receiveMessage.data = new byte[8];
client.receiveMessageBytesLeft = client.receiveMessage.data.Length;
try
{
client.connection.GetStream().BeginRead(client.receiveMessage.data, client.receiveMessage.data.Length - client.receiveMessageBytesLeft, client.receiveMessageBytesLeft, new AsyncCallback(ReceiveCallback), client);
}
catch (Exception e)
{
HandleDisconnectException("Start Receive", client, e);
}
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:16,代码来源:ClientHandler.cs
示例11: SplitAndRewriteMessage
private static void SplitAndRewriteMessage(ClientObject client, ref ServerMessage message)
{
if (message == null)
{
return;
}
if (message.data == null)
{
return;
}
if (message.data.Length > Common.SPLIT_MESSAGE_LENGTH)
{
ServerMessage newSplitMessage = new ServerMessage();
newSplitMessage.type = ServerMessageType.SPLIT_MESSAGE;
int splitBytesLeft = message.data.Length;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)message.type);
mw.Write<int>(message.data.Length);
byte[] firstSplit = new byte[Common.SPLIT_MESSAGE_LENGTH];
Array.Copy(message.data, 0, firstSplit, 0, Common.SPLIT_MESSAGE_LENGTH);
mw.Write<byte[]>(firstSplit);
splitBytesLeft -= Common.SPLIT_MESSAGE_LENGTH;
newSplitMessage.data = mw.GetMessageBytes();
//SPLIT_MESSAGE adds a 12 byte header.
client.bytesQueuedOut += 12;
client.sendMessageQueueSplit.Enqueue(newSplitMessage);
}
while (splitBytesLeft > 0)
{
ServerMessage currentSplitMessage = new ServerMessage();
currentSplitMessage.type = ServerMessageType.SPLIT_MESSAGE;
currentSplitMessage.data = new byte[Math.Min(splitBytesLeft, Common.SPLIT_MESSAGE_LENGTH)];
Array.Copy(message.data, message.data.Length - splitBytesLeft, currentSplitMessage.data, 0, currentSplitMessage.data.Length);
splitBytesLeft -= currentSplitMessage.data.Length;
//Add the SPLIT_MESSAGE header to the out queue count.
client.bytesQueuedOut += 12;
client.sendMessageQueueSplit.Enqueue(currentSplitMessage);
}
client.sendMessageQueueSplit.TryDequeue(out message);
}
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:44,代码来源:ClientHandler.cs
示例12: StartSendingOutgoingMessages
private static void StartSendingOutgoingMessages(ClientObject client)
{
Thread clientSendThread = new Thread(new ParameterizedThreadStart(SendOutgoingMessages));
clientSendThread.IsBackground = true;
clientSendThread.Start(client);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:6,代码来源:ClientHandler.cs
示例13: SendConnectionEnd
private static void SendConnectionEnd(ClientObject client, string reason)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.CONNECTION_END;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string>(reason);
newMessage.data = mw.GetMessageBytes();
}
SendToClient(client, newMessage, true);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:11,代码来源:ClientHandler.cs
示例14: SendMotdReply
private static void SendMotdReply(ClientObject client)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.MOTD_REPLY;
string newMotd = Settings.settingsStore.serverMotd;
newMotd = newMotd.Replace("%name%", client.playerName);
newMotd = newMotd.Replace(@"\n", Environment.NewLine);
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string>(newMotd);
newMessage.data = mw.GetMessageBytes();
}
SendToClient(client, newMessage, true);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:16,代码来源:ClientHandler.cs
示例15: SendAllPlayerStatus
private static void SendAllPlayerStatus(ClientObject client)
{
foreach (ClientObject otherClient in clients)
{
if (otherClient.authenticated)
{
if (otherClient != client)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.PLAYER_STATUS;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string>(otherClient.playerName);
mw.Write<string>(otherClient.playerStatus.vesselText);
mw.Write<string>(otherClient.playerStatus.statusText);
newMessage.data = mw.GetMessageBytes();
}
SendToClient(client, newMessage, true);
}
}
}
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:22,代码来源:ClientHandler.cs
示例16: SendVessel
private static void SendVessel(ClientObject client, byte[] vesselData)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.VESSEL_PROTO;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<double>(0);
mw.Write<byte[]>(vesselData);
newMessage.data = mw.GetMessageBytes();
}
SendToClient(client, newMessage, false);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:12,代码来源:ClientHandler.cs
示例17: SendVesselsComplete
private static void SendVesselsComplete(ClientObject client)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.VESSEL_COMPLETE;
SendToClient(client, newMessage, false);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:6,代码来源:ClientHandler.cs
示例18: SendAllSubspaces
private static void SendAllSubspaces(ClientObject client)
{
//Send all the locks.
foreach (KeyValuePair<int, Subspace> subspace in subspaces)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.WARP_CONTROL;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)WarpMessageType.NEW_SUBSPACE);
mw.Write<string>("");
mw.Write<int>(subspace.Key);
mw.Write<long>(subspace.Value.serverClock);
mw.Write<double>(subspace.Value.planetTime);
mw.Write<float>(subspace.Value.subspaceSpeed);
newMessage.data = mw.GetMessageBytes();
}
SendToClient(client, newMessage, true);
}
//Tell the player "when" everyone is.
foreach (ClientObject otherClient in clients)
{
if (otherClient.authenticated && (otherClient.playerName != client.playerName))
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.WARP_CONTROL;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)WarpMessageType.CHANGE_SUBSPACE);
mw.Write<string>(otherClient.playerName);
mw.Write<int>(otherClient.subspace);
newMessage.data = mw.GetMessageBytes();
}
SendToClient(client, newMessage, true);
}
}
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:37,代码来源:ClientHandler.cs
示例19: SetupClient
private static void SetupClient(TcpClient newClientConnection)
{
ClientObject newClientObject = new ClientObject();
newClientObject.subspace = GetLatestSubspace();
newClientObject.playerStatus = new PlayerStatus();
newClientObject.connectionStatus = ConnectionStatus.CONNECTED;
newClientObject.endpoint = newClientConnection.Client.RemoteEndPoint.ToString();
newClientObject.ipAddress = (newClientConnection.Client.RemoteEndPoint as IPEndPoint).Address;
//Keep the connection reference
newClientObject.connection = newClientConnection;
StartReceivingIncomingMessages(newClientObject);
StartSendingOutgoingMessages(newClientObject);
DMPPluginHandler.FireOnClientConnect(newClientObject);
SendHandshakeChallange(newClientObject);
addClients.Enqueue(newClientObject);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:16,代码来源:ClientHandler.cs
示例20: SendScenarioModules
private static void SendScenarioModules(ClientObject client)
{
int numberOfScenarioModules = Directory.GetFiles(Path.Combine(Server.universeDirectory, "Scenarios", client.playerName)).Length;
int currentScenarioModule = 0;
string[] scenarioNames = new string[numberOfScenarioModules];
byte[][] scenarioDataArray = new byte[numberOfScenarioModules][];
foreach (string file in Directory.GetFiles(Path.Combine(Server.universeDirectory, "Scenarios", client.playerName)))
{
//Remove the .txt part for the name
scenarioNames[currentScenarioModule] = Path.GetFileNameWithoutExtension(file);
scenarioDataArray[currentScenarioModule] = File.ReadAllBytes(file);
currentScenarioModule++;
}
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.SCENARIO_DATA;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<string[]>(scenarioNames);
foreach (byte[] scenarioData in scenarioDataArray)
{
mw.Write<byte[]>(scenarioData);
}
newMessage.data = mw.GetMessageBytes();
}
SendToClient(client, newMessage, true);
}
开发者ID:nux17,项目名称:DarkMultiPlayer,代码行数:26,代码来源:ClientHandler.cs
注:本文中的DarkMultiPlayerServer.ClientObject类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论