protected override void Decode(ByteList bytes) { Log.Debug("Decode a AnswerMessage"); if (bytes == null || !bytes.IsMore) { return; } GameId = bytes.GetShort(); Log.DebugFormat("Decoded GameId = {0}", GameId); if (!bytes.IsMore) { return; } Result = (bytes.GetByte() == 1); Log.DebugFormat("Decoded Result = {0}", Result); if (!bytes.IsMore) { return; } Score = bytes.GetShort(); Log.DebugFormat("Decoded Score = {0}", Score); if (!bytes.IsMore) { return; } Hint = bytes.GetString(); Log.DebugFormat("Decoded Hint = {0}", Hint); }
protected override void Decode(ByteList bytes) { Log.Debug("Decode an GameDef"); if (bytes == null || !bytes.IsMore) { return; } GameId = bytes.GetShort(); Log.DebugFormat("Decoded GameId = {0}", GameId); if (!bytes.IsMore) { return; } Hint = bytes.GetString(); Log.DebugFormat("Decoded Hint = {0}", Hint); if (!bytes.IsMore) { return; } Definition = bytes.GetString(); Log.DebugFormat("Decoded Definition = {0}", Definition); }
protected override void Decode(ByteList bytes) { Log.Debug("Decode an HeartbeatMessage"); if (bytes == null || !bytes.IsMore) { return; } GameId = bytes.GetShort(); Log.DebugFormat("Decoded GameId = {0}", GameId); }
protected override void Decode(ByteList bytes) { Log.Debug("Decode an ErrorMessage"); if (bytes == null || !bytes.IsMore) { return; } GameId = bytes.GetShort(); Log.DebugFormat("Decoded GameId = {0}", GameId); if (!bytes.IsMore) { return; } ErrorText = bytes.GetString(); Log.DebugFormat("Decoded ErrorText = {0}", ErrorText); }
protected override void Decode(ByteList bytes) { Log.Debug("Decode an GuessMessage"); if (bytes == null || !bytes.IsMore) { return; } GameId = bytes.GetShort(); Log.DebugFormat("Decoded GameId = {0}", GameId); if (!bytes.IsMore) { return; } Log.Debug("Try to get the FirstName"); if (bytes.PeekShort() < 0 && bytes.PeekShort() > 40) { Log.WarnFormat("The length of the encoded Word, {0}, is probably not correct. Check how you are encoding the string's length", bytes.PeekShort()); } Word = bytes.GetString(); Log.DebugFormat("Decoded Word = {0}", Word); }
public static Message Create(byte[] receivedBytes) { Message result = null; if (receivedBytes != null && receivedBytes.Length >= 2) { ByteList bytes = new ByteList(receivedBytes); PossibleMessageTypes messageType = (PossibleMessageTypes)bytes.GetShort(); switch (messageType) { case PossibleMessageTypes.NewGame: result = new NewGameMessage(); break; case PossibleMessageTypes.GameDef: result = new GameDef(); break; case PossibleMessageTypes.Guess: result = new GuessMessage(); break; case PossibleMessageTypes.Answer: result = new AnswerMessage(); break; case PossibleMessageTypes.GetHint: result = new GetHintMessage(); break; case PossibleMessageTypes.Hint: result = new HintMessage(); break; case PossibleMessageTypes.Error: result = new ErrorMessage(); break; case PossibleMessageTypes.Exit: result = new ExitMessage(); break; case PossibleMessageTypes.Heartbeat: result = new HeartbeatMessage(); break; case PossibleMessageTypes.Ack: result = new AckMessage(); break; case PossibleMessageTypes.GetStatus: result = new GetStatusMessage(); break; case PossibleMessageTypes.Status: result = new StatusMessage(); break; } try { result?.Decode(bytes); } catch (Exception err) { Log.ErrorFormat("Cannot decode a {0} message", result?.GetType().Name); Log.ErrorFormat("Inner Error: {0}", err.Message); } } return(result); }