private void ReplyChallenge(EndPoint clientEp) { var msg = new BufferWrite(); // get a free challenge number var challengeNr = GetChallengeNr(clientEp); msg.WriteBytes(NetProtocol.ConnectionlessHeader); msg.WriteChar((char)EConnectionType.ServerChallenge); msg.WriteInt(challengeNr); msg.WriteInt(1); // auth protocol msg.WriteString("EE00"); Networking.SendPacket(null, Socket, clientEp, msg.GetData()); }
public override bool WriteToBuffer(BufferWrite buffer) { buffer.WriteInt(Tick); buffer.WriteULong(Utils.Clamp <ulong>((ulong)(HostFrameTime * Networking.NetTickScaleUp), 0, 65535)); buffer.WriteULong(Utils.Clamp <ulong>((ulong)(HostFrameTimeStdDeviation * Networking.NetTickScaleUp), 0, 65535)); return(true); }
private void SendConnectPacket(int challengeNr, int authProtocol) { var serverEp = (EndPoint) new IPEndPoint(IPAddress.Any, 0); if (!Networking.StringToAddr(_retryAddress, ref serverEp)) { Console.WriteLine("Bad server address ({0})!\n", serverEp); Disconnect(); return; } var msg = new BufferWrite(); msg.WriteBytes(NetProtocol.ConnectionlessHeader); msg.WriteChar((char)EConnectionType.PlayerConnect); msg.WriteInt(Program.ProtocolVersion); msg.WriteInt(authProtocol); msg.WriteInt(challengeNr); msg.WriteString(Program.ClientName); msg.WriteString(Program.ServerPassword); Networking.SendPacket(null, _socket, serverEp, msg.GetData()); }
public int SendDatagram(BufferWrite datagram) { var send = new BufferWrite(); send.WriteInt(_outSequenceNr); send.WriteInt(_inSequenceNr); send.WriteByte(_inReliableState); var flagsPos = send.Position; // write correct flags value later send.WriteByte(0); byte flags = 0; if (_chokedPackets > 0) { flags |= (byte)ENetPacketHeader.Choked; send.WriteByte((byte)(_chokedPackets & 0xFF)); } if (datagram != null) { if (datagram.GetNumBitsWritten() > 0) { send.WriteBytes(datagram.GetData()); } } if (StreamUnreliable.GetNumBitsWritten() > 0) { send.WriteBytes(StreamUnreliable.GetData()); } // clear unreliable data buffer StreamUnreliable.Reset(); send.WriteByteAt((int)flagsPos, flags); var bytesSend = Networking.SendPacket(this, _socket, _remoteAddress, send.GetData()); // TODO: Calc sended size with udp header, and retreive stats // TODO: Network throttling if (_clearTime < Networking.NetTime) { _clearTime = Networking.NetTime; } var addTime = bytesSend / _rate; _clearTime += addTime; if (Networking.NetMaxcleartime > 0.0f) { var latestClearTime = Networking.NetTime + Networking.NetMaxcleartime; if (_clearTime > latestClearTime) { _clearTime = latestClearTime; } } _chokedPackets = 0; _outSequenceNr++; // return send sequence nr return(_outSequenceNr - 1); }