本文整理汇总了C#中Lidgren.Network.NetBuffer.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer.ReadByte方法的具体用法?C# NetBuffer.ReadByte怎么用?C# NetBuffer.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBuffer
的用法示例。
在下文中一共展示了NetBuffer.ReadByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleMessage
private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
{
switch (type)
{
case NetMessageType.DebugMessage:
WriteToConsole(buffer.ReadString());
break;
case NetMessageType.StatusChanged:
WriteToConsole("New status: " + source.Status + " (" + buffer.ReadString() + ")");
UpdateStatisticsDisplay(source);
break;
case NetMessageType.Data:
//System.IO.File.AppendAllText("C:\\receivedpackets.txt", s_userMessagesReceived.ToString() + ": " + msg.ReadString() + " (" + msg.m_sequenceNumber + ")" + Environment.NewLine);
s_userMessagesReceived++;
// simulate some processing of the message here
for (int i = 0; i < buffer.LengthBytes - 2; i++)
buffer.ReadByte();
// check checksum
ushort checksum = NetChecksum.Adler16(buffer.Data, 0, buffer.LengthBytes - 2);
ushort given = buffer.ReadUInt16();
if (checksum != given)
WriteToConsole("Wrong checksum! Expected " + checksum + " found given " + given);
double b = s_userMessagesReceived;
for (int i = 0; i < 1000; i++)
b += Math.Sqrt((double)i) / Math.Sin(s_tmp);
s_tmp += b / 10000.0;
break;
default:
break;
}
}
示例2: StatusChangeHandler
public static void StatusChangeHandler(NetClient client, NetBuffer buffer)
{
string status_msg = buffer.ReadString();
NetConnectionStatus status = (NetConnectionStatus)buffer.ReadByte();
if (status == NetConnectionStatus.Connected)
{
Console.WriteLine("Client: Connected");
Console.Write("Client: Starting IOS");
int i;
for (i = 0; i < 10; i++)
{
Console.Write(".");
Thread.Sleep(500);
}
Console.WriteLine("");
//Show the IOS Master form
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);
System.Windows.Forms.Application.Run(new MasterForm());
}
if (status == NetConnectionStatus.Disconnected)
{
Console.WriteLine("Client: Disconnected - " + status_msg);
}
}
示例3: ReadStringTable
internal string ReadStringTable(NetBuffer buffer)
{
byte b = buffer.ReadByte();
bool stringFollows = ((b & 1) == 0);
bool shortVal = ((b & 2) == 0);
int val = 0;
if (shortVal)
val = b >> 2;
else
val = ((b & (255 << 2)) << 6) | buffer.ReadByte();
string retval = string.Empty;
if (stringFollows)
{
retval = buffer.ReadString();
m_stringTable[retval] = val;
m_stringTableLookUp[val] = retval;
//
// Send confirmation
//
NetBuffer buf = new NetBuffer(2);
buf.Write((ushort)val);
m_owner.QueueSingleUnreliableSystemMessage(
NetSystemType.StringTableAck,
buf,
m_remoteEndPoint,
false
);
return retval;
}
if (!m_stringTableLookUp.TryGetValue(val, out retval))
{
// Ack! Failed to find string table value!
throw new Exception("ACK!");
}
return retval;
}
示例4: Read
public void Read(NetBuffer im)
{
PluginName = im.ReadString();
MethodName = im.ReadString();
RspType = im.ReadByte();
if (RspType == StringDataType)
{
StringCommandRsp = im.ReadString();
}
else if (RspType == BinaryDataType)
{
int l = im.ReadInt32();
BinaryCommandRsp = im.ReadBytes(l);
}
}
示例5: ReadFrom
/// <summary>
/// Read this message from the packet buffer
/// </summary>
/// <returns>new read pointer position</returns>
internal void ReadFrom(NetBuffer buffer, IPEndPoint endpoint)
{
m_senderEndPoint = endpoint;
// read header
byte header = buffer.ReadByte();
m_type = (NetMessageLibraryType)(header & 7);
m_sequenceChannel = (NetChannel)(header >> 3);
m_sequenceNumber = buffer.ReadUInt16();
int payLen = (int)buffer.ReadVariableUInt32();
// copy payload into message buffer
m_data.EnsureBufferSize(payLen * 8);
buffer.ReadBytes(m_data.Data, 0, payLen);
m_data.Reset(0, payLen * 8);
return;
}
示例6: ParseGameState
void ParseGameState(NetBuffer msg)
{
clc.connectPacketCount = 0;
// wipe local client state
ClearState();
// a gamestate always marks a server command sequence
clc.serverCommandSequence = msg.ReadInt32();
// parse all the configstrings and baselines
while (true)
{
int cmd = msg.ReadByte();
if (cmd == (int)svc_ops_e.svc_EOF)
break;
if (cmd == (int)svc_ops_e.svc_configstring)
{
int index = msg.ReadInt16();
string s = msg.ReadString();
cl.gamestate.data.Add(index, s);
}
else if (cmd == (int)svc_ops_e.svc_baseline)
{
int newnum = msg.ReadInt32();
if (newnum < 0 || newnum >= 1024)
{
Common.Instance.Error("ParseGameState: Baseline number out of range: " + newnum);
}
Common.entityState_t nullstate = new Common.entityState_t();
Net.Instance.MSG_ReadDeltaEntity(msg, ref nullstate, ref cl.entityBaselines[newnum], newnum);
}
else
{
Common.Instance.Error("ParseGameState: bad command byte");
}
}
clc.clientNum = msg.ReadInt32();
// parse useful values out of CS_SERVERINFO
//ParseServerInfo();
// parse serverId and other cvars
SystemInfoChanged();
InitDownloads();
}
示例7: ParseSnapshot
/*
================
CL_ParseSnapshot
If the snapshot is parsed properly, it will be copied to
cl.snap and saved in cl.snapshots[]. If the snapshot is invalid
for any reason, no changes to the state will be made at all.
================
*/
void ParseSnapshot(NetBuffer msg)
{
// read in the new snapshot to a temporary buffer
// we will only copy to cl.snap if it is valid
clSnapshot_t newsnap = new clSnapshot_t();
clSnapshot_t old;
// we will have read any new server commands in this
// message before we got to svc_snapshot
newsnap.ServerCommandNum = clc.serverCommandSequence;
newsnap.serverTime = msg.ReadInt32();
newsnap.messageNum = clc.serverMessageSequence;
int deltaNum = msg.ReadByte();
if (deltaNum <= 0)
{
newsnap.deltaNum = -1;
}
else
newsnap.deltaNum = newsnap.messageNum - deltaNum;
newsnap.snapFlags = msg.ReadByte();
// If the frame is delta compressed from data that we
// no longer have available, we must suck up the rest of
// the frame, but not use it, then ask for a non-compressed
// message
if (newsnap.deltaNum <= 0)
{
newsnap.valid = true; // uncompressed frame
old = null;
}
else
{
old = cl.snapshots[newsnap.deltaNum & 31];
if (!old.valid)
{
// should never happen
Common.Instance.WriteLine("ParseSnapshot: Delta from invalid frame (not supposed to happen!).");
}
else if (old.messageNum != newsnap.deltaNum)
{
// The frame that the server did the delta from
// is too old, so we can't reconstruct it properly.
Common.Instance.WriteLine("ParseSnapshot: Delta frame too old.");
}
else if (cl.parseEntitiesNum - old.parseEntitiesNum > 2048 - 128)
{
Common.Instance.WriteLine("ParseSnapshot: Delta parseEntitiesNum too old");
}
else
newsnap.valid = true; // valid delta parse
}
// read areamask
int len = msg.ReadByte();
newsnap.areamask = msg.ReadBytes(32);
// read playerinfo
if (old != null)
{
Net.ReadDeltaPlayerstate(msg, old.ps, newsnap.ps);
}
else
Net.ReadDeltaPlayerstate(msg, null, newsnap.ps);
// read packet entities
ParsePacketEntities(msg, old, newsnap);
// if not valid, dump the entire thing now that it has
// been properly read
if (!newsnap.valid)
return;
// clear the valid flags of any snapshots between the last
// received and this one, so if there was a dropped packet
// it won't look like something valid to delta from next
// time we wrap around in the buffer
int oldMessageNum = cl.snap.messageNum + 1;
if (newsnap.messageNum - oldMessageNum >= 32)
{
oldMessageNum = newsnap.messageNum - 31;
}
for (; oldMessageNum < newsnap.messageNum; oldMessageNum++ )
{
cl.snapshots[oldMessageNum & 31].valid = false;
}
// copy to the current good spot
cl.snap = newsnap;
cl.snap.ping = 999;
// calculate ping time
//.........这里部分代码省略.........
示例8: UserMove
/*
==================
SV_UserMove
The message usually contains all the movement commands
that were in the last three packets, so that the information
in dropped packets can be recovered.
On very fast clients, there may be multiple usercmd packed into
each of the backup packets.
==================
*/
void UserMove(client_t cl, NetBuffer buf, bool deltaCompressed)
{
if (deltaCompressed)
cl.deltaMessage = cl.messageAcknowledge;
else
cl.deltaMessage = -1;
int cmdCount = buf.ReadByte();
if (cmdCount < 1)
{
Common.Instance.WriteLine("cmdCount < 1");
return;
}
if (cmdCount > 32)
{
Common.Instance.WriteLine("cmdCount > 32");
return;
}
List<Input.UserCommand> cmds = new List<Input.UserCommand>();
Input.UserCommand oldcmd = new Input.UserCommand();
for (int i = 0; i < cmdCount; i++)
{
Input.UserCommand cmd = Input.Instance.MSG_ReadDeltaUsercmdKey(buf, ref oldcmd);
cmds.Add(cmd);
oldcmd = cmd;
}
// save time for ping calculation
cl.frames[cl.messageAcknowledge & 31].messageAcked = (int)time;
// if this is the first usercmd we have received
// this gamestate, put the client into the world
if (cl.state == clientState_t.CS_PRIMED)
{
ClientEnterWorld(cl, cmds[cmds.Count-1]);
// the moves can be processed normaly
}
if (cl.state != clientState_t.CS_ACTIVE)
{
cl.deltaMessage = -1;
return;
}
// usually, the first couple commands will be duplicates
// of ones we have previously received, but the servertimes
// in the commands will cause them to be immediately discarded
for (int i = 0; i < cmdCount; i++)
{
// if this is a cmd from before a map_restart ignore it
if (cmds[i].serverTime > cmds[cmdCount - 1].serverTime)
{
continue;
}
// don't execute if this is an old cmd which is already executed
// these old cmds are included when cl_packetdup > 0
if (cmds[i].serverTime <= cl.lastUsercmd.serverTime)
{
continue;
}
ClientThink(cl, cmds[i]);
}
}
示例9: CommandImplementation
public CommandImplementation(GameState game, NetBuffer buffer)
{
this.game = game;
var time = new Instant(buffer.ReadDouble());
this.game.SetTime(time);
int count = buffer.ReadByte();
this.parameters = new List<SingleParameters>(count);
for (int i = 0; i < count; i++)
{
this.parameters.Add(buffer.Read<SingleParameters>());
}
}
示例10: PlayerData
public PlayerData(NetBuffer msg) : this()
{
ID = msg.ReadUInt64();
Position = new Vec2(msg.ReadFloat(), msg.ReadFloat());
Type = (ChampionTypes)msg.ReadByte();
Team = msg.ReadBoolean() ? Teams.Left : Teams.Right;
MaxHealth = msg.ReadFloat();
Health = msg.ReadFloat();
}
示例11: ReadFieldState
protected void ReadFieldState(NetBuffer buffer)
{
// bricks & powerups
FieldCellSlot[] slots = game.Field.GetCells().slots;
for (int i = 0; i < slots.Length; ++i)
{
BrickCell brick = slots[i].GetBrick();
if (brick != null)
{
bool hasPowerup = buffer.ReadBoolean();
if (hasPowerup)
{
brick.powerup = buffer.ReadByte();
}
}
}
// players
int senderIndex = buffer.ReadByte();
int playersCount = buffer.ReadByte();
for (int i = 0; i < playersCount; ++i)
{
Player player = new Player(i);
int cx = buffer.ReadByte();
int cy = buffer.ReadByte();
player.SetCell(cx, cy);
if (i != senderIndex)
{
player.SetPlayerInput(new PlayerNetworkInput());
}
game.AddPlayer(player);
}
}
示例12: ParameterGroup
public ParameterGroup(NetBuffer buffer)
{
this.id = buffer.Read<Id>().Generic<Player>();
int count = buffer.ReadByte();
this.values = new List<ValueParameters>(count);
for (int i = 0; i < count; i++)
{
this.values.Add(buffer.Read<ValueParameters>());
}
}
示例13: CommandImplementation
public CommandImplementation(GameState game, NetBuffer buffer)
{
this.game = game;
var time = new Instant(buffer.ReadDouble());
int count = buffer.ReadByte();
this.parameters = new List<ParameterGroup>(count);
for (int i = 0; i < count; i++)
{
this.parameters.Add(new ParameterGroup(buffer));
}
}
示例14: HandleMessage
private static void HandleMessage(NetMessageType type, NetBuffer data)
{
switch (type)
{
case NetMessageType.DebugMessage:
WriteToConsole(data.ReadString());
break;
case NetMessageType.StatusChanged:
string statusMessage = data.ReadString();
NetConnectionStatus newStatus = (NetConnectionStatus)data.ReadByte();
WriteToConsole("New status: " + newStatus + " (" + statusMessage + ")");
UpdateStatisticsDisplay(s_client.ServerConnection);
break;
case NetMessageType.Data:
WriteToConsole("Message received: " + data);
break;
default:
WriteToConsole("Unhandled: " + type);
break;
}
}
示例15: Read
public void Read(NetBuffer im)
{
ConnectionType = im.ReadByte();
}