Last active
August 29, 2015 14:01
-
-
Save abma/2e1c34be119c947fefd2 to your computer and use it in GitHub Desktop.
.net getlobbyid (spring lobby protcol)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Net.NetworkInformation; | |
namespace LobbyClient { | |
using System; | |
public class Crc32 { | |
static uint[] table; | |
static public uint ComputeChecksum(byte[] bytes) { | |
uint crc = 0xffffffff; | |
for(int i = 0; i < bytes.Length; ++i) { | |
byte index = (byte)(((crc) & 0xff) ^ bytes[i]); | |
crc = (uint)((crc >> 8) ^ table[index]); | |
} | |
return ~crc; | |
} | |
static Crc32() { | |
uint poly = 0xedb88320; | |
table = new uint[256]; | |
uint temp = 0; | |
for(uint i = 0; i < table.Length; ++i) { | |
temp = i; | |
for(int j = 8; j > 0; --j) { | |
if((temp & 1) == 1) { | |
temp = (uint)((temp >> 1) ^ poly); | |
}else { | |
temp >>= 1; | |
} | |
} | |
table[i] = temp; | |
} | |
} | |
} | |
} | |
public class Crc | |
{ | |
public static string GetMyUserID() { | |
var nics = NetworkInterface.GetAllNetworkInterfaces().Where(x=> !String.IsNullOrWhiteSpace(x.GetPhysicalAddress().ToString()) | |
&& x.NetworkInterfaceType != NetworkInterfaceType.Loopback && x.NetworkInterfaceType != NetworkInterfaceType.Tunnel); | |
var wantedNic = nics.FirstOrDefault(); | |
if (wantedNic != null) | |
{ | |
return LobbyClient.Crc32.ComputeChecksum(wantedNic.GetPhysicalAddress().GetAddressBytes()).ToString(); | |
} | |
return "0"; | |
} | |
public static void Main() | |
{ | |
System.Console.WriteLine(GetMyUserID()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment