public ExecutionState <VarLong> ReadVarLong() { long result = 0; int numRead = 0; byte read; do { if (!_connection.DataAvaliable) { return(ExecutionState <VarLong> .Failed("Failed to read VarLong length")); } read = _readByte(); long value = ((byte)read & 0b01111111); result |= value << (7 * numRead); numRead++; if (numRead > 10) { return(ExecutionState <VarLong> .Failed("Length too long")); } ; } while ((read & 0b10000000) != 0); return(ExecutionState <VarLong> .Succeeded(result)); }
private ExecutionState ReadLoginResponce(Connection Sender, ByteReader data) { var sucess = data.ReadBoolean(); if (!sucess) { var dbglvl0 = new Dictionary <string, object> { { "Location", "Tortoise.Client.Module.Login.ReadLoginResponce.1" } }; var dbglvl1 = new Dictionary <string, object>(dbglvl0) { { "length Error", sucess.Reason } }; var dbglvl2 = new Dictionary <string, object>(dbglvl1) { { "ByteReader Dump", data.DumpDebugInfo() } }; Debugging.SyncError(Sender, dbglvl0, dbglvl1, dbglvl2); return(ExecutionState.Failed()); } if (sucess.Result) { LoginStatusScreen.Instance.Text = DefaultLanguage.Strings.GetFormatedString("Login_Status_Sucess"); } else { LoginStatusScreen.Instance.Text = DefaultLanguage.Strings.GetFormatedString("Login_Status_Failure"); } return(ExecutionState.Succeeded()); }
ExecutionState <bool> ReadClientInfo(Connection Sender, ByteReader data) { //(byte major, byte minor, ushort revision) var major = data.ReadByte(); var minor = data.ReadByte(); var build = data.ReadUShort(); var revision = data.ReadUShort(); if (!major || !minor || !build || !revision) { Sender.SyncError("Version Data"); return(ExecutionState <bool> .Failed()); } #if DEBUG if (minor.Result != XML.ServerConfig.Instance.CLientMinor || major.Result != XML.ServerConfig.Instance.ClientMajor ) #else if (revision.Result != XML.ServerConfig.Instance.ClientRevision || build.Result != XML.ServerConfig.Instance.CLientBuild || minor.Result != XML.ServerConfig.Instance.CLientMinor || major.Result != XML.ServerConfig.Instance.ClientMajor ) #endif { Sender.Disconnect(MessageID.OutOfDate); } //Write_TempAuthKey(_authKey); return(ExecutionState <bool> .Succeeded(true)); }
public ExecutionState <byte[]> ReadBytes(int length) { if (!EnforceLength(sizeof(byte) * length)) { return(ExecutionState <byte[]> .Failed("Failed to enforce length of byte[]")); } return(ExecutionState <byte[]> .Succeeded(_connection.ReadBytes(length))); }
public ExecutionState <sbyte> ReadSByte() { if (!EnforceLength(sizeof(sbyte))) { return(ExecutionState <sbyte> .Failed("Failed to enforce length of sbyte")); } return(ExecutionState <sbyte> .Succeeded(Convert.ToSByte(_array[_pos++]))); }
public ExecutionState <sbyte> ReadSByte() { if (!EnforceLength(sizeof(sbyte))) { return(ExecutionState <sbyte> .Failed("Failed to enforce length of sbyte")); } return(ExecutionState <sbyte> .Succeeded((sbyte)_readByte())); }
public ExecutionState <byte> ReadByte() { if (!EnforceLength(sizeof(byte))) { return(ExecutionState <byte> .Failed("Failed to enforce length of byte")); } return(ExecutionState <byte> .Succeeded(_array[_pos++])); }
private ExecutionState EnforceLength(int length) { if (_pos + length > _array.Length) { return(ExecutionState.Failed()); } return(ExecutionState.Succeeded()); }
private ExecutionState EnforceLength(int length) { if (length > _connection.BytesAvaliable) { return(ExecutionState.Failed()); } return(ExecutionState.Succeeded()); }
public static ExecutionState <object> Select(this object source, object obja) { if (source == obja) { return(new ExecutionState <object>(true, source)); } return(ExecutionState <object> .Failed()); }
public static ExecutionState <object> Select(this object source, params object[] objs) { if (objs.Contains(source)) { return(new ExecutionState <object>(true, source)); } return(ExecutionState <object> .Failed()); }
public static ExecutionState <object> Select(this object source, object obja, object objb) { if (source.Equals(obja) || source.Equals(objb)) { return(new ExecutionState <object>(true, source)); } return(ExecutionState <object> .Failed()); }
public ExecutionState <byte> ReadByte(bool peek = false) { if (!EnforceLength(sizeof(byte))) { return(ExecutionState <byte> .Failed("Failed to enforce length of byte")); } return(ExecutionState <byte> .Succeeded(_readByte(peek))); }
public ExecutionState <bool> ReadBoolean() { if (!EnforceLength(sizeof(bool))) { return(ExecutionState <bool> .Failed("Failed to enforce length of bool")); } var result = ExecutionState <bool> .Succeeded(_readByte() != 0); return(result); }
public ExecutionState <ulong> ReadULong() { if (!EnforceLength(sizeof(ulong))) { return(ExecutionState <ulong> .Failed("Failed to enforce length of ulong")); } var result = ExecutionState <ulong> .Succeeded(_readUInt64()); return(result); }
public ExecutionState <short> ReadShort() { if (!EnforceLength(sizeof(short))) { return(ExecutionState <short> .Failed("Failed to enforce length of short")); } var result = ExecutionState <short> .Succeeded((short)_readUInt16()); return(result); }
public ExecutionState <uint> ReadUInt() { if (!EnforceLength(sizeof(uint))) { return(ExecutionState <uint> .Failed("Failed to enforce length of uint")); } var result = ExecutionState <uint> .Succeeded(_readUInt32()); return(result); }
public ExecutionState <short> ReadShort() { if (!EnforceLength(sizeof(ushort))) { return(ExecutionState <short> .Failed("Failed to enforce length of short")); } var result = ExecutionState <short> .Succeeded(BitConverter.ToInt16(_array, _pos)); _pos += sizeof(ushort); return(result); }
public ExecutionState <byte[]> ReadBytes(int length) { if (!EnforceLength(sizeof(byte) * length)) { return(ExecutionState <byte[]> .Failed("Failed to enforce length of byte[]")); } byte[] returnValue = new byte[length]; Array.Copy(_array, _pos, returnValue, 0, length); _pos++; return(ExecutionState <byte[]> .Succeeded(returnValue)); }
public unsafe ExecutionState <float> ReadSingle() { if (!EnforceLength(sizeof(float))) { return(ExecutionState <float> .Failed("Failed to enforce length of float")); } uint value = _readUInt32(); var result = ExecutionState <float> .Succeeded(*(float *)&value); return(result); }
public ExecutionState <ulong> ReadULong() { if (!EnforceLength(sizeof(ulong))) { return(ExecutionState <ulong> .Failed("Failed to enforce length of ulong")); } var result = ExecutionState <ulong> .Succeeded(BitConverter.ToUInt64(_array, _pos)); _pos += sizeof(ulong); return(result); }
public ExecutionState <bool> ReadBoolean() { if (!EnforceLength(sizeof(bool))) { return(ExecutionState <bool> .Failed("Failed to enforce length of bool")); } var result = ExecutionState <bool> .Succeeded(BitConverter.ToBoolean(_array, _pos)); _pos += sizeof(bool); return(result); }
public ExecutionState <float> ReadSingle() { if (!EnforceLength(sizeof(float))) { return(ExecutionState <float> .Failed("Failed to enforce length of float")); } var result = ExecutionState <float> .Succeeded(BitConverter.ToSingle(_array, _pos)); _pos += sizeof(float); return(result); }
public unsafe ExecutionState <double> ReadDouble() { if (!EnforceLength(sizeof(double))) { return(ExecutionState <double> .Failed("Failed to enforce length of double")); } ulong value = _readUInt64(); var result = ExecutionState <double> .Succeeded(*(double *)&value); return(result); }
public ExecutionState <uint> ReadUInt() { if (!EnforceLength(sizeof(uint))) { return(ExecutionState <uint> .Failed("Failed to enforce length of uint")); } var result = ExecutionState <uint> .Succeeded(BitConverter.ToUInt32(_array, _pos)); _pos += sizeof(uint); return(result); }
public ExecutionState <double> ReadDouble() { if (!EnforceLength(sizeof(double))) { return(ExecutionState <double> .Failed("Failed to enforce length of double")); } var result = ExecutionState <double> .Succeeded(BitConverter.ToDouble(_array, _pos)); _pos += sizeof(double); return(result); }
ExecutionState CheckConsoleInput(string input) { input = input.Trim(); switch (input) { case "0": case "1": case "2": return(ExecutionState.Succeeded()); default: return(ExecutionState.Failed("Input must be 0, 1, or 2")); } }
public ExecutionState StatusEvent(object sender, T args) { LinkedListNode <_statusEventData> node = _statusEvents.First; while (node != null) { if (node.Value.function(sender, args)) { return(ExecutionState.Succeeded()); } node = node.Next; } return(ExecutionState.Failed()); }
public ExecutionState <string> ReadString() { var stateLen = ReadUShort(); if (!stateLen) { return(ExecutionState <string> .Failed("Failed to read Length")); } ushort length = stateLen.Result; var stateData = ReadBytes(length); if (!stateData) { return(ExecutionState <string> .Failed("Failed to read Data off of length")); } return(ExecutionState <string> .Succeeded(_encoder.GetString(stateData.Result))); }
private ExecutionState ReadAuthKey(Connection Sender, ByteReader data) { var length = data.ReadUShort(); if (!length) { var dbglvl0 = new Dictionary <string, object> { { "Location", "Tortoise.Client.Module.Login.ReadAuthKey.1" } }; var dbglvl1 = new Dictionary <string, object>(dbglvl0) { { "length Error", length.Reason } }; var dbglvl2 = new Dictionary <string, object>(dbglvl1) { { "ByteReader Dump", data.DumpDebugInfo() } }; Debugging.SyncError(Sender, dbglvl0, dbglvl1, dbglvl2); return(ExecutionState.Failed()); } var key = data.ReadBytes(length.Result); if (!key) { var dbglvl0 = new Dictionary <string, object> { { "Location", "Tortoise.Client.Module.Login.ReadAuthKey.2" } }; var dbglvl1 = new Dictionary <string, object>(dbglvl0) { { "key Error", key.Reason } }; var dbglvl2 = new Dictionary <string, object>(dbglvl1) { { "ByteReader Dump", data.DumpDebugInfo() } }; Debugging.SyncError(Sender, dbglvl0, dbglvl1, dbglvl2); return(ExecutionState.Failed()); } AuthKey = key.Result; return(ExecutionState.Succeeded()); }