/// <summary> /// Datagram_CanSendMessage /// </summary> public bool CanSendMessage(qsocket_t sock) { if (sock.sendNext) SendMessageNext(sock); return sock.canSend; }
// PrintStats(qsocket_t* s) private void PrintStats(qsocket_t s) { Con.Print("canSend = {0:4} \n", s.canSend); Con.Print("sendSeq = {0:4} ", s.sendSequence); Con.Print("recvSeq = {0:4} \n", s.receiveSequence); Con.Print("\n"); }
public int SendMessage(qsocket_t sock, MsgWriter data) { if (sock.driverdata == null) { return(-1); } qsocket_t sock2 = (qsocket_t)sock.driverdata; if ((sock2.receiveMessageLength + data.Length + 4) > Net.NET_MAXMESSAGE) { Sys.Error("Loop_SendMessage: overflow\n"); } // message type int offset = sock2.receiveMessageLength; sock2.receiveMessage[offset++] = 1; // length sock2.receiveMessage[offset++] = (byte)(data.Length & 0xff); sock2.receiveMessage[offset++] = (byte)(data.Length >> 8); // align offset++; // message Buffer.BlockCopy(data.Data, 0, sock2.receiveMessage, offset, data.Length); sock2.receiveMessageLength = IntAlign(sock2.receiveMessageLength + data.Length + 4); sock.canSend = false; return(1); }
public int GetMessage(qsocket_t sock) { if (sock.receiveMessageLength == 0) { return(0); } int ret = sock.receiveMessage[0]; int length = sock.receiveMessage[1] + (sock.receiveMessage[2] << 8); // alignment byte skipped here Net.Message.Clear(); Net.Message.FillFrom(sock.receiveMessage, 4, length); length = IntAlign(length + 4); sock.receiveMessageLength -= length; if (sock.receiveMessageLength > 0) { Array.Copy(sock.receiveMessage, length, sock.receiveMessage, 0, sock.receiveMessageLength); } if (sock.driverdata != null && ret == 1) { ((qsocket_t)sock.driverdata).canSend = true; } return(ret); }
public qsocket_t CheckNewConnections() { if (host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_CONNECT) { sys.Error("VCR missmatch"); } if (_Next.session == 0) { ReadNext(); return(null); } qsocket_t sock = net.NewSocket(); sock.driverdata = _Next.session; byte[] buf = new byte[net.NET_NAMELEN]; host.VcrReader.Read(buf, 0, buf.Length); sock.address = Encoding.ASCII.GetString(buf); ReadNext(); return(sock); }
/// <summary> /// NET_CanSendMessage /// Returns true or false if the given qsocket can currently accept a /// message to be transmitted. /// </summary> public static bool CanSendMessage(qsocket_t sock) { if (sock == null) { return(false); } if (sock.disconnected) { return(false); } SetNetTime(); bool r = _Drivers[sock.driver].CanSendMessage(sock); if (_IsRecording) { _VcrSendMessage.time = Host.Time; _VcrSendMessage.op = VcrOp.VCR_OP_CANSENDMESSAGE; _VcrSendMessage.session = 1; // (long)sock; Uze: todo: do something? _VcrSendMessage.ret = r ? 1 : 0; byte[] buf = Sys.StructureToBytes(ref _VcrSendMessage); Host.VcrWriter.Write(buf, 0, buf.Length); } return(r); }
/// <summary> /// NET_SendMessage /// Try to send a complete length+message unit over the reliable stream. /// returns 0 if the message cannot be delivered reliably, but the connection /// is still considered valid /// returns 1 if the message was sent properly /// returns -1 if the connection died /// </summary> public Int32 SendMessage(qsocket_t sock, MessageWriter data) { if (sock == null) { return(-1); } if (sock.disconnected) { Host.Console.Print("NET_SendMessage: disconnected socket\n"); return(-1); } SetNetTime(); var r = _Drivers[sock.driver].SendMessage(sock, data); if (r == 1 && sock.driver != 0) { _MessagesSent++; } if (_IsRecording) { _VcrSendMessage.time = Host.Time; _VcrSendMessage.op = VcrOp.VCR_OP_SENDMESSAGE; _VcrSendMessage.session = 1; // (long)sock; Uze: todo: do something? _VcrSendMessage.ret = r; var buf = Utilities.StructureToBytes(ref _VcrSendMessage); Host.VcrWriter.Write(buf, 0, buf.Length); } return(r); }
/// <summary> /// NET_SendUnreliableMessage /// returns 0 if the message connot be delivered reliably, but the connection /// is still considered valid /// returns 1 if the message was sent properly /// returns -1 if the connection died /// </summary> public static int SendUnreliableMessage(qsocket_t sock, MsgWriter data) { if (sock == null) { return(-1); } if (sock.disconnected) { Con.Print("NET_SendMessage: disconnected socket\n"); return(-1); } SetNetTime(); int r = _Drivers[sock.driver].SendUnreliableMessage(sock, data); if (r == 1 && sock.driver != 0) { _UnreliableMessagesSent++; } if (_IsRecording) { _VcrSendMessage.time = Host.Time; _VcrSendMessage.op = VcrOp.VCR_OP_SENDMESSAGE; _VcrSendMessage.session = 1;// (long)sock; Uze todo: ??????? _VcrSendMessage.ret = r; byte[] buf = Sys.StructureToBytes(ref _VcrSendMessage); Host.VcrWriter.Write(buf); } return(r); }
public int SendUnreliableMessage(qsocket_t sock, MsgWriter data) { if (sock.driverdata == null) { return(-1); } qsocket_t sock2 = (qsocket_t)sock.driverdata; if ((sock2.receiveMessageLength + data.Length + sizeof(byte) + sizeof(short)) > Net.NET_MAXMESSAGE) { return(0); } int offset = sock2.receiveMessageLength; // message type sock2.receiveMessage[offset++] = 2; // length sock2.receiveMessage[offset++] = (byte)(data.Length & 0xff); sock2.receiveMessage[offset++] = (byte)(data.Length >> 8); // align offset++; // message Buffer.BlockCopy(data.Data, 0, sock2.receiveMessage, offset, data.Length); sock2.receiveMessageLength = IntAlign(sock2.receiveMessageLength + data.Length + 4); return(1); }
/// <summary> /// SV_CheckForNewClients /// </summary> public static void CheckForNewClients() { // // check for new connections // while (true) { qsocket_t ret = net.CheckNewConnections(); if (ret == null) { break; } // // init a new client structure // int i; for (i = 0; i < svs.maxclients; i++) { if (!svs.clients[i].active) { break; } } if (i == svs.maxclients) { sys.Error("Host_CheckForNewClients: no free clients"); } svs.clients[i].netconnection = ret; ConnectClient(i); net.ActiveConnections++; } }
// NET_Stats_f private void Stats_f(CommandMessage msg) { if (msg.Parameters == null || msg.Parameters.Length == 0) { Host.Console.Print("unreliable messages sent = %i\n", Host.Network.UnreliableMessagesSent); Host.Console.Print("unreliable messages recv = %i\n", Host.Network.UnreliableMessagesReceived); Host.Console.Print("reliable messages sent = %i\n", Host.Network.MessagesSent); Host.Console.Print("reliable messages received = %i\n", Host.Network.MessagesReceived); Host.Console.Print("packetsSent = %i\n", packetsSent); Host.Console.Print("packetsReSent = %i\n", packetsReSent); Host.Console.Print("packetsReceived = %i\n", packetsReceived); Host.Console.Print("receivedDuplicateCount = %i\n", receivedDuplicateCount); Host.Console.Print("shortPacketCount = %i\n", shortPacketCount); Host.Console.Print("droppedDatagrams = %i\n", droppedDatagrams); } else if (msg.Parameters[0] == "*") { foreach (var s in Host.Network.ActiveSockets) { PrintStats(s); } foreach (var s in Host.Network.FreeSockets) { PrintStats(s); } } else { qsocket_t sock = null; var cmdAddr = msg.Parameters[0]; foreach (var s in Host.Network.ActiveSockets) { if (Utilities.SameText(s.address, cmdAddr)) { sock = s; break; } } if (sock == null) { foreach (var s in Host.Network.FreeSockets) { if (Utilities.SameText(s.address, cmdAddr)) { sock = s; break; } } } if (sock == null) { return; } PrintStats(sock); } }
// NET_Stats_f private void Stats_f() { if (cmd.Argc == 1) { Con.Print("unreliable messages sent = %i\n", net.UnreliableMessagesSent); Con.Print("unreliable messages recv = %i\n", net.UnreliableMessagesReceived); Con.Print("reliable messages sent = %i\n", net.MessagesSent); Con.Print("reliable messages received = %i\n", net.MessagesReceived); Con.Print("packetsSent = %i\n", packetsSent); Con.Print("packetsReSent = %i\n", packetsReSent); Con.Print("packetsReceived = %i\n", packetsReceived); Con.Print("receivedDuplicateCount = %i\n", receivedDuplicateCount); Con.Print("shortPacketCount = %i\n", shortPacketCount); Con.Print("droppedDatagrams = %i\n", droppedDatagrams); } else if (cmd.Argv(1) == "*") { foreach (qsocket_t s in net.ActiveSockets) { PrintStats(s); } foreach (qsocket_t s in net.FreeSockets) { PrintStats(s); } } else { qsocket_t sock = null; string cmdAddr = cmd.Argv(1); foreach (qsocket_t s in net.ActiveSockets) { if (common.SameText(s.address, cmdAddr)) { sock = s; break; } } if (sock == null) { foreach (qsocket_t s in net.FreeSockets) { if (common.SameText(s.address, cmdAddr)) { sock = s; break; } } } if (sock == null) { return; } PrintStats(sock); } }
public bool CanSendMessage(qsocket_t sock) { if (sock.driverdata == null) { return(false); } return(sock.canSend); }
public bool CanSendMessage(qsocket_t sock) { if (Host.Time != _Next.time || _Next.op != VcrOp. VCR_OP_CANSENDMESSAGE || _Next.session != SocketToSession(sock)) Sys.Error("VCR missmatch"); int ret = Host.VcrReader.ReadInt32(); ReadNext(); return ret != 0; }
/// <summary> /// NET_FreeQSocket /// </summary> public static void FreeSocket(qsocket_t sock) { // remove it from active list if (!_ActiveSockets.Remove(sock)) { Sys.Error("NET_FreeQSocket: not active\n"); } // add it to free list _FreeSockets.Add(sock); sock.disconnected = true; }
public void Close(qsocket_t sock) { if (sock.driverdata != null) ((qsocket_t)sock.driverdata).driverdata = null; sock.ClearBuffers(); sock.canSend = true; if (sock == _Client) _Client = null; else _Server = null; }
public bool CanSendMessage(qsocket_t sock) { if (host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_CANSENDMESSAGE || _Next.session != SocketToSession(sock)) { sys.Error("VCR missmatch"); } int ret = host.VcrReader.ReadInt32(); ReadNext(); return(ret != 0); }
public int SendMessage(qsocket_t sock, MsgWriter data) { if (host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_SENDMESSAGE || _Next.session != SocketToSession(sock)) { sys.Error("VCR missmatch"); } int ret = host.VcrReader.ReadInt32(); ReadNext(); return(ret); }
public Boolean CanSendMessage(qsocket_t sock) { if (Host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_CANSENDMESSAGE || _Next.session != SocketToSession(sock)) { Utilities.Error("VCR missmatch"); } var ret = Host.VcrReader.ReadInt32(); ReadNext(); return(ret != 0); }
public Int32 SendMessage(qsocket_t sock, MessageWriter data) { if (Host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_SENDMESSAGE || _Next.session != SocketToSession(sock)) { Utilities.Error("VCR missmatch"); } var ret = Host.VcrReader.ReadInt32(); ReadNext(); return(ret); }
private qsocket_t SearchActiveSockets(String cmdAddr) { qsocket_t sock = null; foreach (var s in Host.Network.ActiveSockets) { if (Utilities.SameText(s.address, cmdAddr)) { sock = s; break; } } return(sock); }
/// <summary> /// NET_CheckNewConnections /// </summary> /// <returns></returns> public static qsocket_t CheckNewConnections() { SetNetTime(); for (_DriverLevel = 0; _DriverLevel < _Drivers.Length; _DriverLevel++) { if (!_Drivers[_DriverLevel].IsInitialized) { continue; } if (_DriverLevel > 0 && !_IsListening) { continue; } qsocket_t ret = Net.Driver.CheckNewConnections(); if (ret != null) { if (_IsRecording) { _VcrConnect.time = Host.Time; _VcrConnect.op = VcrOp.VCR_OP_CONNECT; _VcrConnect.session = 1; // (long)ret; // Uze: todo: make it work on 64bit systems byte[] buf = Sys.StructureToBytes(ref _VcrConnect); Host.VcrWriter.Write(buf, 0, buf.Length); buf = Encoding.ASCII.GetBytes(ret.address); int count = Math.Min(buf.Length, NET_NAMELEN); int extra = NET_NAMELEN - count; Host.VcrWriter.Write(buf, 0, count); for (int i = 0; i < extra; i++) { Host.VcrWriter.Write((byte)0); } } return(ret); } } if (_IsRecording) { _VcrConnect.time = Host.Time; _VcrConnect.op = VcrOp.VCR_OP_CONNECT; _VcrConnect.session = 0; byte[] buf = Sys.StructureToBytes(ref _VcrConnect); Host.VcrWriter.Write(buf, 0, buf.Length); } return(null); }
/// <summary> /// Datagram_Connect /// </summary> public qsocket_t Connect(string host) { qsocket_t ret = null; for (net.LanDriverLevel = 0; net.LanDriverLevel < net.LanDrivers.Length; net.LanDriverLevel++) { if (net.LanDrivers[net.LanDriverLevel].IsInitialized) { ret = InternalConnect(host); if (ret != null) { break; } } } return(ret); }
/// <summary> /// Datagram_CheckNewConnections /// </summary> public qsocket_t CheckNewConnections() { qsocket_t ret = null; for (net.LanDriverLevel = 0; net.LanDriverLevel < net.LanDrivers.Length; net.LanDriverLevel++) { if (net.LanDriver.IsInitialized) { ret = InternalCheckNewConnections(); if (ret != null) { break; } } } return(ret); }
/// <summary> /// Datagram_CheckNewConnections /// </summary> public qsocket_t CheckNewConnections( ) { qsocket_t ret = null; for (Host.Network.LanDriverLevel = 0; Host.Network.LanDriverLevel < Host.Network.LanDrivers.Length; Host.Network.LanDriverLevel++) { if (Host.Network.LanDriver.IsInitialised) { ret = InternalCheckNewConnections( ); if (ret != null) { break; } } } return(ret); }
/// <summary> /// Datagram_Connect /// </summary> public qsocket_t Connect(String host) { qsocket_t ret = null; for (Host.Network.LanDriverLevel = 0; Host.Network.LanDriverLevel < Host.Network.LanDrivers.Length; Host.Network.LanDriverLevel++) { if (Host.Network.LanDrivers[Host.Network.LanDriverLevel].IsInitialised) { ret = InternalConnect(host); if (ret != null) { break; } } } return(ret); }
public void Close(qsocket_t sock) { if (sock.driverdata != null) { ((qsocket_t)sock.driverdata).driverdata = null; } sock.ClearBuffers(); sock.canSend = true; if (sock == _Client) { _Client = null; } else { _Server = null; } }
private void PrintStatsForSocket(CommandMessage msg) { qsocket_t sock = null; var cmdAddr = msg.Parameters[0]; sock = SearchActiveSockets(cmdAddr); if (sock == null) { sock = SearchFreeSockets(cmdAddr); } if (sock == null) { return; } PrintStats(sock); }
/// <summary> /// NET_Close /// </summary> public static void Close(qsocket_t sock) { if (sock == null) { return; } if (sock.disconnected) { return; } SetNetTime(); // call the driver_Close function _Drivers[sock.driver].Close(sock); FreeSocket(sock); }
public void Clear() { this.active = false; this.spawned = false; this.dropasap = false; this.privileged = false; this.sendsignon = false; this.last_message = 0; this.netconnection = null; this.cmd.Clear(); this.wishdir = Vector3.Zero; this.message.Clear(); this.edict = null; this.name = null; this.colors = 0; Array.Clear(this.ping_times, 0, this.ping_times.Length); this.num_pings = 0; Array.Clear(this.spawn_parms, 0, this.spawn_parms.Length); this.old_frags = 0; }
/// <summary> /// SV_ConnectClient /// Initializes a client_t for a new net connection. This will only be called /// once for a player each game, not once for each level change. /// </summary> private static void ConnectClient(int clientnum) { client_t client = svs.clients[clientnum]; Con.DPrint("Client {0} connected\n", client.netconnection.address); int edictnum = clientnum + 1; edict_t ent = EdictNum(edictnum); // set up the client_t qsocket_t netconnection = client.netconnection; float[] spawn_parms = new float[NUM_SPAWN_PARMS]; if (sv.loadgame) { Array.Copy(client.spawn_parms, spawn_parms, spawn_parms.Length); } client.Clear(); client.netconnection = netconnection; client.name = "unconnected"; client.active = true; client.spawned = false; client.edict = ent; client.message.AllowOverflow = true; // we can catch it client.privileged = false; if (sv.loadgame) { Array.Copy(spawn_parms, client.spawn_parms, spawn_parms.Length); } else { // call the progs to get default spawn parms for the new client progs.Execute(progs.GlobalStruct.SetNewParms); AssignGlobalSpawnparams(client); } SendServerInfo(client); }
public qsocket_t Connect(string host) { if (host != "local") { return(null); } _LocalConnectPending = true; if (_Client == null) { _Client = Net.NewSocket(); if (_Client == null) { Con.Print("Loop_Connect: no qsocket available\n"); return(null); } _Client.address = "localhost"; } _Client.ClearBuffers(); _Client.canSend = true; if (_Server == null) { _Server = Net.NewSocket(); if (_Server == null) { Con.Print("Loop_Connect: no qsocket available\n"); return(null); } _Server.address = "LOCAL"; } _Server.ClearBuffers(); _Server.canSend = true; _Client.driverdata = _Server; _Server.driverdata = _Client; return(_Client); }
/// <summary> /// NET_NewQSocket /// Called by drivers when a new communications endpoint is required /// The sequence and buffer fields will be filled in properly /// </summary> public static qsocket_t NewSocket() { if (_FreeSockets.Count == 0) { return(null); } if (Net.ActiveConnections >= Server.svs.maxclients) { return(null); } // get one from free list int i = _FreeSockets.Count - 1; qsocket_t sock = _FreeSockets[i]; _FreeSockets.RemoveAt(i); // add it to active list _ActiveSockets.Add(sock); sock.disconnected = false; sock.connecttime = _Time; sock.address = "UNSET ADDRESS"; sock.driver = _DriverLevel; sock.socket = null; sock.driverdata = null; sock.canSend = true; sock.sendNext = false; sock.lastMessageTime = _Time; sock.ackSequence = 0; sock.sendSequence = 0; sock.unreliableSendSequence = 0; sock.sendMessageLength = 0; sock.receiveSequence = 0; sock.unreliableReceiveSequence = 0; sock.receiveMessageLength = 0; return(sock); }
public int GetMessage(qsocket_t sock) { if (Host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_GETMESSAGE || _Next.session != SocketToSession(sock)) Sys.Error("VCR missmatch"); int ret = Host.VcrReader.ReadInt32(); if (ret != 1) { ReadNext(); return ret; } int length = Host.VcrReader.ReadInt32(); Net.Message.FillFrom(Host.VcrReader.BaseStream, length); ReadNext(); return 1; }
public int SendMessage(qsocket_t sock, MsgWriter data) { if (Host.Time != _Next.time || _Next.op != VcrOp.VCR_OP_SENDMESSAGE || _Next.session != SocketToSession(sock)) Sys.Error("VCR missmatch"); int ret = Host.VcrReader.ReadInt32(); ReadNext(); return ret; }
public long SocketToSession(qsocket_t sock) { return (long)sock.driverdata; }
public int SendUnreliableMessage(qsocket_t sock, MsgWriter data) { throw new NotImplementedException(); }
public int GetMessage(qsocket_t sock) { if (sock.receiveMessageLength == 0) return 0; int ret = sock.receiveMessage[0]; int length = sock.receiveMessage[1] + (sock.receiveMessage[2] << 8); // alignment byte skipped here Net.Message.Clear(); Net.Message.FillFrom(sock.receiveMessage, 4, length); length = IntAlign(length + 4); sock.receiveMessageLength -= length; if (sock.receiveMessageLength > 0) Array.Copy(sock.receiveMessage, length, sock.receiveMessage, 0, sock.receiveMessageLength); if (sock.driverdata != null && ret == 1) ((qsocket_t)sock.driverdata).canSend = true; return ret; }
public int SendUnreliableMessage(qsocket_t sock, MsgWriter data) { if (sock.driverdata == null) return -1; qsocket_t sock2 = (qsocket_t)sock.driverdata; if ((sock2.receiveMessageLength + data.Length + sizeof(byte) + sizeof(short)) > Net.NET_MAXMESSAGE) return 0; int offset = sock2.receiveMessageLength; // message type sock2.receiveMessage[offset++] = 2; // length sock2.receiveMessage[offset++] = (byte)(data.Length & 0xff); sock2.receiveMessage[offset++] = (byte)(data.Length >> 8); // align offset++; // message Buffer.BlockCopy(data.Data, 0, sock2.receiveMessage, offset, data.Length); sock2.receiveMessageLength = IntAlign(sock2.receiveMessageLength + data.Length + 4); return 1; }
public qsocket_t Connect(string host) { if (host != "local") return null; _LocalConnectPending = true; if (_Client == null) { _Client = Net.NewSocket(); if (_Client == null) { Con.Print("Loop_Connect: no qsocket available\n"); return null; } _Client.address = "localhost"; } _Client.ClearBuffers(); _Client.canSend = true; if (_Server == null) { _Server = Net.NewSocket(); if (_Server == null) { Con.Print("Loop_Connect: no qsocket available\n"); return null; } _Server.address = "LOCAL"; } _Server.ClearBuffers(); _Server.canSend = true; _Client.driverdata = _Server; _Server.driverdata = _Client; return _Client; }
/// <summary> /// Datagram_Close /// </summary> public void Close(qsocket_t sock) { sock.LanDriver.CloseSocket(sock.socket); }
public int GetMessage(qsocket_t sock) { if (!sock.canSend) if ((Net.Time - sock.lastSendTime) > 1.0) ReSendMessage(sock); int ret = 0; EndPoint readaddr = new IPEndPoint(IPAddress.Any, 0); while (true) { int length = sock.Read(_PacketBuffer, Net.NET_DATAGRAMSIZE, ref readaddr); if (length == 0) break; if (length == -1) { Con.Print("Read error\n"); return -1; } if (sock.LanDriver.AddrCompare(readaddr, sock.addr) != 0) { #if DEBUG Con.DPrint("Forged packet received\n"); Con.DPrint("Expected: {0}\n", StrAddr(sock.addr)); Con.DPrint("Received: {0}\n", StrAddr(readaddr)); #endif continue; } if (length < Net.NET_HEADERSIZE) { shortPacketCount++; continue; } PacketHeader header = Sys.BytesToStructure<PacketHeader>(_PacketBuffer, 0); length = Common.BigLong(header.length); int flags = length & (~NetFlags.NETFLAG_LENGTH_MASK); length &= NetFlags.NETFLAG_LENGTH_MASK; if ((flags & NetFlags.NETFLAG_CTL) != 0) continue; uint sequence = (uint)Common.BigLong(header.sequence); packetsReceived++; if ((flags & NetFlags.NETFLAG_UNRELIABLE) != 0) { if (sequence < sock.unreliableReceiveSequence) { Con.DPrint("Got a stale datagram\n"); ret = 0; break; } if (sequence != sock.unreliableReceiveSequence) { int count = (int)(sequence - sock.unreliableReceiveSequence); droppedDatagrams += count; Con.DPrint("Dropped {0} datagram(s)\n", count); } sock.unreliableReceiveSequence = sequence + 1; length -= Net.NET_HEADERSIZE; Net.Message.FillFrom(_PacketBuffer, PacketHeader.SizeInBytes, length); ret = 2; break; } if ((flags & NetFlags.NETFLAG_ACK) != 0) { if (sequence != (sock.sendSequence - 1)) { Con.DPrint("Stale ACK received\n"); continue; } if (sequence == sock.ackSequence) { sock.ackSequence++; if (sock.ackSequence != sock.sendSequence) Con.DPrint("ack sequencing error\n"); } else { Con.DPrint("Duplicate ACK received\n"); continue; } sock.sendMessageLength -= QDef.MAX_DATAGRAM; if (sock.sendMessageLength > 0) { Buffer.BlockCopy(sock.sendMessage, QDef.MAX_DATAGRAM, sock.sendMessage, 0, sock.sendMessageLength); sock.sendNext = true; } else { sock.sendMessageLength = 0; sock.canSend = true; } continue; } if ((flags & NetFlags.NETFLAG_DATA) != 0) { header.length = Common.BigLong(Net.NET_HEADERSIZE | NetFlags.NETFLAG_ACK); header.sequence = Common.BigLong((int)sequence); Sys.StructureToBytes(ref header, _PacketBuffer, 0); sock.Write(_PacketBuffer, Net.NET_HEADERSIZE, readaddr); if (sequence != sock.receiveSequence) { receivedDuplicateCount++; continue; } sock.receiveSequence++; length -= Net.NET_HEADERSIZE; if ((flags & NetFlags.NETFLAG_EOM) != 0) { Net.Message.Clear(); Net.Message.FillFrom(sock.receiveMessage, 0, sock.receiveMessageLength); Net.Message.AppendFrom(_PacketBuffer, PacketHeader.SizeInBytes, length); sock.receiveMessageLength = 0; ret = 1; break; } Buffer.BlockCopy(_PacketBuffer, PacketHeader.SizeInBytes, sock.receiveMessage, sock.receiveMessageLength, length); sock.receiveMessageLength += length; continue; } } if (sock.sendNext) SendMessageNext(sock); return ret; }
public bool CanSendUnreliableMessage(qsocket_t sock) { return true; }
public bool CanSendMessage(qsocket_t sock) { if (sock.driverdata == null) return false; return sock.canSend; }
/// <summary> /// NET_SendUnreliableMessage /// returns 0 if the message connot be delivered reliably, but the connection /// is still considered valid /// returns 1 if the message was sent properly /// returns -1 if the connection died /// </summary> public static int SendUnreliableMessage(qsocket_t sock, MsgWriter data) { if (sock == null) return -1; if (sock.disconnected) { Con.Print("NET_SendMessage: disconnected socket\n"); return -1; } SetNetTime(); int r = _Drivers[sock.driver].SendUnreliableMessage(sock, data); if (r == 1 && sock.driver != 0) _UnreliableMessagesSent++; if (_IsRecording) { _VcrSendMessage.time = Host.Time; _VcrSendMessage.op = VcrOp.VCR_OP_SENDMESSAGE; _VcrSendMessage.session = 1;// (long)sock; Uze todo: ??????? _VcrSendMessage.ret = r; byte[] buf = Sys.StructureToBytes(ref _VcrSendMessage); Host.VcrWriter.Write(buf); } return r; }
public void Close(qsocket_t sock) { // nothing to do }
/// <summary> /// NET_GetMessage /// returns data in net_message sizebuf /// returns 0 if no data is waiting /// returns 1 if a message was received /// returns 2 if an unreliable message was received /// returns -1 if the connection died /// </summary> public static int GetMessage(qsocket_t sock) { //int ret; if (sock == null) return -1; if (sock.disconnected) { Con.Print("NET_GetMessage: disconnected socket\n"); return -1; } SetNetTime(); int ret = _Drivers[sock.driver].GetMessage(sock); // see if this connection has timed out if (ret == 0 && sock.driver != 0) { if (_Time - sock.lastMessageTime > _MessageTimeout.Value) { Close(sock); return -1; } } if (ret > 0) { if (sock.driver != 0) { sock.lastMessageTime = _Time; if (ret == 1) _MessagesReceived++; else if (ret == 2) _UnreliableMessagesReceived++; } if (_IsRecording) { _VcrGetMessage.time = Host.Time; _VcrGetMessage.op = VcrOp.VCR_OP_GETMESSAGE; _VcrGetMessage.session = 1;// (long)sock; Uze todo: write somethisng meaningful _VcrGetMessage.ret = ret; byte[] buf = Sys.StructureToBytes(ref _VcrGetMessage); Host.VcrWriter.Write(buf, 0, buf.Length); Host.VcrWriter.Write(Net.Message.Length); Host.VcrWriter.Write(Net.Message.Data, 0, Net.Message.Length); } } else { if (_IsRecording) { _VcrGetMessage.time = Host.Time; _VcrGetMessage.op = VcrOp.VCR_OP_GETMESSAGE; _VcrGetMessage.session = 1; // (long)sock; Uze todo: fix this _VcrGetMessage.ret = ret; byte[] buf = Sys.StructureToBytes(ref _VcrGetMessage); Host.VcrWriter.Write(buf, 0, buf.Length); } } return ret; }
public int SendMessage(qsocket_t sock, MsgWriter data) { if (sock.driverdata == null) return -1; qsocket_t sock2 = (qsocket_t)sock.driverdata; if ((sock2.receiveMessageLength + data.Length + 4) > Net.NET_MAXMESSAGE) Sys.Error("Loop_SendMessage: overflow\n"); // message type int offset = sock2.receiveMessageLength; sock2.receiveMessage[offset++] = 1; // length sock2.receiveMessage[offset++] = (byte)(data.Length & 0xff); sock2.receiveMessage[offset++] = (byte)(data.Length >> 8); // align offset++; // message Buffer.BlockCopy(data.Data, 0, sock2.receiveMessage, offset, data.Length); sock2.receiveMessageLength = IntAlign(sock2.receiveMessageLength + data.Length + 4); sock.canSend = false; return 1; }
/// <summary> /// NET_Close /// </summary> public static void Close(qsocket_t sock) { if (sock == null) return; if (sock.disconnected) return; SetNetTime(); // call the driver_Close function _Drivers[sock.driver].Close(sock); FreeSocket(sock); }
/// <summary> /// NET_FreeQSocket /// </summary> public static void FreeSocket(qsocket_t sock) { // remove it from active list if (!_ActiveSockets.Remove(sock)) Sys.Error("NET_FreeQSocket: not active\n"); // add it to free list _FreeSockets.Add(sock); sock.disconnected = true; }
/// <summary> /// NET_CanSendMessage /// Returns true or false if the given qsocket can currently accept a /// message to be transmitted. /// </summary> public static bool CanSendMessage(qsocket_t sock) { if (sock == null) return false; if (sock.disconnected) return false; SetNetTime(); bool r = _Drivers[sock.driver].CanSendMessage(sock); if (_IsRecording) { _VcrSendMessage.time = Host.Time; _VcrSendMessage.op = VcrOp.VCR_OP_CANSENDMESSAGE; _VcrSendMessage.session = 1; // (long)sock; Uze: todo: do something? _VcrSendMessage.ret = r ? 1 : 0; byte[] buf = Sys.StructureToBytes(ref _VcrSendMessage); Host.VcrWriter.Write(buf, 0, buf.Length); } return r; }