Example #1
0
 private void AppendServerProperty(StringBuilder builder, string name)
 {
     builder.Append("\0");
     builder.Append(name);
     builder.Append("\0");
     builder.Append(AttachedServer?.GetByName(name) ?? string.Empty);
 }
Example #2
0
        private void OnDataReceived(object sender, SocketAsyncEventArgs e)
        {
            if (RemoteUserSteamId == CSteamID.Nil)
            {
                return;
            }

            try
            {
                LocalPoint = e.RemoteEndPoint as IPEndPoint;
                var count = (uint)e.BytesTransferred;

                byte[] receivedBytes = new byte[e.BytesTransferred];
                Array.Copy(e.Buffer, e.Offset, receivedBytes, 0, e.BytesTransferred);

                var str = Encoding.UTF8.GetString(receivedBytes);

                // there by a bunch of different message formats...

                //Log(Category, $">> {RemoteUserSteamId} "+str);
                //Log(Category, ">> BYTES:" + string.Join(" ", receivedBytes.Select(x => x.ToString())));

                //Console.WriteLine("SendTo "+ _userId.m_SteamID+" "+ e.BytesTransferred);
                // IPEndPoint remote = (IPEndPoint)e.RemoteEndPoint;

                // "��\0���J���\u0001"
                //  ��\0�z�J���\u0001
                // "254 253 0 247 122 228 74 255 255 255 1"
                // "254 253 0 170 87 26 75 255 255 255 1"
                // Fake host response to speed up connection

                try
                {
                    if (count == 11 &&
                        e.Buffer[0] == 254 &&
                        e.Buffer[1] == 253 &&
                        e.Buffer[2] == 0 &&
                        // e.Buffer[3] == 247 &&
                        // e.Buffer[4] == 122 &&
                        // e.Buffer[5] == 228 &&
                        // e.Buffer[6] == 228 &&
                        e.Buffer[7] == 255 &&
                        e.Buffer[8] == 255 &&
                        e.Buffer[9] == 255 &&
                        e.Buffer[10] == 1)
                    {
                        // Log(Category, ">> REQUEST BYTES:" + string.Join(" ", receivedBytes.Select(x => x.ToString())));

                        var builder = new StringBuilder("\0$��Jsplitnum\0�");

                        AppendServerProperty(builder, "numplayers");
                        AppendServerProperty(builder, "maxplayers");
                        AppendServerProperty(builder, "hostname");
                        AppendServerProperty(builder, "hostport", Port.ToString());
                        AppendServerProperty(builder, "mapname");
                        AppendServerProperty(builder, "password");
                        AppendServerProperty(builder, "gamever");
                        AppendServerProperty(builder, "numplayers");
                        AppendServerProperty(builder, "maxplayers");
                        AppendServerProperty(builder, "score_");
                        AppendServerProperty(builder, "teamplay");
                        AppendServerProperty(builder, "gametype");
                        AppendServerProperty(builder, "gamevariant");
                        AppendServerProperty(builder, "groupid");
                        AppendServerProperty(builder, "numobservers");
                        AppendServerProperty(builder, "maxobservers");
                        AppendServerProperty(builder, "modname");
                        AppendServerProperty(builder, "moddisplayname");
                        AppendServerProperty(builder, "modversion");
                        AppendServerProperty(builder, "devmode");

                        for (int i = 0; i < 32; i++)
                        {
                            AppendServerProperty(builder, "gametype" + i);
                        }

                        var hostname = AttachedServer?.GetByName("hostname") ?? string.Empty;
                        builder.Append($"\u0001player_\0\0{hostname}\0\0ping_\0\00\0\0player_\0\0{hostname}\0\0\0\u0002\0");

                        var fakeString = builder.ToString();
                        var bytes      = Encoding.UTF8.GetBytes(fakeString);

                        // unique Id
                        bytes[1] = e.Buffer[3];
                        bytes[2] = e.Buffer[4];
                        bytes[3] = e.Buffer[5];
                        bytes[4] = e.Buffer[6];

                        // 172 164 27 75

                        Console.WriteLine("SERVER FAKE " + fakeString);

                        _socket?.SendTo(bytes, bytes.Length, SocketFlags.None, LocalPoint ?? GameEndPoint);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }

                SteamNetworking.SendP2PPacket(RemoteUserSteamId, e.Buffer, count, EP2PSend.k_EP2PSendReliable);
            }
            catch (Exception ex)
            {
                LogError(Category, ex.ToString());
            }

            WaitForData();
        }