/// <summary> /// Returns encoded index /// </summary> public int Write(NetMessage msg, string str) { int idx = m_data.IndexOf(str); if (idx == -1) { idx = m_data.Count; m_data.Add(str); msg.Write(false); msg.Write7BitEncodedUInt((uint)idx); msg.Write(str); return idx; } msg.Write(true); msg.Write7BitEncodedUInt((uint)idx); return idx; }
internal void SendOptimizeInfo(float roundtrip) { NetMessage ping = new NetMessage(NetMessageType.PingPong, 3); ping.Write(false); // meaningless ping.Write(true); // means optimize info ping.Write7BitEncodedUInt((uint)(roundtrip * 1000.0f)); m_connection.SendMessage(ping, NetChannel.Unreliable); }
/// <summary> /// Returns encoded index /// </summary> public int Write(NetMessage msg, string str) { int idx = m_data.IndexOf(str); if (idx == -1) { idx = m_data.Count; m_data.Add(str); msg.Write(false); msg.Write7BitEncodedUInt((uint)idx); msg.Write(str); return(idx); } msg.Write(true); msg.Write7BitEncodedUInt((uint)idx); return(idx); }
/// <summary> /// Reuses the string table index /// </summary> public int Rewrite(NetMessage msg, int idx, string str) { while (m_data.Count < idx - 1) m_data.Add(null); // dummy values m_data[idx] = str; msg.Write(false); msg.Write7BitEncodedUInt((uint)idx); msg.Write(str); return idx; }
internal static int SendConnect(NetClient client, IPEndPoint remoteEndpoint, byte[] customData) { if (client.Configuration.UsesEncryption) { client.Log.Debug("Sending Connect containing key: " + Convert.ToBase64String(client.ServerConnection.m_encryption.SymmetricEncryptionKeyBytes)); } else { client.Log.Debug("Sending Connect - Unencrypted connection!"); } NetMessage msg = new NetMessage(NetMessageType.Handshake, 3); msg.Write((byte)NetHandshakeType.Connect); msg.WriteSendStamp(); // encrypt symmetric key using server public key if (client.Configuration.UsesEncryption) { byte[] encryptedKey = client.ServerConnection.m_encryption.EncryptRSA(client.ServerConnection.m_encryption.SymmetricEncryptionKeyBytes); msg.Write((ushort)encryptedKey.Length); msg.Write(encryptedKey); } else { // request no encryption msg.Write((ushort)0); } if (customData == null || customData.Length < 1) { msg.Write7BitEncodedUInt(0); } else { msg.Write7BitEncodedUInt((uint)customData.Length); msg.Write(customData); } return(client.SendSingleMessageAtOnce(msg, null, remoteEndpoint)); }
/// <summary> /// Reuses the string table index /// </summary> public int Rewrite(NetMessage msg, int idx, string str) { while (m_data.Count < idx - 1) { m_data.Add(null); // dummy values } m_data[idx] = str; msg.Write(false); msg.Write7BitEncodedUInt((uint)idx); msg.Write(str); return(idx); }
internal void SendOptimizeInfo(float roundtrip) { NetMessage ping = new NetMessage(NetMessageType.PingPong, 3); ping.Write(false); // meaningless ping.Write(true); // means optimize info ping.Write7BitEncodedUInt((uint)(roundtrip * 1000.0f)); m_connection.SendMessage(ping, NetChannel.Unreliable); }
internal static int SendConnect(NetClient client, IPEndPoint remoteEndpoint, byte[] customData) { if (client.Configuration.UsesEncryption) client.Log.Debug("Sending Connect containing key: " + Convert.ToBase64String(client.ServerConnection.m_encryption.SymmetricEncryptionKeyBytes)); else client.Log.Debug("Sending Connect - Unencrypted connection!"); NetMessage msg = new NetMessage(NetMessageType.Handshake, 3); msg.Write((byte)NetHandshakeType.Connect); msg.WriteSendStamp(); // encrypt symmetric key using server public key if (client.Configuration.UsesEncryption) { byte[] encryptedKey = client.ServerConnection.m_encryption.EncryptRSA(client.ServerConnection.m_encryption.SymmetricEncryptionKeyBytes); msg.Write((ushort)encryptedKey.Length); msg.Write(encryptedKey); } else { // request no encryption msg.Write((ushort)0); } if (customData == null || customData.Length < 1) { msg.Write7BitEncodedUInt(0); } else { msg.Write7BitEncodedUInt((uint)customData.Length); msg.Write(customData); } return client.SendSingleMessageAtOnce(msg, null, remoteEndpoint); }