12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- #include "ChatMessage.h"
- #include <sys/time.h>
- ChatMessage::ChatMessage(Framework::Text message,
- Framework::Text channel,
- Framework::Text targetPlayerName)
- : ReferenceCounter(),
- message(message),
- channel(channel),
- targetPlayerName(targetPlayerName)
- {
- timeval tv;
- gettimeofday(&tv, 0);
- time = tv.tv_sec;
- }
- ChatMessage::ChatMessage(Framework::StreamReader* zReader)
- : ReferenceCounter()
- {
- short len;
- zReader->lese((char*)&len, 2);
- char* buffer = new char[len + 1];
- zReader->lese(buffer, len);
- buffer[len] = 0;
- message = buffer;
- delete[] buffer;
- char channelLen;
- zReader->lese(&channelLen, 1);
- buffer = new char[channelLen + 1];
- zReader->lese(buffer, channelLen);
- buffer[(int)channelLen] = 0;
- channel = buffer;
- delete[] buffer;
- zReader->lese(&channelLen, 1);
- buffer = new char[channelLen + 1];
- zReader->lese(buffer, channelLen);
- buffer[(int)channelLen] = 0;
- targetPlayerName = buffer;
- delete[] buffer;
- }
- Framework::Text ChatMessage::getChannel() const
- {
- return channel;
- }
- Framework::Text ChatMessage::getTargetPlayerName() const
- {
- return targetPlayerName;
- }
- void ChatMessage::writeTo(Framework::StreamWriter* zWriter) const
- {
- short mLen = (short)message.getLength();
- zWriter->schreibe((char*)&mLen, 2);
- zWriter->schreibe(message.getText(), mLen);
- char len = (char)channel.getLength();
- zWriter->schreibe(&len, 1);
- zWriter->schreibe(channel.getText(), len);
- len = (char)targetPlayerName.getLength();
- zWriter->schreibe(&len, 1);
- zWriter->schreibe(targetPlayerName.getText(), len);
- }
|