123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- #include "ChatMessage.h"
- #ifndef _WINDOWS
- # include <sys/time.h>
- #endif
- ChatMessage::ChatMessage(Framework::Text message,
- Framework::Text channel,
- Framework::Text targetPlayerName)
- : ReferenceCounter(),
- message(message),
- channel(channel),
- targetPlayerName(targetPlayerName)
- {
- #ifdef _WINDOWS
- struct tm timeinfo;
- std::time(&time);
- gmtime_s(&timeinfo ,& time); /* Convert to UTC */
- time = mktime(&timeinfo); /* Store as unix timestamp */
- #else
- timeval tv;
- gettimeofday(&tv, 0);
- time = tv.tv_sec;
- #endif
- }
- ChatMessage::ChatMessage(Framework::StreamReader* zReader)
- : ReferenceCounter()
- {
- zReader->lese((char*)&time, 8);
- 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
- {
- zWriter->schreibe((char*)&time, 8);
- 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);
- }
|