private void OnApproved(Message packet) { try { using (var approval = Approval.Deserialize(packet.read)) { ConsoleSystem.LogWarning( $"[VirtualServer]: Подключились к: {(approval.official ? "[Oficial] " : "")}" + approval.hostname); if (_quitAfterConnected) { BaseClient.Disconnect("", true); Framework.Quit(); } BaseClient.Connection.encryptionLevel = approval.encryption; BaseClient.Connection.decryptIncoming = true; if (BaseClient.write.Start()) { BaseClient.write.PacketId(Message.Type.Ready); BaseClient.write.Send(new SendInfo(BaseClient.Connection)); } packet.connection.encryptOutgoing = true; } } catch (Exception ex) { ConsoleSystem.LogError("[VirtualServer]: Исключение в OnApproved(): " + ex.Message); } }
public void SendPacket(NetworkPeer peer, Message message) { message.peer.read.Position = 0L; using (var br = new BinaryReader(message.peer.read)) { peer.write.Start(); peer.write.Write(br.ReadBytes((int)message.peer.read.Length), 0, (int)message.peer.read.Length); peer.write.Send(new SendInfo(BaseClient.Connection)); } }
public byte[] GetPacketBytes(Message message) { byte[] buffer = null; var startPos = message.read.Position; message.peer.read.Position = 0L; using (var br = new BinaryReader(message.peer.read)) { buffer = br.ReadBytes((int)message.peer.read.Length); } message.read.Position = startPos; return(buffer); }
public void IN_OnNetworkMessage(Message packet) { // if (packet.type != Message.Type.Entities && packet.type != Message.Type.Tick && // packet.type != Message.Type.EAC // && packet.type != Message.Type.EntityPosition && packet.type != Message.Type.GroupEnter && // packet.type != Message.Type.GroupDestroy && packet.type != Message.Type.GroupLeave) // { // // if (packet.type == Message.Type.RPCMessage) // { // UInt32 UID = packet.read.EntityID(); // UInt32 rpcId = packet.read.UInt32(); // packet.read.UInt64(); // ConsoleSystem.Log($"IN RPC => {pooledStrings[rpcId]} - {rpcId}"); // }else if (packet.type == Message.Type.ConsoleCommand) // { //// ConsoleSystem.Log($"IN COMMAND => {packet.read.String()}"); // }else // ConsoleSystem.Log($"IN => {packet.type}"); // } switch (packet.type) { case Message.Type.Approved: OnApproved(packet); break; case Message.Type.RequestUserInformation: ConnectionInformation = new UserInformation { Branch = "", ConnectionProtocol = 2155, Os = "editor", PacketProtocol = 228, SteamId = _steamId, Username = _username, SteamToken = _token }; if (BaseClient.write.Start()) { BaseClient.write.PacketId(Message.Type.GiveUserInformation); ConnectionInformation.Write(BaseClient); BaseClient.Send(); } break; case Message.Type.ConsoleCommand: string command = packet.read.String(); if (command == "sfk.gosleep") { BaseClient.Disconnect("", true); ConsoleSystem.Log("[GOSLEEP]"); Framework.Quit(); } break; case Message.Type.DisconnectReason: packet.read.Position = 1L; var reasone = packet.read.String(); ConsoleSystem.LogWarning("[VirtualServer]: От игрового сервера получена причина дисконнекта: " + reasone); break; } }