本文整理汇总了C#中MessageReader类的典型用法代码示例。如果您正苦于以下问题:C# MessageReader类的具体用法?C# MessageReader怎么用?C# MessageReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MessageReader类属于命名空间,在下文中一共展示了MessageReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleSplitMessage
public static void HandleSplitMessage(ClientObject client, byte[] messageData)
{
if (!client.isReceivingSplitMessage)
{
//New split message
using (MessageReader mr = new MessageReader(messageData))
{
client.receiveSplitMessage = new ClientMessage();
client.receiveSplitMessage.type = (ClientMessageType)mr.Read<int>();
client.receiveSplitMessage.data = new byte[mr.Read<int>()];
client.receiveSplitMessageBytesLeft = client.receiveSplitMessage.data.Length;
byte[] firstSplitData = mr.Read<byte[]>();
firstSplitData.CopyTo(client.receiveSplitMessage.data, 0);
client.receiveSplitMessageBytesLeft -= firstSplitData.Length;
}
client.isReceivingSplitMessage = true;
}
else
{
//Continued split message
messageData.CopyTo(client.receiveSplitMessage.data, client.receiveSplitMessage.data.Length - client.receiveSplitMessageBytesLeft);
client.receiveSplitMessageBytesLeft -= messageData.Length;
}
if (client.receiveSplitMessageBytesLeft == 0)
{
ClientHandler.HandleMessage(client, client.receiveSplitMessage);
client.receiveSplitMessage = null;
client.isReceivingSplitMessage = false;
}
}
示例2: HandleAdminMessage
public void HandleAdminMessage(byte[] messageData)
{
using (MessageReader mr = new MessageReader(messageData))
{
AdminMessageType messageType = (AdminMessageType)mr.Read<int>();
switch (messageType)
{
case AdminMessageType.LIST:
{
string[] adminNames = mr.Read<string[]>();
foreach (string adminName in adminNames)
{
RegisterServerAdmin(adminName);
}
}
break;
case AdminMessageType.ADD:
{
string adminName = mr.Read<string>();
RegisterServerAdmin(adminName);
}
break;
case AdminMessageType.REMOVE:
{
string adminName = mr.Read<string>();
UnregisterServerAdmin(adminName);
}
break;
}
}
}
示例3: PrintMessage
internal static void PrintMessage(Message msg)
{
Console.WriteLine ("Message (" + msg.Header.Endianness + " endian, v" + msg.Header.MajorVersion + "):");
Console.WriteLine (indent + "Type: " + msg.Header.MessageType);
Console.WriteLine (indent + "Flags: " + msg.Header.Flags);
Console.WriteLine (indent + "Serial: " + msg.Header.Serial);
//foreach (HeaderField hf in msg.HeaderFields)
// Console.WriteLine (indent + hf.Code + ": " + hf.Value);
Console.WriteLine (indent + "Header Fields:");
foreach (KeyValuePair<FieldCode,object> field in msg.Header.Fields)
Console.WriteLine (indent + indent + field.Key + ": " + field.Value);
Console.WriteLine (indent + "Body (" + msg.Header.Length + " bytes):");
if (msg.Body != null) {
MessageReader reader = new MessageReader (msg);
//TODO: this needs to be done more intelligently
//TODO: number the args
try {
foreach (DType dtype in msg.Signature.GetBuffer ()) {
if (dtype == DType.Invalid)
continue;
object arg = reader.ReadValue (dtype);
Console.WriteLine (indent + indent + dtype + ": " + arg);
}
} catch {
Console.WriteLine (indent + indent + "monitor is too dumb to decode message body");
}
}
}
示例4: ReadGroup
static UnknownFieldCollection ReadGroup(MessageTag startTag, MessageReader reader)
{
var group = new UnknownFieldCollection();
for(int stop = startTag.WithWireType(WireType.EndGroup), tag = reader.ReadInt32(); tag != stop; tag = reader.ReadInt32())
group.Add(new MessageTag(tag), reader);
return group;
}
示例5: HandleMessage
public void HandleMessage(byte[] messageData)
{
using (MessageReader mr = new MessageReader(messageData))
{
FlagMessageType messageType = (FlagMessageType)mr.Read<int>();
switch (messageType)
{
case FlagMessageType.LIST:
{
//List code
string[] serverFlagFiles = mr.Read<string[]>();
string[] serverFlagOwners = mr.Read<string[]>();
string[] serverFlagShaSums = mr.Read<string[]>();
for (int i = 0; i < serverFlagFiles.Length; i++)
{
FlagInfo fi = new FlagInfo();
fi.owner = serverFlagOwners[i];
fi.shaSum = serverFlagShaSums[i];
serverFlags[Path.GetFileNameWithoutExtension(serverFlagFiles[i])] = fi;
}
syncComplete = true;
//Check if we need to upload the flag
flagChangeEvent = true;
}
break;
case FlagMessageType.FLAG_DATA:
{
FlagRespondMessage frm = new FlagRespondMessage();
frm.flagInfo.owner = mr.Read<string>();
frm.flagName = mr.Read<string>();
frm.flagData = mr.Read<byte[]>();
frm.flagInfo.shaSum = Common.CalculateSHA256Hash(frm.flagData);
newFlags.Enqueue(frm);
}
break;
case FlagMessageType.DELETE_FILE:
{
string flagName = mr.Read<string>();
string flagFile = Path.Combine(flagPath, flagName);
if (File.Exists(flagFile))
{
try
{
if (File.Exists(flagFile))
{
DarkLog.Debug("Deleting flag " + flagFile);
File.Delete(flagFile);
}
}
catch (Exception e)
{
DarkLog.Debug("Error deleting flag " + flagFile + ", exception: " + e);
}
}
}
break;
}
}
}
示例6: HandleVesselsRequest
public static void HandleVesselsRequest(ClientObject client, byte[] messageData)
{
using (MessageReader mr = new MessageReader(messageData))
{
int sendVesselCount = 0;
int cachedVesselCount = 0;
List<string> clientRequested = new List<string>(mr.Read<string[]>());
lock (Server.universeSizeLock)
{
foreach (string file in Directory.GetFiles(Path.Combine(Server.universeDirectory, "Vessels")))
{
string vesselID = Path.GetFileNameWithoutExtension(file);
byte[] vesselData = File.ReadAllBytes(file);
string vesselObject = Common.CalculateSHA256Hash(vesselData);
if (clientRequested.Contains(vesselObject))
{
sendVesselCount++;
VesselProto.SendVessel(client, vesselID, vesselData);
}
else
{
cachedVesselCount++;
}
}
}
DarkLog.Debug("Sending " + client.playerName + " " + sendVesselCount + " vessels, cached: " + cachedVesselCount + "...");
SendVesselsComplete(client);
}
}
示例7: HandleVesselRemoval
public static void HandleVesselRemoval(ClientObject client, byte[] messageData)
{
using (MessageReader mr = new MessageReader(messageData))
{
//Don't care about the subspace on the server.
mr.Read<double>();
string vesselID = mr.Read<string>();
bool isDockingUpdate = mr.Read<bool>();
if (!isDockingUpdate)
{
DarkLog.Debug("Removing vessel " + vesselID + " from " + client.playerName);
}
else
{
DarkLog.Debug("Removing DOCKED vessel " + vesselID + " from " + client.playerName);
}
if (File.Exists(Path.Combine(Server.universeDirectory, "Vessels", vesselID + ".txt")))
{
lock (Server.universeSizeLock)
{
File.Delete(Path.Combine(Server.universeDirectory, "Vessels", vesselID + ".txt"));
}
}
//Relay the message.
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.VESSEL_REMOVE;
newMessage.data = messageData;
ClientHandler.SendToAll(client, newMessage, false);
}
}
示例8: HandlePlayerColor
public static void HandlePlayerColor(ClientObject client, byte[] messageData)
{
using (MessageReader mr = new MessageReader(messageData))
{
PlayerColorMessageType messageType = (PlayerColorMessageType)mr.Read<int>();
switch (messageType)
{
case PlayerColorMessageType.SET:
{
string playerName = mr.Read<string>();
if (playerName != client.playerName)
{
DarkLog.Debug(client.playerName + " tried to send a color update for " + playerName + ", kicking.");
Messages.ConnectionEnd.SendConnectionEnd(client, "Kicked for sending a color update for another player");
return;
}
client.playerColor = mr.Read<float[]>();
//Relay the message
ServerMessage newMessage = new ServerMessage();
newMessage.type = ServerMessageType.PLAYER_COLOR;
newMessage.data = messageData;
ClientHandler.SendToAll(client, newMessage, true);
}
break;
}
}
}
示例9: ExecuteRequest
public async Task<Response> ExecuteRequest(Request request)
{
if (!_tcpClient.Connected)
{
throw new InvalidOperationException("Connect first.");
}
var converter = new MessageConverter();
var requestBuffer = new MemoryStream();
var streamWriter = new HmBinaryMessageWriter(requestBuffer);
var requestReader = new MessageReader(request);
converter.Convert(requestReader, streamWriter);
var networkStream = _tcpClient.GetStream();
requestBuffer.Position = 0;
await requestBuffer.CopyToAsync(networkStream);
await Task.Delay(100);
//todo: implement buffered reader
var streamReader = new HmBinaryMessageReader(networkStream);
var responseBuilder = new MessageBuilder();
converter.Convert(streamReader, responseBuilder);
var response = (Response)responseBuilder.Result;
return response;
}
示例10: HandleWarpControl
public static void HandleWarpControl(ClientObject client, byte[] messageData)
{
using (MessageReader mr = new MessageReader(messageData))
{
WarpMessageType warpType = (WarpMessageType)mr.Read<int>();
switch (warpType)
{
case WarpMessageType.REQUEST_CONTROLLER:
{
HandleRequestController(client);
}
break;
case WarpMessageType.RELEASE_CONTROLLER:
{
HandleReleaseController(client);
}
break;
case WarpMessageType.REPLY_VOTE:
{
bool voteReply = mr.Read<bool>();
HandleReplyVote(client, voteReply);
}
break;
case WarpMessageType.NEW_SUBSPACE:
{
long serverTime = mr.Read<long>();
double planetTime = mr.Read<double>();
float subspaceRate = mr.Read<float>();
HandleNewSubspace(client, serverTime, planetTime, subspaceRate);
}
break;
case WarpMessageType.CHANGE_SUBSPACE:
{
int newSubspace = mr.Read<int>();
HandleChangeSubspace(client, newSubspace);
}
break;
case WarpMessageType.REPORT_RATE:
{
float newSubspaceRate = mr.Read<float>();
HandleReportRate(client, newSubspaceRate);
}
break;
case WarpMessageType.CHANGE_WARP:
{
bool physWarp = mr.Read<bool>();
int rateIndex = mr.Read<int>();
long serverClock = mr.Read<long>();
double planetTime = mr.Read<double>();
HandleChangeWarp(client, physWarp, rateIndex, serverClock, planetTime);
}
break;
#if DEBUG
default:
throw new NotImplementedException("Warp type not implemented");
#endif
}
}
}
示例11: ToType
public object ToType (Type conversionType, IFormatProvider provider)
{
Signature typeSig = Signature.GetSig (conversionType);
if (typeSig != signature)
throw new InvalidCastException ();
MessageReader reader = new MessageReader (endianness, data);
return reader.ReadValue (conversionType);
}
示例12: ReadCommand
/// <summary>
/// Reads the <see cref="MoveVillageObjectCommand"/> from the specified <see cref="MessageReader"/>.
/// </summary>
/// <param name="reader">
/// <see cref="MessageReader"/> that will be used to read the <see cref="MoveVillageObjectCommand"/>.
/// </param>
public override void ReadCommand(MessageReader reader)
{
MoveData = new MoveVillageObjectData();
MoveData.X = reader.ReadInt32();
MoveData.Y = reader.ReadInt32();
MoveData.VillageObjectGameIndex = reader.ReadInt32();
Unknown1 = reader.ReadInt32();
}
示例13: ReadMessage
/// <summary>
/// Reads the <see cref="OwnHomeDataMessage"/> from the specified <see cref="MessageReader"/>.
/// </summary>
/// <param name="reader">
/// <see cref="MessageReader"/> that will be used to read the <see cref="OwnHomeDataMessage"/>.
/// </param>
public override void ReadMessage(MessageReader reader)
{
LastVisit = TimeSpan.FromSeconds(reader.ReadInt32());
Unknown1 = reader.ReadInt32(); // -1
Timestamp = DateTimeConverter.FromUnixTimestamp(reader.ReadInt32());
OwnAvatarData = new AvatarData();
OwnAvatarData.Read(reader);
}
示例14: ReadCommand
/// <summary>
/// Reads the <see cref="ClearObstacleCommand"/> from the specified <see cref="MessageReader"/>.
/// </summary>
/// <param name="reader">
/// <see cref="MessageReader"/> that will be used to read the <see cref="ClearObstacleCommand"/>.
/// </param>
public override void ReadCommand(MessageReader reader)
{
var gameID = reader.ReadInt32();
if (!Obstacle.ValidGameID(gameID))
throw new InvalidCommandException("Unexpected game ID: " + gameID, this);
ObstacleGameIndex = Obstacle.GameIDToIndex(gameID);
Unknown1 = reader.ReadInt32();
}
示例15: HandleConnectionEnd
public static void HandleConnectionEnd(ClientObject client, byte[] messageData)
{
string reason = "Unknown";
using (MessageReader mr = new MessageReader(messageData))
{
reason = mr.Read<string>();
}
DarkLog.Debug(client.playerName + " sent connection end message, reason: " + reason);
ClientHandler.DisconnectClient(client);
}