public bool SendToServer(ref LoginSocketState state, byte[] data, int count) { if (data == null || state == null || state.ServerSocket == null) { return(false); } var bytes = new byte[count]; Array.Copy(data, bytes, count); var str = DataFunctions.BytesToString(bytes); Log(Category, "RETR >> " + str); if (str.StartsWith("\\login\\") || str.StartsWith("\\newuser\\")) { str = AddSteamIdBeforeFinal(str, "\\final\\"); data = DataFunctions.StringToBytes(str); count = data.Length; Log(Category, "RETRCHANGED >> " + str); } try { state.ServerSocket.BeginSend(data, 0, count, SocketFlags.None, OnToServerSent, state); return(true); } catch (NullReferenceException) { if (state != null) { state.Dispose(); } state = null; return(false); } catch (SocketException e) { if (e.SocketErrorCode != SocketError.ConnectionAborted && e.SocketErrorCode != SocketError.ConnectionReset) { LogError(Category, "Error sending data"); LogError(Category, String.Format("{0} {1}", e.SocketErrorCode, e)); } if (state != null) { state.Dispose(); } state = null; return(false); } catch (Exception ex) { LogError(Category, "Error receiving data"); LogError(Category, ex.ToString()); } return(false); }
public static int GsEncode(ref string password) { byte[] pass = DataFunctions.StringToBytes(password); int i; int a; int c; int d; int num = 0x79707367; // "gspy" int passlen = pass.Length; if (num == 0) { num = 1; } else { num &= 0x7fffffff; } for (i = 0; i < passlen; i++) { d = 0xff; c = 0; d -= c; if (d != 0) { num = GsLame(num); a = num % d; a += c; } else { a = c; } pass[i] ^= (byte)(a % 256); } password = DataFunctions.BytesToString(pass); return(passlen); }
public bool SendToClient(ref LoginSocketState state, byte[] data) { if (data == null || state == null || state.Socket == null) { return(false); } Logger.Info($"RESP: {DataFunctions.BytesToString(data)}"); try { state.Socket.BeginSend(data, 0, data.Length, SocketFlags.None, OnSent, state); return(true); } catch (NullReferenceException) { if (state != null) { state.Dispose(); } state = null; return(false); } catch (SocketException e) { if (e.SocketErrorCode != SocketError.ConnectionAborted && e.SocketErrorCode != SocketError.ConnectionReset) { Logger.Error(e, $"Error sending data. SocketErrorCode: {e.SocketErrorCode}"); } if (state != null) { state.Dispose(); } state = null; return(false); } }
public static string GsBase64Decode(string s, int size) { byte[] data = DataFunctions.StringToBytes(s); int len; int xlen; int a = 0; int b = 0; int c = 0; int step; int limit; int y = 0; int z = 0; byte[] buff; byte[] p; char[] basechars = new char[128] { // supports also the Gamespy base64 '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x3e', '\x00', '\x00', '\x00', '\x3f', '\x34', '\x35', '\x36', '\x37', '\x38', '\x39', '\x3a', '\x3b', '\x3c', '\x3d', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0a', '\x0b', '\x0c', '\x0d', '\x0e', '\x0f', '\x10', '\x11', '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18', '\x19', '\x3e', '\x00', '\x3f', '\x00', '\x00', '\x00', '\x1a', '\x1b', '\x1c', '\x1d', '\x1e', '\x1f', '\x20', '\x21', '\x22', '\x23', '\x24', '\x25', '\x26', '\x27', '\x28', '\x29', '\x2a', '\x2b', '\x2c', '\x2d', '\x2e', '\x2f', '\x30', '\x31', '\x32', '\x33', '\x00', '\x00', '\x00', '\x00', '\x00' }; if (size <= 0) { len = data.Length; } else { len = size; } xlen = ((len >> 2) * 3) + 1; buff = new byte[xlen % 256]; if (buff.Length == 0) { return(null); } p = buff; limit = data.Length + len; for (step = 0; ; step++) { do { if (z >= limit) { c = 0; break; } if (z < data.Length) { c = data[z]; } else { c = 0; } z++; if ((c == '=') || (c == '_')) { c = 0; break; } } while (c != 0 && ((c <= (byte)' ') || (c > 0x7f))); if (c == 0) { break; } switch (step & 3) { case 0: a = basechars[c]; break; case 1: b = basechars[c]; p[y++] = (byte)(((a << 2) | (b >> 4)) % 256); break; case 2: a = basechars[c]; p[y++] = (byte)((((b & 15) << 4) | (a >> 2)) % 256); break; case 3: p[y++] = (byte)((((a & 3) << 6) | basechars[c]) % 256); break; default: break; } } p[y] = 0; len = p.Length - buff.Length; if (size != 0) { size = len; } if ((len + 1) != xlen) { if (buff.Length == 0) { return(null); } } return(DataFunctions.BytesToString(buff).Substring(0, y)); }