本文整理汇总了C#中Package.WriteTo方法的典型用法代码示例。如果您正苦于以下问题:C# Package.WriteTo方法的具体用法?C# Package.WriteTo怎么用?C# Package.WriteTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Package
的用法示例。
在下文中一共展示了Package.WriteTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseServerData
void ParseServerData(IProxy sender, MessageEventArgs e)
{
RawData incomingData = new RawData(e.Data);
int sequence = incomingData.ReadInt();
int inId = sequence & ~(1 << 31);
if (inId <= _lastReceivedMessageId || sequence == -1)
return;
_lastReceivedMessageId = inId;
int ack = incomingData.ReadInt();
Package<IServerCommand> package = incomingData.ReadServerPackage();
Package<IServerCommand> okPackage = new Package<IServerCommand>();
lock (_fakeServerCommands)
{
while (_fakeServerCommands.Count > 0)
okPackage.Commands.Enqueue(_fakeServerCommands.Dequeue());
}
if (OnServerPackage.Check(this, package))
{
foreach (IServerCommand cmd in package.Commands)
{
switch (cmd.Type)
{
case ServerCommand.Disconnect:
_lastReceivedMessageId = 0;
_lastSentMessageId = 0;
if (OnServerDisconnect.Check(this, (Disconnect)cmd))
okPackage.Commands.Enqueue(cmd);
break;
case ServerCommand.Layout:
if(OnServerLayout.Check(this, (Layout)cmd))
okPackage.Commands.Enqueue(cmd);
break;
case ServerCommand.ServerData:
if(OnServerData.Check(this, (ServerData)cmd))
okPackage.Commands.Enqueue(cmd);
break;
case ServerCommand.CenterPrint:
if(OnServerCenterPrint.Check(this, (CenterPrint)cmd) &&
OnServerStringPackage.Check(this, (IServerStringPackage)cmd))
okPackage.Commands.Enqueue(cmd);
break;
case ServerCommand.Print:
if(OnServerPrint.Check(this, (Print)cmd) &&
OnServerStringPackage.Check(this, (IServerStringPackage)cmd))
okPackage.Commands.Enqueue(cmd);
break;
case ServerCommand.StuffText:
if(OnServerStuffText.Check(this, (StuffText)cmd) &&
OnServerStringPackage.Check(this, (IServerStringPackage)cmd))
okPackage.Commands.Enqueue(cmd);
break;
case ServerCommand.ConfigString:
switch (((ConfigString)cmd).ConfigType)
{
case ConfigStringType.PlayerInfo:
if(OnServerPlayerInfo.Check(this, (PlayerInfo)cmd) &&
OnServerConfigString.Check(this, (PlayerInfo)cmd) &&
OnServerStringPackage.Check(this, (PlayerInfo)cmd))
okPackage.Commands.Enqueue(cmd);
break;
default:
if(OnServerConfigString.Check(this, (ConfigString)cmd) &&
OnServerStringPackage.Check(this, (ConfigString)cmd))
okPackage.Commands.Enqueue(cmd);
break;
}
break;
}
}
}
okPackage.RemainingData = package.RemainingData;
var finalServerPackage = new RawData(8 + okPackage.Size());
finalServerPackage.WriteInt(sequence);
finalServerPackage.WriteInt(ack);
okPackage.WriteTo(finalServerPackage);
e.Data = finalServerPackage.Data;
}
示例2: ParseClientData
void ParseClientData(IProxy sender, MessageEventArgs e)
{
var outcomingData = new RawData(e.Data);
int sequence = outcomingData.ReadInt();
int outId = sequence & ~(1 << 31);
if (sequence == -1)
{
string cmd = outcomingData.ReadString(' ');
if (cmd == "connect")
Protocol = (ServerData.ServerProtocol)int.Parse(outcomingData.ReadString(' '));
return;
}
if (outId <= _lastSentMessageId)
return;
int ack = outcomingData.ReadInt();
short qPort;
if (Protocol == ServerData.ServerProtocol.R1Q2)
qPort = outcomingData.ReadByte();
else
qPort = outcomingData.ReadShort();
_lastSentMessageId = outId;
Package<IClientCommand> package = outcomingData.ReadClientPackage();
Package<IClientCommand> okPackage = new Package<IClientCommand>();
lock (_fakeClientCommands)
{
while (_fakeClientCommands.Count > 0)
okPackage.Commands.Enqueue(_fakeClientCommands.Dequeue());
}
if (OnClientPackage.Check(this, package))
{
foreach (IClientCommand cmd in package.Commands)
{
switch (cmd.Type)
{
case ClientCommand.StringCmd:
if (OnClientStringCmd.Check(this, (StringCmd)cmd) &&
OnClientStringPackage.Check(this, (IClientStringPackage)cmd))
okPackage.Commands.Enqueue(cmd);
break;
case ClientCommand.UserInfo:
if (OnClientUserInfo.Check(this, (UserInfo)cmd) &&
OnClientStringPackage.Check(this, (IClientStringPackage)cmd))
okPackage.Commands.Enqueue(cmd);
break;
case ClientCommand.Setting:
if (OnClientSetting.Check(this, (Setting)cmd))
okPackage.Commands.Enqueue(cmd);
break;
default:
okPackage.Commands.Enqueue(cmd);
break;
}
}
}
okPackage.RemainingData = package.RemainingData;
var finalPackage = new RawData(8 + (Protocol == ServerData.ServerProtocol.R1Q2 ? 1 : 2) + okPackage.Size());
finalPackage.WriteInt(sequence);
finalPackage.WriteInt(ack);
if (Protocol == ServerData.ServerProtocol.R1Q2)
finalPackage.WriteByte((byte)qPort);
else
finalPackage.WriteShort(qPort);
okPackage.WriteTo(finalPackage);
e.Data = finalPackage.Data;
}