本文整理汇总了C#中Lidgren.Network.NetBuffer.ReadString方法的典型用法代码示例。如果您正苦于以下问题:C# NetBuffer.ReadString方法的具体用法?C# NetBuffer.ReadString怎么用?C# NetBuffer.ReadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetBuffer
的用法示例。
在下文中一共展示了NetBuffer.ReadString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: receive
private void receive()
{
NetBuffer buffer = new NetBuffer();
bool keepGoing = true;
while (keepGoing)
{
NetIncomingMessage message;
while ((message = client.ReadMessage()) != null)
{
switch (message.MessageType)
{
case NetIncomingMessageType.DebugMessage:
Console.WriteLine(buffer.ReadString());
break;
case NetIncomingMessageType.StatusChanged:
Console.WriteLine("New status: " + client.Status + " (Reason: " + buffer.ReadString() + ")");
if(client.Status != NetPeerStatus.Running)
{
keepGoing = false;
break;
}
break;
case NetIncomingMessageType.Data:
// Handle data in buffer here
break;
}
}
}
}
示例2: 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;
}
}
示例3: HandleMessage
private static void HandleMessage(NetMessageType type, NetConnection source, NetBuffer buffer)
{
switch (type)
{
case NetMessageType.StatusChanged:
if (source.LocalHailData == null)
source.LocalHailData = Encoding.ASCII.GetBytes("Hi; I'm " + s_peer.GetHashCode());
if (source.RemoteHailData != null)
WriteToConsole("New status: " + source.Status + " - remote hail is: " + Encoding.ASCII.GetString(source.RemoteHailData));
else
WriteToConsole("New status: " + source.Status + " - remote hail is null");
break;
case NetMessageType.DebugMessage:
case NetMessageType.VerboseDebugMessage:
case NetMessageType.BadMessageReceived:
case NetMessageType.ConnectionRejected:
WriteToConsole(buffer.ReadString());
break;
case NetMessageType.Data:
WriteToConsole(source.RemoteEndpoint + " writes: " + buffer.ReadString());
break;
case NetMessageType.ServerDiscovered:
// discovered another peer!
s_peer.Connect(buffer.ReadIPEndPoint(), Encoding.ASCII.GetBytes("Hi; I'm " + s_peer.GetHashCode()));
break;
default:
// unhandled
break;
}
}
示例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: 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);
}
}
示例6: Process
public static void Process(NetServer server, NetBuffer buffer, NetConnection sender)
{
Config config = Config.Instance;
List<NetConnection> connections = server.Connections;
//Lets send that message onto any plugin clients
foreach (NetConnection connection in connections)
{
if (config.Server.client_connections.ContainsKey(connection.RemoteEndpoint.ToString()))
{
string client_type = (string)config.Server.client_connections[connection.RemoteEndpoint.ToString()];
if (client_type.ToLower() == "plugin")
{
string msg = buffer.ReadString();
Console.WriteLine("Slave: Data sent - " + msg);
NetBuffer slavebuf = server.CreateBuffer();
slavebuf.Write(msg);
server.SendMessage(slavebuf, connection, NetChannel.ReliableInOrder4);
}
}
}
}
示例7: ClientCommand
bool ClientCommand(client_t cl, NetBuffer msg)
{
int seq = msg.ReadInt32();
string s = msg.ReadString();
// see if we have already executed it
if (cl.lastClientCommand >= seq)
return true;
Common.Instance.WriteLine("ClientCommand: {0}[s{1}]: {2}", cl.name, seq, s);
// drop the connection if we have somehow lost commands
if (seq > cl.lastClientCommand + 1)
{
Common.Instance.WriteLine("Client {0} lost {1} clientCommands", cl.name, seq-cl.lastClientCommand+1);
DropClient(cl, "Lost reliable commands");
return false;
}
// don't allow another command for one second
cl.nextReliableTime = (int)time + 1000;
ExecuteClientCommand(cl, s);
cl.lastClientCommand = seq;
cl.lastClientCommandString = s;
return true; // continue procesing
}
示例8: ParseCommandString
/*
=====================
CL_ParseCommandString
Command strings are just saved off until cgame asks for them
when it transitions a snapshot
=====================
*/
void ParseCommandString(NetBuffer buf)
{
int seq = buf.ReadInt32();
string s = buf.ReadString();
// see if we have already executed stored it off
if (clc.serverCommandSequence >= seq)
return;
clc.serverCommandSequence = seq;
int index = seq & 63;
clc.serverCommands[index] = s;
}
示例9: Read
public void Read(NetBuffer im)
{
if (Plugins == null)
{
Plugins = new List<string>();
}
int count = im.ReadInt32();
for(int i = 0; i < count; ++i)
{
var plugin = im.ReadString();
Plugins.Add(plugin);
}
}
示例10: 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;
}
示例11: DataHandler
public static void DataHandler(NetClient client, NetBuffer buffer)
{
//Check which page to load
string[] requested_page = buffer.ReadString().Split(':');
string page = requested_page[1];
Console.WriteLine("Requested page: " + page);
Config config = Config.Instance;
//Close any running forms
if (config.Client.form_thread != null)
{
config.Client.form_thread.Abort();
if (config.Client.form_active == "metar")
{
config.Client.metar_form.Close();
}
if (config.Client.form_active == "wind")
{
config.Client.wind_form.Close();
}
}
if (page == "metar")
{
config.Client.form_active = "metar";
config.Client.form_thread = new Thread(new ThreadStart(RunForm));
config.Client.form_thread.Start();
}
if (page == "wind")
{
config.Client.form_active = "wind";
config.Client.form_thread = new Thread(new ThreadStart(RunForm));
config.Client.form_thread.Start();
}
}
示例12: 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();
}
示例13: Main
static unsafe void Main(string[] args)
{
// JIT stuff
NetBuffer msg = new NetBuffer(20);
msg.Write((short)short.MaxValue);
// Go
double timeStart = NetTime.Now;
msg = new NetBuffer(20);
for (int n = 0; n < 10000; n++)
{
msg.Reset();
msg.Write((short)short.MaxValue);
msg.Write((short)short.MinValue);
msg.Write((short)-42);
msg.Write(421);
msg.Write((byte)7);
msg.Write(-42.8f);
if (msg.LengthBytes != 15)
throw new Exception("Bad message length");
msg.Write("duke of earl");
int bytesWritten;
bytesWritten = msg.WriteVariableInt32(-1);
bytesWritten = msg.WriteVariableInt32(5);
bytesWritten = msg.WriteVariableInt32(-18);
bytesWritten = msg.WriteVariableInt32(42);
bytesWritten = msg.WriteVariableInt32(-420);
msg.Write((uint)9991);
// byte boundary kept until here
msg.Write(true);
msg.Write((uint)3, 5);
msg.Write(8.111f);
msg.Write("again");
byte[] arr = new byte[] { 1, 6, 12, 24 };
msg.Write(arr);
msg.Write((byte)7, 7);
msg.Write(Int32.MinValue);
msg.Write(UInt32.MaxValue);
msg.WriteRangedSingle(21.0f, -10, 50, 12);
// test reduced bit signed writing
msg.Write(15, 5);
msg.Write(2, 5);
msg.Write(0, 5);
msg.Write(-1, 5);
msg.Write(-2, 5);
msg.Write(-15, 5);
msg.Write(UInt64.MaxValue);
msg.Write(Int64.MaxValue);
msg.Write(Int64.MinValue);
msg.Write(42);
msg.WritePadBits();
int numBits = msg.WriteRangedInteger(0, 10, 5);
if (numBits != 4)
throw new Exception("Ack WriteRangedInteger failed");
// verify
msg.Position = 0;
short a = msg.ReadInt16();
short b = msg.ReadInt16();
short c = msg.ReadInt16();
if (a != short.MaxValue || b != short.MinValue || c != -42)
throw new Exception("Ack thpth short failed");
if (msg.ReadInt32() != 421)
throw new Exception("Ack thphth 1");
if (msg.ReadByte() != (byte)7)
throw new Exception("Ack thphth 2");
if (msg.ReadSingle() != -42.8f)
throw new Exception("Ack thphth 3");
if (msg.ReadString() != "duke of earl")
throw new Exception("Ack thphth 4");
if (msg.ReadVariableInt32() != -1) throw new Exception("ReadVariableInt32 failed 1");
if (msg.ReadVariableInt32() != 5) throw new Exception("ReadVariableInt32 failed 2");
if (msg.ReadVariableInt32() != -18) throw new Exception("ReadVariableInt32 failed 3");
if (msg.ReadVariableInt32() != 42) throw new Exception("ReadVariableInt32 failed 4");
if (msg.ReadVariableInt32() != -420) throw new Exception("ReadVariableInt32 failed 5");
if (msg.ReadUInt32() != 9991)
throw new Exception("Ack thphth 4.5");
if (msg.ReadBoolean() != true)
throw new Exception("Ack thphth 5");
if (msg.ReadUInt32(5) != (uint)3)
throw new Exception("Ack thphth 6");
//.........这里部分代码省略.........
示例14: Read
public void Read(NetBuffer im)
{
Address = im.ReadString();
ConnectName = im.ReadString();
Information = im.ReadString();
}
示例15: HandleMessage
/// <summary>
/// Handle incoming message
/// </summary>
private void HandleMessage(NetMessageType type, NetBuffer buffer)
{
switch (type)
{
case NetMessageType.DebugMessage:
//
// it's a library debug message; just display it in the console if debugger is attached
//
Console.WriteLine(buffer.ReadString());
break;
case NetMessageType.StatusChanged:
//
// it's a status change message; set the reason as window title and refresh picture
//
this.Text = buffer.ReadString();
pictureBox1.Refresh();
break;
case NetMessageType.ServerDiscovered:
//
// it's a server discovered message; connect to the discovered server
//
m_imageWidth = 0;
m_imageHeight = 0;
m_lineDisplayed = 0;
m_client.Connect(buffer.ReadIPEndPoint());
break;
case NetMessageType.Data:
//
// it's a data message (data sent from the server)
//
if (m_imageWidth == 0)
{
// first message is size
m_imageWidth = (int)buffer.ReadVariableUInt32();
m_imageHeight = (int)buffer.ReadVariableUInt32();
this.Size = new System.Drawing.Size(m_imageWidth + 40, m_imageHeight + 60);
pictureBox1.Image = new Bitmap(m_imageWidth, m_imageHeight);
pictureBox1.SetBounds(12, 12, m_imageWidth, m_imageHeight);
return;
}
uint pixelPos = buffer.ReadUInt32();
// it's color data
int y = (int)(pixelPos / m_imageWidth);
int x = (int)(pixelPos - (y * m_imageWidth));
Bitmap bm = pictureBox1.Image as Bitmap;
pictureBox1.SuspendLayout();
int pixels = (buffer.LengthBytes - 4) / 3;
for (int i = 0; i < pixels; i++)
{
// set pixel
byte r = buffer.ReadByte();
byte g = buffer.ReadByte();
byte b = buffer.ReadByte();
Color col = Color.FromArgb(r, g, b);
if (y > m_imageHeight)
continue;
bm.SetPixel(x, y, col);
x++;
if (x >= m_imageWidth)
{
x = 0;
y++;
}
}
pictureBox1.ResumeLayout();
// refresh image every horizontal line
if (pixelPos / m_imageWidth > m_lineDisplayed)
{
m_lineDisplayed = (int)(pixelPos / m_imageWidth);
pictureBox1.Refresh();
}
break;
default:
// unhandled
break;
}
}