/// <summary> /// Handle a message from the messagebuffer /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void OnRecvReaderProcessMessage(object sender, MessageBufferEventArgs e) { if (e.Length > MessageHeader.Tcp.HEADERLENGTH) { // save encoded type byte encodedType = e.MessageBuffer[MessageHeader.Tcp.HEADERLENGTH]; // decode type e.MessageBuffer[MessageHeader.Tcp.HEADERLENGTH] = PIDecoder.Decode(encodedType); try { // mark as incoming message e.Direction = MessageDirection.ServerToClient; // parse the message to a typed instance GameMessage typedMessage = ExtractMessage(e); // set encoded pi and memoryaddres typedMessage.EncryptedPI = encodedType; typedMessage.Header.MemoryStartAddress = e.MemoryAddress; // examine serversave value CheckServerSave(typedMessage); // trigger event for this new message OnNewMessageAvailable(new GameMessageEventArgs(typedMessage)); } catch (Exception Error) { byte[] dump = new byte[e.Length]; Array.Copy(e.MessageBuffer, 0, dump, 0, e.Length); OnHandlerError(new HandlerErrorEventArgs(dump, Error.Message)); } } else { OnEmptyPacketFound(new EmptyMessageFoundEventArgs()); } }
/// <summary> /// Resets the PacketController to initial state /// </summary> public virtual void Reset() { CurrentServerSave = 0x00; LastServerSave = 0x00; PIDecoder = new PIDecoder(stringResources); CRCCreator = new CRCCreator(); CRCCreatorEnabled = false; Mode = ProtocolMode.Login; }