本文整理汇总了C#中MessageWriter.Write方法的典型用法代码示例。如果您正苦于以下问题:C# MessageWriter.Write方法的具体用法?C# MessageWriter.Write怎么用?C# MessageWriter.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessageWriter
的用法示例。
在下文中一共展示了MessageWriter.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendAllPlayerColors
public static void SendAllPlayerColors(ClientObject client)
{
Dictionary<string,float[]> sendColors = new Dictionary<string, float[]>();
foreach (ClientObject otherClient in ClientHandler.GetClients())
{
if (otherClient.authenticated && otherClient.playerColor != null)
{
if (otherClient != client)
{
sendColors[otherClient.playerName] = otherClient.playerColor;
}
}
}
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.PLAYER_COLOR;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)PlayerColorMessageType.LIST);
mw.Write<int>(sendColors.Count);
foreach (KeyValuePair<string, float[]> kvp in sendColors)
{
mw.Write<string>(kvp.Key);
mw.Write<float[]>(kvp.Value);
}
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, true);
}
示例2: WriteCommand
/// <summary>
/// Writes the <see cref="UpgradeBuildingCommand"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="UpgradeBuildingCommand"/>.
/// </param>
public override void WriteCommand(MessageWriter writer)
{
writer.Write(BuildingGameIndex);
writer.Write(Unknown1);
writer.Write(Unknown2);
}
示例3: SendScenarioModules
public 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)
{
if (client.compressionEnabled)
{
mw.Write<byte[]>(Compression.CompressIfNeeded(scenarioData));
}
else
{
mw.Write<byte[]>(Compression.AddCompressionHeader(scenarioData, false));
}
}
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, true);
}
示例4: RunNukeKSC
public static void RunNukeKSC(string commandText)
{
lock (Server.universeSizeLock)
{
string[] vesselList = Directory.GetFiles(Path.Combine(Server.universeDirectory, "Vessels"));
int numberOfRemovals = 0;
foreach (string vesselFile in vesselList)
{
string vesselID = Path.GetFileNameWithoutExtension(vesselFile);
bool landedAtKSC = false;
bool landedAtRunway = false;
using (StreamReader sr = new StreamReader(vesselFile))
{
string currentLine = sr.ReadLine();
while (currentLine != null && !landedAtKSC && !landedAtRunway)
{
string trimmedLine = currentLine.Trim();
if (trimmedLine.StartsWith("landedAt = "))
{
string landedAt = trimmedLine.Substring(trimmedLine.IndexOf("=") + 2);
if (landedAt == "KSC")
{
landedAtKSC = true;
}
if (landedAt == "Runway")
{
landedAtRunway = true;
}
}
currentLine = sr.ReadLine();
}
}
if (landedAtKSC | landedAtRunway)
{
DarkLog.Normal("Removing vessel: " + vesselID);
//Delete it from the universe
if (File.Exists(vesselFile))
{
File.Delete(vesselFile);
}
//Send a vessel remove message
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.VESSEL_REMOVE;
using (MessageWriter mw = new MessageWriter())
{
//Send it with a delete time of 0 so it shows up for all players.
mw.Write<int>(0);
mw.Write<double>(0);
mw.Write<string>(vesselID);
mw.Write<bool>(false);
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToAll(null, newMessage, false);
numberOfRemovals++;
}
}
DarkLog.Normal("Nuked " + numberOfRemovals + " vessels around the KSC");
}
}
示例5: WriteCommand
/// <summary>
/// Writes the <see cref="BuyBuildingCommand"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="BuyBuildingCommand"/>.
/// </param>
public override void WriteCommand(MessageWriter writer)
{
writer.Write(X);
writer.Write(Y);
writer.Write(BuildingDataIndex);
writer.Write(Unknown1);
}
示例6: WriteCommand
/// <summary>
/// Writes the <see cref="BuyDecoration"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="BuyDecoration"/>.
/// </param>
public override void WriteCommand(MessageWriter writer)
{
writer.Write(X);
writer.Write(Y);
writer.Write(DecorationDataIndex);
writer.Write(Unknown1);
}
示例7: WriteCommand
/// <summary>
/// Writes the <see cref="MoveVillageObjectCommand"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="MoveVillageObjectCommand"/>.
/// </param>
/// <exception cref="NullReferenceException">MoveData is null.</exception>
public override void WriteCommand(MessageWriter writer)
{
if (MoveData == null)
throw new NullReferenceException("MoveData cannot be null");
writer.Write(MoveData.X);
writer.Write(MoveData.Y);
writer.Write(MoveData.VillageObjectGameIndex);
writer.Write(Unknown1);
}
示例8: WriteMessage
/// <summary>
/// Writes the <see cref="OwnHomeDataMessage"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="OwnHomeDataMessage"/>.
/// </param>
public override void WriteMessage(MessageWriter writer)
{
if (OwnAvatarData == null) // quit early just not to mess up the stream
throw new NullReferenceException("OwnAvatarData was null.");
writer.Write((int)LastVisit.TotalSeconds);
writer.Write(Unknown1); // -1
writer.Write((int)DateTimeConverter.ToUnixTimestamp(Timestamp));
OwnAvatarData.Write(writer);
}
示例9: WriteMessage
/// <summary>
/// Writes the <see cref="NewClientEncryptionMessage"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="NewClientEncryptionMessage"/>.
/// </param>
public override void WriteMessage(MessageWriter writer)
{
writer.Write(Unknown1);
writer.Write(Unknown2);
writer.Write(MajorVersion);
writer.Write(Unknown4);
writer.Write(MinorVersion);
writer.Write(Hash);
writer.Write(Unknown6);
writer.Write(Unknown7);
}
示例10: SendAllAdmins
public static void SendAllAdmins(ClientObject client)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.ADMIN_SYSTEM;
using (MessageWriter mw = new MessageWriter())
{
mw.Write((int)AdminMessageType.LIST);
mw.Write<string[]>(DarkMultiPlayerServer.AdminSystem.fetch.GetAdmins());
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, true);
}
示例11: SendConsoleMessageToClient
public static void SendConsoleMessageToClient(ClientObject client, string message)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.CHAT_MESSAGE;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)ChatMessageType.CONSOLE_MESSAGE);
mw.Write<string>(message);
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, false);
}
示例12: WriteCommand
/// <summary>
/// Writes the <see cref="MoveVillageObjectCommand"/> to the specified <see cref="MessageWriter"/>.
/// </summary>
/// <param name="writer">
/// <see cref="MessageWriter"/> that will be used to write the <see cref="MoveVillageObjectCommand"/>.
/// </param>
/// <exception cref="NullReferenceException">MovesData is null.</exception>
public override void WriteCommand(MessageWriter writer)
{
if (MovesData == null)
throw new NullReferenceException("MovesData cannot be null");
for (int i = 0; i < MovesData.Length; i++)
{
writer.Write(MovesData[i].X);
writer.Write(MovesData[i].Y);
writer.Write(MovesData[i].VillageObjectGameIndex);
}
writer.Write(Unknown1);
}
示例13: SendKerbal
private static void SendKerbal(ClientObject client, string kerbalName, byte[] kerbalData)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.KERBAL_REPLY;
using (MessageWriter mw = new MessageWriter())
{
//Send the vessel with a send time of 0 so it instantly loads on the client.
mw.Write<double>(0);
mw.Write<string>(kerbalName);
mw.Write<byte[]>(kerbalData);
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, false);
}
示例14: SendChatMessageToClient
public static void SendChatMessageToClient(ClientObject client, string messageText)
{
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.CHAT_MESSAGE;
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)ChatMessageType.PRIVATE_MESSAGE);
mw.Write<string>(Settings.settingsStore.consoleIdentifier);
mw.Write<string>(client.playerName);
mw.Write(messageText);
newMessage.data = mw.GetMessageBytes();
}
ClientHandler.SendToClient(client, newMessage, true);
}
示例15: AcquireLock
public void AcquireLock(string lockName, bool force)
{
lock (lockObject)
{
using (MessageWriter mw = new MessageWriter())
{
mw.Write<int>((int)LockMessageType.ACQUIRE);
mw.Write<string>(Settings.fetch.playerName);
mw.Write<string>(lockName);
mw.Write<bool>(force);
NetworkWorker.fetch.SendLockSystemMessage(mw.GetMessageBytes());
}
}
}