public static void Netchan_OutOfBand(int net_socket, netadr_t adr, int length, byte[] data) { SZ.Init(send, send_buf, Defines.MAX_MSGLEN); MSG.WriteInt(send, -1); SZ.Write(send, data, length); NET.SendPacket(net_socket, send.cursize, send.data, adr); }
public static void WriteShort(sizebuf_t sb, Int32 c) { var i = SZ.GetSpace(sb, 2); sb.data[i++] = ( Byte )(c & 0xff); sb.data[i] = ( Byte )((c >> 8) & 0xFF); }
public static void Transmit(netchan_t chan, int length, byte[] data) { int send_reliable; int w1, w2; if (chan.message.overflowed) { chan.fatal_error = true; Com.Printf(NET.AdrToString(chan.remote_address) + ":Outgoing message overflow\\n"); return; } send_reliable = Netchan_NeedReliable(chan) ? 1 : 0; if (chan.reliable_length == 0 && chan.message.cursize != 0) { System.Array.Copy(chan.message_buf, 0, chan.reliable_buf, 0, chan.message.cursize); chan.reliable_length = chan.message.cursize; chan.message.cursize = 0; chan.reliable_sequence ^= 1; } SZ.Init(send, send_buf, send_buf.Length); w1 = (chan.outgoing_sequence & ~(1 << 31)) | (send_reliable << 31); w2 = (chan.incoming_sequence & ~(1 << 31)) | (chan.incoming_reliable_sequence << 31); chan.outgoing_sequence++; chan.last_sent = (int)Globals.curtime; MSG.WriteInt(send, w1); MSG.WriteInt(send, w2); if (chan.sock == Defines.NS_CLIENT) { MSG.WriteShort(send, (int)qport.value); } if (send_reliable != 0) { SZ.Write(send, chan.reliable_buf, chan.reliable_length); chan.last_reliable_sequence = chan.outgoing_sequence; } if (send.maxsize - send.cursize >= length) { SZ.Write(send, data, length); } else { Com.Printf("Netchan_Transmit: dumped unreliable\\n"); } NET.SendPacket(chan.sock, send.cursize, send.data, chan.remote_address); if (showpackets.value != 0) { if (send_reliable != 0) { Com.Printf("send " + send.cursize + " : s=" + (chan.outgoing_sequence - 1) + " reliable=" + chan.reliable_sequence + " ack=" + chan.incoming_sequence + " rack=" + chan.incoming_reliable_sequence + "\\n"); } else { Com.Printf("send " + send.cursize + " : s=" + (chan.outgoing_sequence - 1) + " ack=" + chan.incoming_sequence + " rack=" + chan.incoming_reliable_sequence + "\\n"); } } }
public static void WriteInt(sizebuf_t sb, Int32 c) { var i = SZ.GetSpace(sb, 4); sb.data[i++] = ( Byte )((c & 0xff)); sb.data[i++] = ( Byte )((c >> 8) & 0xff); sb.data[i++] = ( Byte )((c >> 16) & 0xff); sb.data[i++] = ( Byte )((c >> 24) & 0xff); }
public static void WriteString(sizebuf_t sb, String s) { var x = s; if (s == null) { x = ""; } SZ.Write(sb, Lib.StringToBytes(x)); WriteByte(sb, 0); }
public static void AddText(string text) { int l = text.Length; if (Globals.cmd_text.cursize + l >= Globals.cmd_text.maxsize) { Com.Printf("Cbuf_AddText: overflow\\n"); return; } SZ.Write(Globals.cmd_text, Encoding.ASCII.GetBytes(text), l); }
public static void Setup(int sock, netchan_t chan, netadr_t adr, int qport) { chan.Clear(); chan.sock = sock; chan.remote_address.Set(adr); chan.qport = qport; chan.last_received = Globals.curtime; chan.incoming_sequence = 0; chan.outgoing_sequence = 1; SZ.Init(chan.message, chan.message_buf, chan.message_buf.Length); chan.message.allowoverflow = true; }
public static void InsertText(string text) { int templen = 0; templen = Globals.cmd_text.cursize; if (templen != 0) { System.Array.Copy(Globals.cmd_text.data, 0, tmp, 0, templen); SZ.Clear(Globals.cmd_text); } Cbuf.AddText(text); if (templen != 0) { SZ.Write(Globals.cmd_text, tmp, templen); } }
public static void Main(String[] args) { byte[] buf_data = new byte[Defines.MAX_MSGLEN]; sizebuf_t buf = new sizebuf_t(); SZ.Init(buf, buf_data, Defines.MAX_MSGLEN); MSG.WriteInt(buf, 0x80000000); MSG.WriteInt(buf, 0x12345678); MSG.WriteInt(buf, 0x7fffffff); MSG.WriteInt(buf, 0xffffffff); MSG.WriteByte(buf, 1); MSG.WriteByte(buf, 2); MSG.WriteByte(buf, 3); MSG.WriteByte(buf, 4); SZ.Print(buf, "[einz]\\n"); SZ.Print(buf, "[zwei]..."); MSG.WriteByte(buf, 0xfe); MSG.WriteByte(buf, 4); MSG.WriteShort(buf, 32766); MSG.WriteShort(buf, 16384); MSG.WriteShort(buf, -32768); MSG.WriteFloat(buf, (float)Math.PI); System.Diagnostics.Debug.WriteLine("Read:" + Integer.ToHexString(MSG.ReadLong(buf))); System.Diagnostics.Debug.WriteLine("Read:" + Integer.ToHexString(MSG.ReadLong(buf))); System.Diagnostics.Debug.WriteLine("Read:" + Integer.ToHexString(MSG.ReadLong(buf))); System.Diagnostics.Debug.WriteLine("Read:" + Integer.ToHexString(MSG.ReadLong(buf))); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:<" + MSG.ReadString(buf) + ">"); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadByte(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadShort(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadShort(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadShort(buf)); System.Diagnostics.Debug.WriteLine("Read:" + MSG.ReadFloat(buf)); }
public static void Init( ) { SZ.Init(Globals.cmd_text, Globals.cmd_text_buf, Globals.cmd_text_buf.Length); }
public static void WriteChar(sizebuf_t sb, Int32 c) { sb.data[SZ.GetSpace(sb, 1)] = ( Byte )(c & 0xFF); }