本文整理汇总了C#中Lidgren.Network.NetIncomingMessage.PeekByte方法的典型用法代码示例。如果您正苦于以下问题:C# NetIncomingMessage.PeekByte方法的具体用法?C# NetIncomingMessage.PeekByte怎么用?C# NetIncomingMessage.PeekByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetIncomingMessage
的用法示例。
在下文中一共展示了NetIncomingMessage.PeekByte方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HandleMessage
public static Packet HandleMessage(NetIncomingMessage msg)
{
byte header = msg.PeekByte();
Console.WriteLine(header);
Packet p = GetPacket(msg.PeekByte());
p.Decode(msg);
return p;
}
示例2: ReadPacket
private void ReadPacket(NetIncomingMessage msg)
{
switch (msg.PeekByte ()) {
case Packet.CLIENTINFO:
ClientInfo ci = ClientInfo.decode (ref msg);
if(clientId == - 1){
clientId = ci.ClientId;
}
else if (ci.ClientId != clientId ){
if(otherClients.ContainsKey(ci.ClientId)){
NetworkClient c = otherClients[ci.ClientId];
c.Pseudo = ci.Pseudo;
c.Player.Color = ci.Color;
}
else
{
NetworkClient newClient = new NetworkClient(ci.ClientId, null);
newClient.Player = new Player(map, imageManager);
newClient.Player.Color = ci.Color;
newClient.Pseudo = ci.Pseudo;
map.AddPlayer(newClient.Player);
otherClients.Add(newClient.ClientId, newClient);
}
}
break;
case Packet.USERMESSAGE:
UserMessage uMsg = UserMessage.decode(ref msg);
if(uMsg.ClientId == clientId){
uMsgBuffer.clientCorrection(player, uMsg);
}
else
{
if(otherClients.ContainsKey(uMsg.ClientId)){
NetworkClient c = otherClients[uMsg.ClientId];
c.Player.LookAt(uMsg.EyePosition);
c.Player.Layer = uMsg.Layer;
if(VectorUtils.Distance(c.Player.Position, uMsg.Position) > 1){
c.Player.Position = uMsg.Position;
}
else
c.Player.Position += (c.Player.Position - uMsg.Position) * 0.1F;
return;
}
}
break;
case Packet.BLOCKUPDATE:
BlockUpdate bu = BlockUpdate.decode(ref msg);
if(bu.Added)
map.ForceAddCube(bu.Position, bu.BlockType, bu.Layer);
else
map.DeleteCube(bu.Position, bu.Layer);
break;
case Packet.CLIENTDISCONNECT:
ClientDisconnect cd = ClientDisconnect.decode(ref msg);
if(otherClients.ContainsKey(cd.ClientId)){
NetworkClient c = otherClients[cd.ClientId];
otherClients.Remove(c.ClientId);
map.DeletePlayer(c.Player);
}
break;
case Packet.CHATMESSAGE:
ChatMessage cm = ChatMessage.decode(ref msg);
chat.addMsg(cm.Pseudo +": " + cm.Message);
break;
default:
break;
}
}
示例3: HandleDataPacket
/// <summary>
/// Handles a single incoming data packet from a client.
/// </summary>
/// <param name="msg">The packet to handle.</param>
private void HandleDataPacket( NetIncomingMessage msg )
{
MsgType type = (MsgType)msg.PeekByte();
switch ( type )
{
case MsgType.Debug:
msg.ReadByte();
string output = "[Dbg Msg From " + NetUtility.ToHexString( msg.SenderConnection.RemoteUniqueIdentifier ) + "]: "
+ msg.ReadString();
WriteConsoleMessage( output );
break;
case MsgType.ReqLobbyList:
SendLobbyList( msg.SenderConnection );
break;
case MsgType.ReqJoinLobby:
msg.ReadByte();
int lobbyID = msg.ReadByte();
string playerName = msg.ReadString();
MsgErrorCode err;
if ( ! AddPlayerToLobby( msg.SenderConnection, lobbyID, playerName, out err ) )
{
NetOutgoingMessage errMsg = server.CreateMessage();
errMsg.Write( (byte)MsgType.Error );
errMsg.Write( (byte)err );
server.SendMessage( errMsg, msg.SenderConnection, NetDeliveryMethod.Unreliable );
}
else
{
playerLobbies[msg.SenderConnection.RemoteUniqueIdentifier] = lobbyID;
}
break;
case MsgType.ReqLeaveLobby:
if ( playerLobbies.ContainsKey( msg.SenderConnection.RemoteUniqueIdentifier ) )
{
int playerLobby = playerLobbies[msg.SenderConnection.RemoteUniqueIdentifier];
if ( playerLobby != NO_LOBBY )
{
lock ( lobbyLock )
{
lobbies[playerLobby].RemovePlayer( msg.SenderConnection );
}
}
}
break;
case MsgType.ReqCreateLobby:
msg.ReadByte();
string lName = msg.ReadString();
int maxCap = msg.ReadInt32();
double matchDur = msg.ReadDouble();
string pName = msg.ReadString();
ServiceLobbyCreateRequest( msg.SenderConnection, lName, pName, maxCap, matchDur );
break;
default:
int pLobby = playerLobbies[msg.SenderConnection.RemoteUniqueIdentifier];
if ( pLobby != NO_LOBBY )
{
lobbies[pLobby].messageQueue.Enqueue( msg );
}
break;
}
}
示例4: HandleDataPacket
private void HandleDataPacket( NetIncomingMessage msg )
{
MsgType type = (MsgType)msg.PeekByte();
switch ( type )
{
case MsgType.Debug:
msg.ReadByte();
string output = "[Dbg Msg From Server]: " + msg.ReadString();
System.Console.WriteLine( output );
break;
default:
int numReceivers = packetReceivers.Count;
for ( int i = 0; i < numReceivers; ++i )
{
packetReceivers[i].ReceivePacket( msg );
msg.Position = 0; // Reset the message for the next guy
}
break;
}
}
示例5: Act
public void Act()
{
double time = sw.ElapsedMilliseconds / timeDivider;
sw.Reset(); // reset the timer (change current time to 0)
sw.Start();
OutStrCmd = String.Empty;
if (TimerWait.ElapsedMilliseconds / 1000 > 10)
{
AnalyzeMsg();
TimerWait.Reset();
DG = false;
}
while ((inMsg = server.ReadMessage()) != null)
{
switch (inMsg.MessageType)
{
case NetIncomingMessageType.Data:
AnalyzeMsg();
break;
case NetIncomingMessageType.StatusChanged:
if (((NetConnectionStatus)(inMsg.PeekByte())).ToString() != "RespondedConnect" &&
((NetConnectionStatus)(inMsg.PeekByte())).ToString() != "Connected")
{
Console.WriteLine(((NetConnectionStatus)(inMsg.ReadByte())).ToString());
Console.ReadLine();
}
break;
}
server.Recycle(inMsg);
}
UpdateUnits(time);
}
示例6: ReadPacket
public void ReadPacket(NetIncomingMessage msg)
{
switch (msg.PeekByte()) {
case Packet.CLIENTINFO:
if (clientList.ContainsKey(msg.SenderConnection)) {
NetworkClient c = clientList[msg.SenderConnection];
ClientInfo ci = ClientInfo.decode(ref msg);
Console.WriteLine("Client " + c.Pseudo + " changed pseudo for " + ci.Pseudo);
c.Pseudo = ci.Pseudo;
c.Player.Color = ci.Color;
SendPktToAll(ci);
}
break;
case Packet.USERMESSAGE:
UserMessage uMsg = UserMessage.decode(ref msg);
if (clientList.ContainsKey(msg.SenderConnection)) {
NetworkClient c = clientList[msg.SenderConnection];
c.Player.Layer = uMsg.Layer;
c.Player.Noclip = uMsg.Nolcip;
c.Player.Update((float)(uMsg.Time - c.LastUpdate).TotalSeconds, uMsg.Input);
c.LastUpdate = uMsg.Time;
uMsg.Position = c.Player.Position;
SendPktToAll(uMsg, true);
}
break;
case Packet.BLOCKUPDATE:
BlockUpdate bu = BlockUpdate.decode(ref msg);
if ((bu.Added && map.AddCube(bu.Position, bu.BlockType, bu.Layer)) || !bu.Added) {
SendPktToAll(bu);
}
if (!bu.Added)
map.DeleteCube(bu.Position, bu.Layer);
break;
case Packet.CLIENTRESET:
if (clientList.ContainsKey(msg.SenderConnection)) {
NetworkClient c = clientList[msg.SenderConnection];
c.Player.Reset();
}
break;
case Packet.CHATMESSAGE:
ChatMessage cm = ChatMessage.decode(ref msg);
SendPktToAll(cm, true);
Console.WriteLine(cm.Pseudo + ": " + cm.Message);
break;
default:
Console.WriteLine("Unsupported packet recieved");
break;
}
}