mirror of
https://github.com/SWG-Source/src.git
synced 2026-07-29 23:15:56 -04:00
Added ChatServer and soePlatform
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
|
||||
add_subdirectory(ChatServer)
|
||||
add_subdirectory(ConnectionServer)
|
||||
add_subdirectory(LoginServer)
|
||||
add_subdirectory(LogServer)
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
|
||||
cmake_minimum_required(VERSION 2.8)
|
||||
|
||||
project(ChatServer)
|
||||
|
||||
add_subdirectory(src)
|
||||
@@ -0,0 +1,122 @@
|
||||
|
||||
set(SHARED_SOURCES
|
||||
shared/CentralServerConnection.cpp
|
||||
shared/CentralServerConnection.h
|
||||
shared/ChatInterface.cpp
|
||||
shared/ChatInterface.h
|
||||
shared/ChatServerAvatarOwner.cpp
|
||||
shared/ChatServerAvatarOwner.h
|
||||
shared/ChatServer.cpp
|
||||
shared/ChatServer.h
|
||||
shared/ChatServerRoomOwner.cpp
|
||||
shared/ChatServerRoomOwner.h
|
||||
shared/ConfigChatServer.cpp
|
||||
shared/ConfigChatServer.h
|
||||
shared/ConnectionServerConnection.cpp
|
||||
shared/ConnectionServerConnection.h
|
||||
shared/CustomerServiceServerConnection.cpp
|
||||
shared/CustomerServiceServerConnection.h
|
||||
shared/FirstChatServer.cpp
|
||||
shared/FirstChatServer.h
|
||||
shared/GameServerConnection.cpp
|
||||
shared/GameServerConnection.h
|
||||
shared/PlanetServerConnection.h
|
||||
shared/PlanetServerServerConnection.cpp
|
||||
shared/ChatServerMetricsData.cpp
|
||||
shared/ChatServerMetricsData.h
|
||||
shared/VChatInterface.h
|
||||
shared/VChatInterface.cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(PLATFORM_SOURCES
|
||||
win32/WinMain.cpp
|
||||
)
|
||||
else()
|
||||
set(PLATFORM_SOURCES
|
||||
linux/main.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/shared
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedCommandParser/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedCompression/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDatabaseInterface/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedDebug/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFile/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundation/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedFoundationTypes/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedGame/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedLog/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMath/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMemoryManager/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedMessageDispatch/include/public
|
||||
${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetwork/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedNetworkMessages/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedRandom/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedSynchronization/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedThread/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/shared/library/sharedUtility/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/server/library/serverKeyShare/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/server/library/serverNetworkMessages/include/public
|
||||
#${SWG_ENGINE_SOURCE_DIR}/server/library/serverUtility/include/public
|
||||
${SWG_EXTERNALS_SOURCE_DIR}/ours/library/archive/include
|
||||
#${SWG_EXTERNALS_SOURCE_DIR}/ours/library/localization/include
|
||||
#${SWG_EXTERNALS_SOURCE_DIR}/ours/library/localizationArchive/include/public
|
||||
#${SWG_EXTERNALS_SOURCE_DIR}/ours/library/singleton/include
|
||||
#${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicode/include
|
||||
#${SWG_EXTERNALS_SOURCE_DIR}/ours/library/unicodeArchive/include/public
|
||||
#${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/platform/projects
|
||||
#${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/platform/utils
|
||||
#${SWG_EXTERNALS_SOURCE_DIR}/3rd/library/udplibrary
|
||||
)
|
||||
|
||||
link_directories(${STLPORT_LIBDIR})
|
||||
|
||||
add_executable(ChatServer
|
||||
${SHARED_SOURCES}
|
||||
${PLATFORM_SOURCES}
|
||||
)
|
||||
|
||||
target_link_libraries(ChatServer
|
||||
# sharedCommandParser
|
||||
# sharedCompression
|
||||
# sharedDatabaseInterface
|
||||
# sharedDatabaseInterface_oci
|
||||
# sharedDebug
|
||||
# sharedFile
|
||||
# sharedFoundation
|
||||
# sharedGame
|
||||
# sharedLog
|
||||
# sharedMath
|
||||
# sharedMemoryManager
|
||||
# sharedMessageDispatch
|
||||
# sharedNetwork
|
||||
# sharedNetworkMessages
|
||||
# sharedRandom
|
||||
# sharedSynchronization
|
||||
# sharedThread
|
||||
# sharedUtility
|
||||
# serverKeyShare
|
||||
# serverNetworkMessages
|
||||
# serverUtility
|
||||
# archive
|
||||
# crypto
|
||||
# fileInterface
|
||||
# localization
|
||||
# localizationArchive
|
||||
# unicode
|
||||
# unicodeArchive
|
||||
# Base
|
||||
# CommonAPI
|
||||
# LoginAPI
|
||||
# MonAPI2
|
||||
# udplibrary
|
||||
# ${ZLIB_LIBRARY}
|
||||
# ${ORACLE_LIBRARY}
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
target_link_libraries(ChatServer mswsock ws2_32)
|
||||
endif()
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "FirstChatServer.h"
|
||||
|
||||
#include "ConfigChatServer.h"
|
||||
#include "ChatServer.h"
|
||||
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFile/SetupSharedFile.h"
|
||||
#include "sharedFoundation/Os.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedRandom/SetupSharedRandom.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
|
||||
// ======================================================================
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
setupFoundationData.lpCmdLine = ConvertCommandLine(argc,argv);
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
|
||||
SetupSharedCompression::install();
|
||||
|
||||
SetupSharedFile::install(false);
|
||||
SetupSharedNetworkMessages::install();
|
||||
|
||||
SetupSharedRandom::install(static_cast<uint32>(time(NULL))); //lint !e1924 !e64 // NULL is a C-Style cast?
|
||||
|
||||
Os::setProgramName("ChatServer");
|
||||
//setup the server
|
||||
ConfigChatServer::install();
|
||||
|
||||
//-- run game
|
||||
ChatServer::run();
|
||||
SetupSharedFoundation::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
// CentralServerConnection.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "Archive/ByteStream.h"
|
||||
#include "CentralServerConnection.h"
|
||||
#include "ChatServer.h"
|
||||
#include "ChatInterface.h"
|
||||
#include "ConfigChatServer.h"
|
||||
#include "serverNetworkMessages/EnumerateServers.h"
|
||||
#include "serverNetworkMessages/RenameCharacterMessage.h"
|
||||
#include "serverNetworkMessages/TransferCharacterData.h"
|
||||
#include "serverNetworkMessages/TransferCharacterDataArchive.h"
|
||||
#include "sharedFoundation/ConfigFile.h"
|
||||
#include "sharedFoundation/NetworkIdArchive.h"
|
||||
#include "sharedLog/Log.h"
|
||||
#include "sharedNetworkMessages/GenericValueTypeMessage.h"
|
||||
#include "sharedMessageDispatch/Transceiver.h"
|
||||
#include "sharedNetwork/NetworkSetupData.h"
|
||||
#include "sharedNetwork/Service.h"
|
||||
#include "UnicodeUtils.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
CentralServerConnection::CentralServerConnection(const std::string & a, const unsigned short p) :
|
||||
ServerConnection(a, p, NetworkSetupData())
|
||||
{
|
||||
ChatServer::fileLog(true, "CentralServerConnection", "Connection created...listening on (%s:%d)", a.c_str(), static_cast<int>(p));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
CentralServerConnection::~CentralServerConnection()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void CentralServerConnection::onConnectionClosed()
|
||||
{
|
||||
ChatServer::fileLog(true, "CentralServerConnection", "onConnectionClosed()");
|
||||
|
||||
ChatServer::onCentralServerConnectionClosed();
|
||||
ChatServer::quit();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void CentralServerConnection::onConnectionOpened()
|
||||
{
|
||||
ChatServer::fileLog(true, "CentralServerConnection", "onConnectionOpened()");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void CentralServerConnection::onReceive(const Archive::ByteStream & message)
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
GameNetworkMessage m(ri);
|
||||
|
||||
ri = message.begin();
|
||||
|
||||
if(m.isType("EnumerateServers"))
|
||||
{
|
||||
static MessageDispatch::Transceiver<const EnumerateServers &> emitter;
|
||||
|
||||
EnumerateServers e(ri);
|
||||
emitter.emitMessage(e);
|
||||
}
|
||||
else if (m.isType("CustomerServiceServerChatServerServiceAddress"))
|
||||
{
|
||||
GenericValueTypeMessage<std::pair<std::string, unsigned short> > msg(ri);
|
||||
|
||||
ChatServer::instance().connectToCustomerServiceServer(msg.getValue().first, msg.getValue().second);
|
||||
}
|
||||
else if(m.isType("RequestChatTransferAvatar"))
|
||||
{
|
||||
GenericValueTypeMessage<TransferCharacterData> request(ri);
|
||||
LOG("CustomerService", ("CharacterTransfer: Received RequestChatTransferAvatar from CentralServer. Forwarding request to ChatAPI. %s", request.getValue().toString().c_str()));
|
||||
ChatServer::requestTransferAvatar(request.getValue());
|
||||
}
|
||||
else if (m.isType("RenameCharacterMessageEx"))
|
||||
{
|
||||
RenameCharacterMessageEx const msg(ri);
|
||||
|
||||
// if the player requested the rename, also rename the chat
|
||||
// avatar, so mail, friends list, and ignore list will migrate
|
||||
if ((msg.getRenameCharacterMessageSource() == RenameCharacterMessageEx::RCMS_player_request) && !msg.getLastNameChangeOnly() && !ConfigFile::getKeyBool("CharacterRename", "disableRenameChatAvatar", false))
|
||||
{
|
||||
std::string const oldName(Unicode::toLower(Unicode::wideToNarrow(msg.getOldName())));
|
||||
std::string const oldNameNormalized(oldName, 0, oldName.find(' '));
|
||||
ChatAvatarId const oldAvatar("SWG", ConfigChatServer::getClusterName(), oldNameNormalized);
|
||||
|
||||
std::string const newName(Unicode::toLower(Unicode::wideToNarrow(msg.getNewName())));
|
||||
std::string const newNameNormalized(newName, 0, newName.find(' '));
|
||||
ChatAvatarId const newAvatar("SWG", ConfigChatServer::getClusterName(), newNameNormalized);
|
||||
|
||||
IGNORE_RETURN(ChatServer::getChatInterface()->RequestTransferAvatar(msg.getStationId(), oldAvatar.getName(), oldAvatar.getAPIAddress(), msg.getStationId(), newAvatar.getName(), newAvatar.getAPIAddress(), true, NULL));
|
||||
}
|
||||
}
|
||||
else if (m.isType("ChatDestroyAvatar"))
|
||||
{
|
||||
GenericValueTypeMessage<std::string> const msg(ri);
|
||||
ChatServer::getChatInterface()->DestroyAvatar(msg.getValue());
|
||||
}
|
||||
else if(m.isType("AllCluserGlobalChannel"))
|
||||
{
|
||||
typedef std::pair<std::pair<std::string,std::string>, bool> PayloadType;
|
||||
GenericValueTypeMessage<PayloadType> msg(ri);
|
||||
|
||||
PayloadType const & payload = msg.getValue();
|
||||
std::string const & channelName = payload.first.first;
|
||||
std::string const & messageText = payload.first.second;
|
||||
bool const & isRemove = payload.second;
|
||||
|
||||
LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer got AllCluserGlobalChannel on CentralServerConnection chan(%s) text(%s) remove(%d)",
|
||||
channelName.c_str(), messageText.c_str(), (isRemove?1:0)));
|
||||
ChatServer::requestBroadcastChannelMessage(channelName, messageText, isRemove);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
// CentralServerConnection.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_CentralServerConnection_H
|
||||
#define _INCLUDED_CentralServerConnection_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverUtility/ServerConnection.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class CentralServerConnection : public ServerConnection
|
||||
{
|
||||
public:
|
||||
CentralServerConnection(const std::string & remoteAddress, const unsigned short remotePort);
|
||||
~CentralServerConnection();
|
||||
|
||||
void onConnectionClosed ();
|
||||
void onConnectionOpened ();
|
||||
void onReceive (const Archive::ByteStream & bs);
|
||||
private:
|
||||
CentralServerConnection & operator = (const CentralServerConnection & rhs);
|
||||
CentralServerConnection(const CentralServerConnection & source);
|
||||
};//lint !e1712 default constructor not defined for class
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_CentralServerConnection_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,257 @@
|
||||
|
||||
// ChatInterface.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_ChatInterface_H
|
||||
#define _INCLUDED_ChatInterface_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "ChatAPI/ChatAPI.h"
|
||||
#include "ChatServerAvatarOwner.h"
|
||||
#include "ChatServerRoomOwner.h"
|
||||
#include <deque>
|
||||
#include <hash_map>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include "sharedNetworkMessages/ChatRoomData.h"
|
||||
#include "sharedFoundation/NetworkId.h"
|
||||
|
||||
class ChatPersistentMessageToClient;
|
||||
class ConnectionServerConnection;
|
||||
class GameNetworkMessage;
|
||||
|
||||
namespace Archive
|
||||
{
|
||||
class ByteStream;
|
||||
}
|
||||
|
||||
void makeAvatarId(const ChatAvatar & avatar, ChatAvatarId & id);
|
||||
|
||||
using namespace ChatSystem;
|
||||
|
||||
class ChatInterface : public ChatAPI
|
||||
{
|
||||
public:
|
||||
ChatInterface (const std::string & strGameCode,
|
||||
const std::string & strGatewayServerIP,
|
||||
const unsigned short sGatewayServerPort,
|
||||
const std::string & registrarHost,
|
||||
const unsigned short registrarPort
|
||||
);
|
||||
|
||||
virtual ~ChatInterface (); //lint !e1510 base class 'ChatAPI' has no destructor // jrandall - this is beyond my control
|
||||
|
||||
const NetworkId & getNetworkIdByAvatarId(const ChatAvatarId &id);
|
||||
ChatServerAvatarOwner *getAvatarOwner(const ChatAvatar *avatar);
|
||||
void disconnectPlayer (const ChatAvatarId & avatarId);
|
||||
const std::hash_map<std::string, ChatServerRoomOwner> & getRoomList () const;
|
||||
|
||||
const ChatServerRoomOwner *getRoomOwner(const std::string &roomName);
|
||||
ChatServerRoomOwner *getRoomOwner(unsigned roomId);
|
||||
const ChatServerRoomOwner * getRoomByName (const std::string & roomName) const;
|
||||
|
||||
void checkQueuedLogins();
|
||||
|
||||
void sendQueuedHeadersToClient();
|
||||
void clearQueuedHeadersForAvatar(const ChatAvatarId & avatarId);
|
||||
void addQueuedHeaderForAvatar(const ChatAvatarId & avatarId, const ChatPersistentMessageToClient * header, unsigned long sendTime);
|
||||
|
||||
void sendMessageToAvatar (const ChatAvatar & avatar, const GameNetworkMessage & message);
|
||||
void sendMessageToAvatar (const ChatAvatarId & avatar, const GameNetworkMessage & message);
|
||||
void requestRoomList (const NetworkId & id, ConnectionServerConnection * connection);
|
||||
void deferChatMessageFor (const NetworkId & id, const Archive::ByteStream & bs);
|
||||
void sendMessageToAllAvatars (const GameNetworkMessage & message);
|
||||
bool sendMessageToPendingAvatar(const ChatAvatarId &id, const GameNetworkMessage &message);
|
||||
|
||||
std::string getChatName(const NetworkId &id);
|
||||
|
||||
void queryRoom (const NetworkId & id, ConnectionServerConnection * connection, const unsigned int sequenceId, const std::string & roomName);
|
||||
void updateRoomForThisChatAPI(const ChatRoom *room, const ChatAvatar *additionalAvatar);
|
||||
void updateRooms();
|
||||
|
||||
void ConnectPlayer(const unsigned int suid, const std::string & characterName, const NetworkId & networkId);
|
||||
void DestroyAvatar(const std::string & characterName);
|
||||
|
||||
virtual void OnConnect();
|
||||
virtual void OnDisconnect();
|
||||
|
||||
virtual void OnFailoverBegin();
|
||||
virtual void OnFailoverComplete();
|
||||
|
||||
virtual void OnSendRoomMessage(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveRoomMessage(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatRoom *destRoom, const ChatUnicodeString &msg, const ChatUnicodeString &oob, unsigned messageID);
|
||||
|
||||
virtual void OnAddFriend(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatUnicodeString &destName, const ChatUnicodeString &destAddress, void *user);
|
||||
virtual void OnRemoveFriend(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatUnicodeString &destName, const ChatUnicodeString &destAddress, void *user);
|
||||
virtual void OnFriendStatus(unsigned track, unsigned result, const ChatAvatar *srcAvatar, unsigned listLength, const ChatFriendStatus *friendList, void *user);
|
||||
virtual void OnReceiveFriendLogin(const ChatAvatar *srcAvatar, const ChatUnicodeString &srcAddress, const ChatAvatar *destAvatar);
|
||||
virtual void OnReceiveFriendLogout(const ChatAvatar *srcAvatar, const ChatUnicodeString &srcAddress, const ChatAvatar *destAvatar);
|
||||
|
||||
virtual void OnAddIgnore(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatUnicodeString &destName, const ChatUnicodeString &destAddress, void *user);
|
||||
virtual void OnRemoveIgnore(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatUnicodeString &destName, const ChatUnicodeString &destAddress, void *user);
|
||||
virtual void OnIgnoreStatus(unsigned track, unsigned result, const ChatAvatar *srcAvatar, unsigned listLength, const ChatIgnoreStatus *ignoreList, void *user);
|
||||
|
||||
virtual void OnLoginAvatar(unsigned track, unsigned result, const ChatAvatar *newAvatar, void *user);
|
||||
virtual void OnLogoutAvatar(unsigned track, unsigned result, const ChatAvatar *oldAvatar, void *user);
|
||||
virtual void OnDestroyAvatar(unsigned track, unsigned result, const ChatAvatar *oldAvatar, void *user);
|
||||
virtual void OnGetAnyAvatar(unsigned track, unsigned result, const ChatAvatar *foundAvatar, bool loggedIn, void *user);
|
||||
|
||||
virtual void OnCreateRoom(unsigned track,unsigned result, const ChatRoom *newRoom, void *user);
|
||||
virtual void OnDestroyRoom(unsigned track, unsigned result, void *user);
|
||||
virtual void OnReceiveDestroyRoom(const ChatAvatar *srcAvatar, const ChatRoom *destRoom);
|
||||
|
||||
virtual void OnEnterRoom(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveEnterRoom(const ChatAvatar *srcAvatar, const ChatRoom *destRoom);
|
||||
|
||||
virtual void OnAddInvite(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveAddInviteRoom(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatRoom *destRoom);
|
||||
virtual void OnReceiveAddInviteAvatar(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatUnicodeString &roomName, const ChatUnicodeString &roomAddress);
|
||||
|
||||
virtual void OnRemoveInvite(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveRemoveInviteRoom(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatRoom *destRoom);
|
||||
virtual void OnReceiveRemoveInviteAvatar(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatUnicodeString &roomName, const ChatUnicodeString &roomAddress);
|
||||
|
||||
virtual void OnLeaveRoom(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveLeaveRoom(const ChatAvatar *srcAvatar, const ChatRoom *destRoom);
|
||||
|
||||
virtual void OnKickAvatar(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveKickRoom(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatRoom *destRoom);
|
||||
virtual void OnReceiveKickAvatar(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatUnicodeString &roomName, const ChatUnicodeString &roomAddress);
|
||||
|
||||
virtual void OnGetPersistentMessage(unsigned track, unsigned result, ChatAvatar *destAvatar, const PersistentHeader *header, const ChatUnicodeString &msg, const ChatUnicodeString &oob, void *user);
|
||||
virtual void OnSendInstantMessage(unsigned track, unsigned result, const ChatAvatar *srcAvatar, void *user);
|
||||
virtual void OnReceiveInstantMessage(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatUnicodeString &msg, const ChatUnicodeString &oob);
|
||||
|
||||
virtual void OnSendPersistentMessage(unsigned track, unsigned result, const ChatAvatar *srcAvatar, void *user);
|
||||
virtual void OnGetRoomSummaries(unsigned track, unsigned result, unsigned numFoundRooms, RoomSummary *foundRooms, void *user);
|
||||
virtual void OnGetRoom(unsigned track, unsigned result, const ChatRoom *room, void *user);
|
||||
|
||||
virtual void OnAddModerator(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveAddModeratorRoom(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatRoom *destRoom);
|
||||
virtual void OnReceiveAddModeratorAvatar(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatUnicodeString &roomName, const ChatUnicodeString &roomAddress);
|
||||
|
||||
virtual void OnRemoveModerator(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveRemoveModeratorRoom(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatRoom *destRoom);
|
||||
virtual void OnReceiveRemoveModeratorAvatar(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatUnicodeString &roomName, const ChatUnicodeString &roomAddress);
|
||||
|
||||
virtual void OnGetPersistentHeaders(unsigned track, unsigned result, ChatAvatar *destAvatar, unsigned listLength, const PersistentHeader *list, void *user);
|
||||
|
||||
virtual void OnReceiveForcedLogout(const ChatAvatar *oldAvatar);
|
||||
|
||||
virtual void OnReceivePersistentMessage(const ChatAvatar *destAvatar, const PersistentHeader *header);
|
||||
|
||||
virtual void OnAddBan(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveAddBanRoom(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatRoom *destRoom);
|
||||
virtual void OnReceiveAddBanAvatar(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatUnicodeString &roomName, const ChatUnicodeString &roomAddress);
|
||||
|
||||
virtual void OnRemoveBan(unsigned track, unsigned result, const ChatAvatar *srcAvatar, const ChatRoom *destRoom, void *user);
|
||||
virtual void OnReceiveRemoveBanRoom(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatRoom *destRoom);
|
||||
virtual void OnReceiveRemoveBanAvatar(const ChatAvatar *srcAvatar, const ChatAvatar *destAvatar, const ChatUnicodeString &roomName, const ChatUnicodeString &roomAddress);
|
||||
|
||||
virtual void OnUpdatePersistentMessages(unsigned track, unsigned result, const ChatAvatar *targetAvatar, void *user);
|
||||
virtual void OnReceiveUnregisterRoomReady(const ChatRoom *destRoom);
|
||||
virtual void OnTransferAvatar(unsigned track, unsigned result, unsigned oldUserID, unsigned newUserID, const ChatUnicodeString &oldName, const ChatUnicodeString &newName, const ChatUnicodeString &oldAddress, const ChatUnicodeString &newAddress, void *user);
|
||||
|
||||
private:
|
||||
std::map<ChatAvatarId, ChatServerAvatarOwner *> avatarMap;
|
||||
std::hash_map<std::string, NetworkId> pendingAvatars;
|
||||
std::set<NetworkId> pendingRoomQueries;
|
||||
int roomQueriesThisFrame;
|
||||
std::hash_map<std::string, ChatServerRoomOwner> roomList;
|
||||
std::hash_map<NetworkId, std::vector<Archive::ByteStream>, NetworkId::Hash > deferredChatMessages;
|
||||
std::map<ChatAvatarId, std::pair<unsigned long, std::deque<const ChatPersistentMessageToClient *> > > queuedHeaders;
|
||||
std::map<unsigned, std::pair<std::pair<ChatUnicodeString, ChatUnicodeString>, int> > trackingRequestGetAnyAvatarForDestroy;
|
||||
};
|
||||
|
||||
#if 0
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ChatInterface : public ChatAPI
|
||||
{
|
||||
public:
|
||||
ChatInterface (const std::string & strGameCode,
|
||||
const std::string & strGatewayServerIP,
|
||||
const unsigned short sGatewayServerPort,
|
||||
const std::string & strBackupGatewayServerIP,
|
||||
const unsigned short sBackupGatewayServerPort
|
||||
);
|
||||
|
||||
virtual ~ChatInterface (); //lint !e1510 base class 'ChatAPI' has no destructor // jrandall - this is beyond my control
|
||||
|
||||
|
||||
void checkRoomExpirations ();
|
||||
void ConnectPlayer (const unsigned int suid, const std::string & characterName, const NetworkId & networkId);
|
||||
void deferChatMessageFor (const NetworkId & id, const Archive::ByteStream & bs);
|
||||
void destroyRoomByName (const std::string & roomName);
|
||||
|
||||
const std::hash_map<std::string, ChatServerRoomOwner> & getRoomList () const;
|
||||
const ChatServerAvatarOwner *findAvatar(const ChatAvatarId & avatarId);
|
||||
|
||||
void leaveRoom (const ChatAvatarId & avatarId, const std::string & roomName);
|
||||
|
||||
//--- ChatAPI virtual overrides
|
||||
virtual void OnConnectAvatar (const std::string & track, const unsigned int resultCode, const ChatAvatar & avatar);
|
||||
virtual void OnAddFriend (const unsigned int sequence, const std::string & track, const unsigned int nResultCode, const ChatAvatar & requestingAvatar, const ChatAvatar & friendAvatar);
|
||||
virtual void OnRemoveFriend (const unsigned int sequence, const std::string & track, const unsigned int nResultCode, const ChatAvatar & requestingAvatar, const ChatAvatar & friendAvatar);
|
||||
virtual void OnAddIgnore (const unsigned int sequence, const std::string & track, const unsigned int nResultCode, const ChatAvatar & requestingAvatar, const ChatAvatar & ignoreAvatar);
|
||||
virtual void OnRemoveIgnore (const unsigned int sequence, const std::string & track, const unsigned int nResultCode, const ChatAvatar & requestingAvatar, const ChatAvatar & ignoreAvatar);
|
||||
virtual void OnAddRoomModerator (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatRoom & room, const unsigned int nRequestingAvatarUID, const ChatAvatar & moderator);
|
||||
virtual void OnCreateRoom (const unsigned int sequence, const std::string & track, const unsigned int nResultCode, const ChatRoom & room);
|
||||
virtual void OnDestroyRoom (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatRoom & room, const std::string & strCharacterName, const std::string & strGameServerName, const std::string & strGameCode);
|
||||
virtual void OnDisconnectAvatar (const std::string & track, const unsigned int nResultCode, const ChatAvatar & toAvatar);
|
||||
virtual void OnDisconnectAvatarNotify (const ChatAvatar & toAvatar);
|
||||
virtual void OnEnterRoom (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatRoom & room, const ChatAvatar & avatar);
|
||||
virtual void OnLeaveRoom (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatRoom & room, const ChatAvatar & avatar);
|
||||
virtual void OnReceiveInstantMessage (const ChatAvatar & toAvatar, const ChatAvatar & fromAvatar, const Unicode::String & ustrMessage, const Unicode::String & oob);
|
||||
virtual void OnReceivePersistentMessage (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatPersistentMessage & message);
|
||||
virtual void OnReceivePersistentMessageHeader (const ChatPersistentMessageHeader & header);
|
||||
virtual void OnReceivePersistentMessageHeaders (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatAvatar & toAvatar, const std::vector<ChatPersistentMessageHeader> & headers);
|
||||
virtual void OnReceiveRoomMessage (const unsigned int nSequenceID, const ChatRoom & room, const std::string & strFromCharacterName, const std::string & strFromGameServerName, const std::string & strFromGameCode, const Unicode::String & ustrMessage, const Unicode::String & outOfBand, unsigned messageID);
|
||||
virtual void OnConnect (const unsigned int resultCode);
|
||||
virtual void OnReceiveRooms (const std::string & track, const unsigned int nResultCode, const std::vector<ChatRoom*> & rooms);
|
||||
virtual void OnRemoveRoomModerator (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatRoom & room, const unsigned int nRequestingAvatarUID, const ChatAvatar & moderator);
|
||||
virtual void OnSendInstantMessage (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatAvatar & sendingAvatar);
|
||||
virtual void OnSendPersistentMessage (const unsigned int nSequenceID, const std::string & track, const unsigned int nResultCode, const ChatAvatar& sendingAvatar);
|
||||
virtual void OnSendRoomMessage (const unsigned int sequence, const std::string & track, const unsigned int resultCode);
|
||||
virtual void OnUpdateFriendStatus (const ChatAvatar & toAvatar, const ChatAvatar & fromAvatar, const bool bIsConnected);
|
||||
virtual void OnReceiveRoomInvitation (const std::string & strRoomName, const ChatAvatar & invitorAvatar, const ChatAvatar & inviteeAvatar);
|
||||
virtual void OnSendRoomInvitation (const unsigned int sequence, const std::string & track, const unsigned int resultCode, const ChatRoom & room, const bool isOnline, const ChatAvatar & invitor, const ChatAvatar & invitee);
|
||||
|
||||
const ChatServerRoomOwner * getRoomByName (const std::string & roomName) const;
|
||||
|
||||
void disconnectPlayer (const ChatAvatarId & avatarId);
|
||||
void queryRoom (const NetworkId & id, ConnectionServerConnection * connection, const unsigned int sequenceId, const std::string & roomName);
|
||||
void queryRoom (const NetworkId & id, ConnectionServerConnection * connection, const unsigned int sequenceId, const unsigned int roomId);
|
||||
void requestRoomList (const NetworkId & id, ConnectionServerConnection * connection);
|
||||
void sendMessageToAllAvatars (const GameNetworkMessage & message);
|
||||
bool sendMessageToPendingAvatar(const ChatAvatarId &id, const GameNetworkMessage &message);
|
||||
|
||||
private:
|
||||
void sendMessageToAvatar (const ChatAvatar & avatar, const GameNetworkMessage & message);
|
||||
void sendMessageToAvatar (const ChatAvatarId & avatar, const GameNetworkMessage & message);
|
||||
|
||||
private:
|
||||
ChatInterface & operator = (const ChatInterface & rhs);
|
||||
ChatInterface(const ChatInterface & source);
|
||||
std::hash_map<std::string, NetworkId> pendingAvatars;
|
||||
std::hash_map<NetworkId, std::vector<Archive::ByteStream>, NetworkId::Hash > deferredChatMessages;
|
||||
std::hash_map<std::string, ChatServerRoomOwner> roomList;
|
||||
std::map<ChatAvatarId, ChatServerAvatarOwner *> avatarMap;
|
||||
time_t lastRoomCheck;
|
||||
|
||||
}; //lint !e1712 default constructor not defined for class
|
||||
|
||||
#endif
|
||||
|
||||
std::string toLower(const std::string & source);
|
||||
std::string toUpper(const std::string & source);
|
||||
void makeRoomData(const ChatRoom & room, ChatRoomData & roomData);
|
||||
void makeRoomData(const RoomSummary & room, ChatRoomData & roomData);
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_ChatInterface_H
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,301 @@
|
||||
// ChatServer.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_ChatServer_H
|
||||
#define _INCLUDED_ChatServer_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "ChatAPI/ChatAvatar.h"
|
||||
#include "ChatAPI/ChatAPI.h"
|
||||
#include "sharedFoundation/NetworkId.h"
|
||||
#include "sharedNetworkMessages/ChatAvatarId.h"
|
||||
#include <hash_map>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include "unicodeArchive/UnicodeArchive.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class CentralServerConnection;
|
||||
class ChatInterface;
|
||||
class Connection;
|
||||
class ConnectionServerConnection;
|
||||
class EnumerateServers;
|
||||
class Service;
|
||||
class GameNetworkMessage;
|
||||
class GameServerConnection;
|
||||
class ChatServerRoomOwner;
|
||||
class CustomerServiceServerConnection;
|
||||
struct ChatLogEntry;
|
||||
class TransferCharacterData;
|
||||
class VChatInterface;
|
||||
|
||||
using namespace ChatSystem;
|
||||
|
||||
|
||||
namespace MessageDispatch {
|
||||
class Callback;
|
||||
}
|
||||
|
||||
struct AvatarSequencePair
|
||||
{
|
||||
AvatarSequencePair(unsigned s, const ChatAvatar *a) : sequence(s), avatar(a) {}
|
||||
unsigned sequence;
|
||||
const ChatAvatar *avatar;
|
||||
};
|
||||
|
||||
struct AvatarIdSequencePair
|
||||
{
|
||||
AvatarIdSequencePair(unsigned s, const ChatAvatarId &a) : sequence(s), avatar(a) {}
|
||||
unsigned sequence;
|
||||
const ChatAvatarId avatar;
|
||||
|
||||
private:
|
||||
AvatarIdSequencePair(AvatarIdSequencePair const &);
|
||||
AvatarIdSequencePair & operator =(AvatarIdSequencePair const &);
|
||||
};
|
||||
|
||||
struct RoomOwnerSequencePair
|
||||
{
|
||||
RoomOwnerSequencePair(unsigned s, const ChatServerRoomOwner * r) : sequence(s), roomOwner(r) {}
|
||||
unsigned sequence;
|
||||
const ChatServerRoomOwner *roomOwner;
|
||||
};
|
||||
|
||||
struct ReturnAddress;
|
||||
|
||||
class ChatServer
|
||||
{
|
||||
public:
|
||||
ChatServer();
|
||||
~ChatServer();
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void sendResponse(ReturnAddress const & requester, const GameNetworkMessage & response);
|
||||
|
||||
GameServerConnection * getGameServerConnectionFromId(unsigned int connectionId);
|
||||
unsigned registerGameServerConnection(GameServerConnection * connection);
|
||||
void unregisterGameServerConnection(unsigned const connectionId);
|
||||
void sendToGameServerById(unsigned const connectionId, GameNetworkMessage const & message);
|
||||
|
||||
static VChatInterface* getVChatInterface();
|
||||
|
||||
//TODO: remove these and integrate their functionality where it should rightly go (voice and text should be unified)
|
||||
static void requestGetChannel(ReturnAddress const & requester, std::string const &roomName, bool isPublic, bool isPersistant, uint32 limit, std::list<std::string> const & moderators);
|
||||
static void requestChannelInfo(ReturnAddress const & requester, std::string const &roomName);
|
||||
static void requestDeleteChannel(ReturnAddress const & requester, std::string const & roomName);
|
||||
static void requestAddClientToChannel(const NetworkId & id, std::string const & playerName, std::string const &roomName, bool forceShortlist);
|
||||
static void requestRemoveClientFromChannel(const NetworkId & id, std::string const & playerName, std::string const &roomName);
|
||||
static void requestChannelCommand(ReturnAddress const & requester, const std::string &srcUserName, const std::string &destUserName,
|
||||
const std::string &destChannelAddress, unsigned command, unsigned banTimeout);
|
||||
|
||||
static void requestBroadcastChannelMessage(std::string const & channelName, std::string const & textMessage, bool isRemove);
|
||||
|
||||
static bool getVoiceChatLoginInfoFromId(NetworkId const & id, std::string & userName, std::string & playerName);
|
||||
static bool getVoiceChatLoginInfoFromName(std::string const & playerName, NetworkId & id);
|
||||
static bool getVoiceChatLoginInfoFromLoginName(std::string const & loginName, NetworkId & id);
|
||||
static void voiceChatGotLoginInfo(NetworkId const & id, std::string const & userName, std::string const & playerName);
|
||||
|
||||
static void requestInvitePlayerToChannel(NetworkId const & sourceId, NetworkId const & targetId, std::string const & channelName);
|
||||
static void requestKickPlayerFromChannel(NetworkId const & sourceId, NetworkId const & targetId, std::string const & channelName);
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
|
||||
std::hash_map<unsigned, NetworkId> pendingRequests;
|
||||
static ChatServer & instance ();
|
||||
|
||||
static bool isValidChatAvatarName(Unicode::String const &chatName);
|
||||
static std::string getFullChatAvatarName(ChatAvatar const *chatAvatar);
|
||||
static std::string toNarrowString(ChatUnicodeString const &chatUnicodeString);
|
||||
static std::string getConnectionAddress(Connection const *connection);
|
||||
static Unicode::String getChatRoomName(ChatRoom const *chatRoom);
|
||||
static std::string getChatRoomNameNarrow(ChatRoom const *chatRoom);
|
||||
static Unicode::String toUnicodeString(ChatUnicodeString const &chatUnicodeString);
|
||||
|
||||
static const ChatAvatar * getAvatarByNetworkId (const NetworkId & id);
|
||||
static const NetworkId & getNetworkIdByAvatarId(const ChatAvatarId & id);
|
||||
static NetworkId sendResponseForTrackId (unsigned trackId, const GameNetworkMessage & msg);
|
||||
static ChatInterface * getChatInterface();
|
||||
|
||||
static void setOwnerSystem (const ChatAvatar * ownerSystem);
|
||||
static ConnectionServerConnection * getConnectionForCharacter(const NetworkId & characterId);
|
||||
static const ChatAvatarId & getSystemAvatarId ();
|
||||
static const Service * getGameService ();
|
||||
static GameServerConnection * getGameServerConnection(unsigned int sequence);
|
||||
static void addGameServerConnection(unsigned int sequence, GameServerConnection *connection);
|
||||
|
||||
static void clearGameServerConnection(const GameServerConnection *connection);
|
||||
static void clearCustomerServiceServerConnection();
|
||||
|
||||
static void connectToCustomerServiceServer(const std::string &address, const unsigned short port);
|
||||
|
||||
static void sendToClient (const NetworkId & id, const GameNetworkMessage & msg);
|
||||
static void deferChatMessageFor (const NetworkId &, const Archive::ByteStream &);
|
||||
|
||||
static ChatAvatarId getAvatarIdForTrackId (unsigned trackId);
|
||||
|
||||
static void reconnectToCentralServer ();
|
||||
static void onCentralServerConnectionClosed();
|
||||
|
||||
static void run ();
|
||||
static void quit ();
|
||||
static void chatConnectedAvatar (const NetworkId & id, const ChatAvatar & avatar);
|
||||
|
||||
static void connectPlayer (ConnectionServerConnection * connection, const unsigned int suid, const std::string & characterName, const NetworkId & networkId, const bool isSecure, const bool isSubscribed);
|
||||
static void createRoom (const NetworkId & id, const unsigned int sequence, const std::string & name, const bool isModerated, const bool isPublic, const std::string & title);
|
||||
static void putSystemAvatarInRoom (const std::string & roomName);
|
||||
static void enterRoom (const NetworkId & id, const unsigned int sequence, const std::string & roomName);
|
||||
static void enterRoom (const NetworkId & id, const unsigned int sequence, const unsigned int roomId);
|
||||
static void enterRoom (const ChatAvatarId & id, const std::string & roomName, bool forceCreate, bool createPrivate);
|
||||
static void sendInstantMessage (const NetworkId & fromId, const unsigned int sequence, const ChatAvatarId & to, const Unicode::String & message, const Unicode::String & oob);
|
||||
static void sendInstantMessage (const ChatAvatarId & from, const ChatAvatarId & to, const Unicode::String & message, const Unicode::String & oob);
|
||||
static void leaveRoom (const NetworkId & id, const unsigned int sequence, const unsigned int roomId);
|
||||
static void removeAvatarFromRoom (const NetworkId & requestor, const ChatAvatarId & avatarId, const std::string & roomName);
|
||||
static void removeSystemAvatarFromRoom(const ChatRoom *room);
|
||||
static void removeAvatarFromRoom (const ChatAvatarId & avatarId, const std::string & roomName);
|
||||
static void kickAvatarFromRoom (const NetworkId & id, const ChatAvatarId & avatarId, const std::string & roomName);
|
||||
static void sendRoomMessage (const NetworkId & id, const unsigned int sequence, const unsigned int roomId, const Unicode::String & message, const Unicode::String & oob);
|
||||
static void sendRoomMessage (const ChatAvatarId & from, const std::string & roomName, const Unicode::String & message, const Unicode::String & oob);
|
||||
static void sendStandardRoomMessage (const ChatAvatarId & from, const std::string & roomName, const Unicode::String & message, const Unicode::String & oob);
|
||||
static void destroyRoom (const NetworkId & id, const unsigned int sequence, const unsigned int roomId);
|
||||
static void destroyRoom (const std::string & roomName);
|
||||
static void addFriend (const NetworkId & id, const unsigned int sequence, const ChatAvatarId & friendName);
|
||||
static void removeFriend (const NetworkId & id, const unsigned int sequence, const ChatAvatarId & friendName);
|
||||
static void getFriendsList (const ChatAvatarId & characterName);
|
||||
static void addIgnore (const NetworkId & id, const unsigned int sequence, const ChatAvatarId & ignoreName);
|
||||
static void removeIgnore (const NetworkId & id, const unsigned int sequence, const ChatAvatarId & ignoreName);
|
||||
static void getIgnoreList (const ChatAvatarId & characterName);
|
||||
static void disconnectAvatar (const ChatAvatar &);
|
||||
static void disconnectPlayer (const NetworkId &);
|
||||
static void invite (const NetworkId & id, const ChatAvatarId & avatar, const std::string & roomName);
|
||||
static void inviteGroupMembers (const NetworkId & id, const ChatAvatarId & avatar, const std::string & roomName, const stdvector<NetworkId>::fwd & members);
|
||||
static void uninvite (const NetworkId & id, const unsigned int sequence, const ChatAvatarId & avatar, const std::string & roomName);
|
||||
static void queryRoom (const NetworkId & id, ConnectionServerConnection * connection, const unsigned int sequence, const std::string & roomName);
|
||||
static void requestRoomList (const NetworkId & id, ConnectionServerConnection * connection);
|
||||
static void addModeratorToRoom (const unsigned int sequenceId, const NetworkId & id, const ChatAvatarId & avatarId, const std::string & roomName);
|
||||
static void removeModeratorFromRoom (const unsigned int sequenceId, const NetworkId & id, const ChatAvatarId & avatarId, const std::string & roomName);
|
||||
static void deletePersistentMessage (const NetworkId & ownerId, const unsigned int messageId);
|
||||
static void deleteAllPersistentMessages(const NetworkId &sourceNetworkId, const NetworkId &targetNetworkId);
|
||||
static void sendPersistentMessage (const NetworkId & fromId, const unsigned int sequence, const ChatAvatarId & to, const Unicode::String & subject, const Unicode::String & message, const Unicode::String & oob);
|
||||
static void sendPersistentMessage (const ChatAvatarId & from, const ChatAvatarId & to, const Unicode::String & subject, const Unicode::String & message, const Unicode::String & oob);
|
||||
static void requestPersistentMessage (const NetworkId &id, const unsigned int sequence, const unsigned int messageId);
|
||||
static void banFromRoom (const unsigned sequence, const NetworkId &banner, const ChatAvatarId &bannee, const std::string &roomName);
|
||||
static void unbanFromRoom (const unsigned sequence, const NetworkId &banner, const ChatAvatarId &bannee, const std::string &roomName);
|
||||
static void removeConnectionServerConnection(ConnectionServerConnection * target);
|
||||
|
||||
static void sendToAllConnectionServers(const GameNetworkMessage &message);
|
||||
static void broadcastToGameServers(const GameNetworkMessage &message);
|
||||
|
||||
static bool getChatLog(Unicode::String const &player, std::vector<ChatLogEntry> &chatLog);
|
||||
static void logChatMessage(Unicode::String const &logPlayer, Unicode::String const &fromPlayer, Unicode::String const &toPlayer, Unicode::String const &text, Unicode::String const &channel);
|
||||
static Unicode::String const &getChannelTell();
|
||||
static Unicode::String const &getChannelEmail();
|
||||
|
||||
static void fileLog(bool const forceLog, char const * const label, char const * const format, ...);
|
||||
static void requestTransferAvatar(const TransferCharacterData & request);
|
||||
static void onCreateRoomSuccess(const std::string & lowerName, const unsigned int roomId);
|
||||
static bool isGod(const NetworkId & networkId);
|
||||
|
||||
static void setUnsquelchTime(NetworkId const & character, time_t unsquelchTime);
|
||||
static void handleChatStatisticsFromGameServer(NetworkId const & character, time_t unsquelchTime, time_t chatSpamTimeEndInterval, int spatialNumCharacters, int nonSpatialNumCharacters);
|
||||
private:
|
||||
|
||||
void onEnumerateServers(const EnumerateServers &);
|
||||
void update();
|
||||
void removeServices();
|
||||
|
||||
struct AvatarExtendedData
|
||||
{
|
||||
ChatAvatar chatAvatar;
|
||||
bool isSubscribed;
|
||||
int spatialCharCount;
|
||||
int nonSpatialCharCount;
|
||||
time_t chatSpamTimeEndInterval;
|
||||
time_t chatSpamNextTimeToSyncWithGameServer;
|
||||
time_t chatSpamNextTimeToNotifyPlayerWhenLimited;
|
||||
time_t unsquelchTime;
|
||||
};
|
||||
typedef std::hash_map<NetworkId, AvatarExtendedData, NetworkId::Hash> ChatAvatarList;
|
||||
|
||||
|
||||
struct VoiceChatAvatarData
|
||||
{
|
||||
std::string loginName;
|
||||
std::string playerName;
|
||||
};
|
||||
|
||||
typedef std::hash_map<NetworkId, VoiceChatAvatarData, NetworkId::Hash> VoiceChatAvatarList;
|
||||
|
||||
static AvatarExtendedData * getAvatarExtendedDataByNetworkId(const NetworkId & id);
|
||||
|
||||
MessageDispatch::Callback * callback;
|
||||
CentralServerConnection * centralServerConnection;
|
||||
ChatAvatarList chatAvatars;
|
||||
ChatInterface * chatInterface;
|
||||
VChatInterface * voiceChatInterface;
|
||||
std::hash_map<NetworkId, ConnectionServerConnection *, NetworkId::Hash> clientMap;
|
||||
std::hash_map<unsigned int, GameServerConnection *> gameServerConnectionMap;
|
||||
std::set<ConnectionServerConnection *> connectionServerConnections;
|
||||
|
||||
bool done;
|
||||
Service * gameService;
|
||||
Service * planetService;
|
||||
const ChatAvatar * ownerSystem;
|
||||
ChatAvatarId systemAvatarId;
|
||||
static ChatServer * m_instance;
|
||||
CustomerServiceServerConnection *customerServiceServerConnection;
|
||||
|
||||
typedef std::hash_map<unsigned int, GameServerConnection *> GameServerMap;
|
||||
GameServerMap m_gameServerConnectionRegistry;
|
||||
VoiceChatAvatarList m_voiceChatIdMap;
|
||||
std::map<std::string, NetworkId> m_voiceChatNameToIdMap;
|
||||
std::map<std::string, NetworkId> m_voiceLoginNameToIdMap;
|
||||
|
||||
// Disabled
|
||||
|
||||
ChatServer &operator =(ChatServer const &);
|
||||
};
|
||||
|
||||
/*
|
||||
class ChatServer
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
ChatServer & operator = (const ChatServer & rhs);
|
||||
ChatServer(const ChatServer & source);
|
||||
|
||||
private:
|
||||
MessageDispatch::Callback * callback;
|
||||
CentralServerConnection * centralServerConnection;
|
||||
std::hash_map<NetworkId, const ChatAvatar *, NetworkId::Hash> chatAvatars;
|
||||
ChatInterface * chatInterface;
|
||||
std::hash_map<NetworkId, ConnectionServerConnection *, NetworkId::Hash> clientMap;
|
||||
std::hash_map<unsigned int, GameServerConnection *> gameServerConnectionMap;
|
||||
std::set<ConnectionServerConnection *> connectionServerConnections;
|
||||
bool done;
|
||||
Service * gameService;
|
||||
Service * planetService;
|
||||
const ChatAvatar * ownerSystem;
|
||||
ChatAvatarId systemAvatarId;
|
||||
std::hash_map<unsigned, NetworkId> pendingRequests;
|
||||
static ChatServer * m_instance;
|
||||
|
||||
};*/
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_ChatServer_H
|
||||
@@ -0,0 +1,40 @@
|
||||
// ChatServerAvatarOwner.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "ChatServerAvatarOwner.h"
|
||||
#include "ConnectionServerConnection.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChatServerAvatarOwner::ChatServerAvatarOwner(ConnectionServerConnection * c, const NetworkId & n) :
|
||||
networkId(n),
|
||||
playerConnection(c)
|
||||
{
|
||||
c->addAvatar(this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChatServerAvatarOwner::~ChatServerAvatarOwner()
|
||||
{
|
||||
if(playerConnection)
|
||||
{
|
||||
playerConnection->removeAvatar(this);
|
||||
}
|
||||
|
||||
playerConnection = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerAvatarOwner::setPlayerConnection(ConnectionServerConnection * c)
|
||||
{
|
||||
playerConnection = c;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
// ChatServerAvatarOwner.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_ChatServerAvatarOwner_H
|
||||
#define _INCLUDED_ChatServerAvatarOwner_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "ChatAPI/ChatAvatar.h"
|
||||
#include "sharedFoundation/NetworkId.h"
|
||||
|
||||
class ConnectionServerConnection;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ChatServerAvatarOwner
|
||||
{
|
||||
public:
|
||||
explicit ChatServerAvatarOwner(ConnectionServerConnection * playerConnection, const NetworkId & networkId);
|
||||
~ChatServerAvatarOwner();
|
||||
|
||||
const NetworkId & getNetworkId () const;
|
||||
ConnectionServerConnection * getPlayerConnection ();
|
||||
void setPlayerConnection (ConnectionServerConnection *);
|
||||
|
||||
private:
|
||||
ChatServerAvatarOwner & operator = (const ChatServerAvatarOwner & rhs);
|
||||
ChatServerAvatarOwner(const ChatServerAvatarOwner & source);
|
||||
NetworkId networkId;
|
||||
ConnectionServerConnection * playerConnection;
|
||||
}; //lint !e1712 default constructor not defined for class
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const NetworkId & ChatServerAvatarOwner::getNetworkId() const
|
||||
{
|
||||
return networkId;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline ConnectionServerConnection * ChatServerAvatarOwner::getPlayerConnection()
|
||||
{
|
||||
return playerConnection;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_ChatServerAvatarOwner_H
|
||||
@@ -0,0 +1,55 @@
|
||||
//ChatServerMetricsData.cpp
|
||||
//Copyright 2002 Sony Online Entertainment
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "ChatServerMetricsData.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChatServerMetricsData::ChatServerMetricsData() :
|
||||
MetricsData(),
|
||||
m_clientCount(0),
|
||||
m_connectionServerCount(0),
|
||||
m_gameServerCount(0)
|
||||
{
|
||||
MetricsPair p;
|
||||
ADD_METRICS_DATA(clientCount, 0, false);
|
||||
ADD_METRICS_DATA(connectionServerCount, 0, false);
|
||||
ADD_METRICS_DATA(gameServerCount, 0, false);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChatServerMetricsData::~ChatServerMetricsData()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerMetricsData::setClientCount(const int clientCount)
|
||||
{
|
||||
m_data[m_clientCount].m_value = clientCount;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerMetricsData::setConnectionServerConnectionCount(const int connectionServerConnectionCount)
|
||||
{
|
||||
m_data[m_connectionServerCount].m_value = connectionServerConnectionCount;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerMetricsData::setGameServerConnectionCount(const int gameServerConnectionCount)
|
||||
{
|
||||
m_data[m_gameServerCount].m_value = gameServerConnectionCount;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerMetricsData::updateData()
|
||||
{
|
||||
MetricsData::updateData();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -0,0 +1,39 @@
|
||||
//ChatServerMetricsData.h
|
||||
//Copyright 2002 Sony Online Entertainment
|
||||
|
||||
|
||||
#ifndef _ChatServerMetricsData_H
|
||||
#define _ChatServerMetricsData_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverMetrics/MetricsData.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ChatServerMetricsData : public MetricsData
|
||||
{
|
||||
public:
|
||||
ChatServerMetricsData();
|
||||
~ChatServerMetricsData();
|
||||
|
||||
virtual void updateData();
|
||||
void setClientCount(const int clientCount);
|
||||
void setConnectionServerConnectionCount(const int connectionServerConnectionCount);
|
||||
void setGameServerConnectionCount(const int gameServerConnectionCount);
|
||||
|
||||
private:
|
||||
|
||||
// Disabled.
|
||||
ChatServerMetricsData(const ChatServerMetricsData&);
|
||||
ChatServerMetricsData &operator =(const ChatServerMetricsData&);
|
||||
|
||||
private:
|
||||
unsigned long m_clientCount;
|
||||
unsigned long m_connectionServerCount;
|
||||
unsigned long m_gameServerCount;
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
#endif
|
||||
@@ -0,0 +1,175 @@
|
||||
// ChatServerRoomOwner.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "ChatServerRoomOwner.h"
|
||||
#include "ChatInterface.h"
|
||||
#include "ChatServer.h"
|
||||
#include "UnicodeUtils.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChatServerRoomOwner::ChatServerRoomOwner(const ChatRoom * r) :
|
||||
roomID(r->getRoomID()),
|
||||
roomData(),
|
||||
lastUsed(time(0)),
|
||||
lastPopulated(time(0)),
|
||||
wideRoomAddress(r->getAddress().string_data, r->getAddress().string_length),
|
||||
roomAddress(wideRoomAddress.data(), wideRoomAddress.size()),
|
||||
flaggedForDelete(false),
|
||||
groupChatRoom(false)
|
||||
{
|
||||
if(r)
|
||||
{
|
||||
makeRoomData(*r, roomData);
|
||||
if (!_stricmp(ChatServer::getChatRoomNameNarrow(r).c_str(), ChatRoomTypes::ROOM_GROUP.c_str()) && !_stricmp(Unicode::wideToNarrow(ChatServer::toUnicodeString(r->getCreatorName())).c_str(), "SYSTEM"))
|
||||
groupChatRoom = true;
|
||||
else
|
||||
groupChatRoom = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
groupChatRoom = false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChatServerRoomOwner::ChatServerRoomOwner(const ChatServerRoomOwner & source) :
|
||||
roomID(source.roomID),
|
||||
roomData(source.roomData),
|
||||
lastUsed(time(0)),
|
||||
lastPopulated(time(0)),
|
||||
wideRoomAddress(source.wideRoomAddress),
|
||||
roomAddress(wideRoomAddress.data(), wideRoomAddress.size()),
|
||||
flaggedForDelete(false),
|
||||
groupChatRoom(source.groupChatRoom)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChatServerRoomOwner::~ChatServerRoomOwner()
|
||||
{
|
||||
roomID = 0;
|
||||
lastUsed = 0;
|
||||
lastPopulated = 0;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ChatServerRoomOwner & ChatServerRoomOwner::operator = (const ChatServerRoomOwner & rhs)
|
||||
{
|
||||
if(this != &rhs)
|
||||
{
|
||||
// make assignments if right hand side is not this instance
|
||||
roomID = rhs.roomID;
|
||||
roomData = rhs.roomData;
|
||||
lastUsed = rhs.lastUsed;
|
||||
lastPopulated = rhs.lastPopulated;
|
||||
wideRoomAddress = rhs.wideRoomAddress;
|
||||
roomAddress = wideRoomAddress;
|
||||
flaggedForDelete = rhs.flaggedForDelete;
|
||||
groupChatRoom = rhs.groupChatRoom;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const ChatRoom * ChatServerRoomOwner::getRoom() const
|
||||
{
|
||||
ChatInterface * const chatInterface = ChatServer::getChatInterface();
|
||||
if (chatInterface)
|
||||
return chatInterface->getRoom(roomID);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const ChatRoomData & ChatServerRoomOwner::getRoomData() const
|
||||
{
|
||||
return roomData;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerRoomOwner::updateRoomData()
|
||||
{
|
||||
ChatRoom const * const room = getRoom();
|
||||
if(room)
|
||||
{
|
||||
makeRoomData(*room, roomData);
|
||||
if (!_stricmp(ChatServer::getChatRoomNameNarrow(room).c_str(), ChatRoomTypes::ROOM_GROUP.c_str()) && !_stricmp(Unicode::wideToNarrow(ChatServer::toUnicodeString(room->getCreatorName())).c_str(), "SYSTEM"))
|
||||
groupChatRoom = true;
|
||||
else
|
||||
groupChatRoom = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
groupChatRoom = false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerRoomOwner::updateRoomData(const ChatRoom *newRoom)
|
||||
{
|
||||
if(newRoom)
|
||||
{
|
||||
roomID = newRoom->getRoomID(),
|
||||
makeRoomData(*newRoom, roomData);
|
||||
if (!_stricmp(ChatServer::getChatRoomNameNarrow(newRoom).c_str(), ChatRoomTypes::ROOM_GROUP.c_str()) && !_stricmp(Unicode::wideToNarrow(ChatServer::toUnicodeString(newRoom->getCreatorName())).c_str(), "SYSTEM"))
|
||||
groupChatRoom = true;
|
||||
else
|
||||
groupChatRoom = false;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
const ChatUnicodeString & ChatServerRoomOwner::getAddress() const
|
||||
{
|
||||
return roomAddress;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerRoomOwner::touch()
|
||||
{
|
||||
lastUsed = time(0);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
time_t ChatServerRoomOwner::getLastUsed() const
|
||||
{
|
||||
return lastUsed;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool ChatServerRoomOwner::isFlaggedForDelete() const
|
||||
{
|
||||
return flaggedForDelete;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ChatServerRoomOwner::flagForDelete()
|
||||
{
|
||||
flaggedForDelete = true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
time_t ChatServerRoomOwner::getLastPopulated()
|
||||
{
|
||||
return lastPopulated;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -0,0 +1,58 @@
|
||||
// ChatServerRoomOwner.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_ChatServerRoomOwner_H
|
||||
#define _INCLUDED_ChatServerRoomOwner_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "ChatAPI/ChatRoom.h"
|
||||
#include "sharedNetworkMessages/ChatRoomData.h"
|
||||
|
||||
using namespace ChatSystem;
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ChatServerRoomOwner
|
||||
{
|
||||
public:
|
||||
explicit ChatServerRoomOwner(const ChatRoom * room);
|
||||
virtual ~ChatServerRoomOwner();
|
||||
ChatServerRoomOwner & operator = (const ChatServerRoomOwner & rhs);
|
||||
ChatServerRoomOwner(const ChatServerRoomOwner & source);
|
||||
|
||||
const ChatRoom * getRoom () const;
|
||||
const ChatRoomData & getRoomData () const;
|
||||
void updateRoomData ();
|
||||
void updateRoomData (const ChatRoom *room);
|
||||
void touch ();
|
||||
time_t getLastUsed () const;
|
||||
time_t getLastPopulated();
|
||||
const ChatUnicodeString & getAddress () const;
|
||||
void flagForDelete();
|
||||
bool isFlaggedForDelete() const;
|
||||
bool isGroupChatRoom() const;
|
||||
|
||||
private:
|
||||
|
||||
unsigned roomID;
|
||||
ChatRoomData roomData;
|
||||
time_t lastUsed;
|
||||
time_t lastPopulated;
|
||||
Unicode::String wideRoomAddress;
|
||||
ChatUnicodeString roomAddress;
|
||||
bool flaggedForDelete;
|
||||
bool groupChatRoom;
|
||||
};//lint !e1712 default constructor not defined for class
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline bool ChatServerRoomOwner::isGroupChatRoom() const
|
||||
{
|
||||
return groupChatRoom;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_ChatServerRoomOwner_H
|
||||
@@ -0,0 +1,148 @@
|
||||
// ConfigChatServer.cpp
|
||||
// copyright 2000 Verant Interactive
|
||||
// Author: Justin Randall
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "serverUtility/ConfigServerUtility.h"
|
||||
#include "sharedFoundation/ConfigFile.h"
|
||||
#include "sharedNetwork/SetupSharedNetwork.h"
|
||||
#include "ConfigChatServer.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ConfigChatServer::Data * ConfigChatServer::data = 0;
|
||||
|
||||
#define KEY_INT(a,b) (data->a = ConfigFile::getKeyInt("ChatServer", #a, b))
|
||||
#define KEY_STRING(a,b) (data->a = ConfigFile::getKeyString("ChatServer", #a, b))
|
||||
#define KEY_BOOL(a,b) (data->a = ConfigFile::getKeyBool("ChatServer", #a, b))
|
||||
|
||||
//Commented out so lint doesn't whine that we're not using them
|
||||
//#define KEY_REAL(a,b) (data->a = ConfigFile::getKeyReal("ChatServer", #a, b))
|
||||
|
||||
// ======================================================================
|
||||
|
||||
namespace ConfigChatServerNamespace
|
||||
{
|
||||
typedef std::vector<char const *> StringPtrArray;
|
||||
StringPtrArray ms_createRoom; // ConfigFile owns the pointer
|
||||
StringPtrArray ms_voiceGateways;
|
||||
}
|
||||
|
||||
using namespace ConfigChatServerNamespace;
|
||||
|
||||
// ======================================================================
|
||||
|
||||
int ConfigChatServer::getNumberOfCreateRooms()
|
||||
{
|
||||
return static_cast<int>(ms_createRoom.size());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
char const * ConfigChatServer::getCreateRoom(int index)
|
||||
{
|
||||
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfCreateRooms());
|
||||
return ms_createRoom[static_cast<size_t>(index)];
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
int ConfigChatServer::getNumberOfVoiceChatGateways()
|
||||
{
|
||||
return static_cast<int>(ms_voiceGateways.size());
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
char const * ConfigChatServer::getVoiceChatGateway(int index)
|
||||
{
|
||||
VALIDATE_RANGE_INCLUSIVE_EXCLUSIVE(0, index, getNumberOfVoiceChatGateways());
|
||||
return ms_voiceGateways[static_cast<size_t>(index)];
|
||||
}
|
||||
|
||||
void ConfigChatServer::install(void)
|
||||
{
|
||||
ConfigServerUtility::install();
|
||||
|
||||
SetupSharedNetwork::SetupData networkSetupData;
|
||||
SetupSharedNetwork::getDefaultServerSetupData(networkSetupData);
|
||||
SetupSharedNetwork::install(networkSetupData);
|
||||
|
||||
data = new ConfigChatServer::Data;
|
||||
|
||||
KEY_STRING (backupGatewayServerIP, "swo-dev8.station.sony.com");
|
||||
KEY_INT (backupGatewayServerPort, 15150);
|
||||
KEY_STRING (clusterName, "devcluster");
|
||||
KEY_STRING (centralServerAddress, "swo-dev8.station.sony.com");
|
||||
KEY_INT (centralServerPort, 61232);
|
||||
KEY_STRING (gameCode, "SWG");
|
||||
KEY_STRING (gatewayServerIP, "sdplatdev1.station.sony.com");
|
||||
KEY_INT (gatewayServerPort, 5001);
|
||||
KEY_INT (roomInactivityTimeout, 60 * 60 * 24 * 3);
|
||||
KEY_INT (roomUnpopulatedTimeout, 60 * 5);
|
||||
KEY_STRING (gameServiceBindInterface, "");
|
||||
KEY_STRING (planetServiceBindInterface, "");
|
||||
KEY_INT (loginFlowControlRate, 50);
|
||||
KEY_INT (maxRoomQueriesPerFrame, 5);
|
||||
KEY_BOOL (loggingEnabled, false);
|
||||
KEY_STRING (registrarHost, "sdplatdev1.station.sony.com");
|
||||
KEY_INT (registrarPort, 5000);
|
||||
KEY_INT (intervalToSendHeadersToClientSeconds, 1);
|
||||
KEY_INT (maxHeadersToSendToClientPerInterval, 100);
|
||||
KEY_INT (chatStatisticsReportIntervalSeconds, 60);
|
||||
KEY_INT (chatSpamLimiterNumCharacters, 400);
|
||||
KEY_BOOL (chatSpamLimiterEnabledForFreeTrial, true);
|
||||
KEY_INT (chatSpamNotifyPlayerWhenLimitedIntervalSeconds, 30); // <= 0 to disable
|
||||
KEY_BOOL (voiceChatLoggingEnabled, false);
|
||||
KEY_INT (voiceChatRoomListRefresh, 600000);
|
||||
|
||||
int index = 0;
|
||||
char const * result = 0;
|
||||
do
|
||||
{
|
||||
result = ConfigFile::getKeyString("ChatServer", "createRoom", index++, 0);
|
||||
if (result != 0)
|
||||
{
|
||||
ms_createRoom.push_back(result);
|
||||
}
|
||||
}
|
||||
while (result);
|
||||
|
||||
index = 0;
|
||||
result = 0;
|
||||
do
|
||||
{
|
||||
result = ConfigFile::getKeyString("ChatServer", "voiceChatGateway", index++, 0);
|
||||
if(result != 0)
|
||||
{
|
||||
ms_voiceGateways.push_back(result);
|
||||
}
|
||||
} while(result);
|
||||
|
||||
if(ms_voiceGateways.empty())
|
||||
{
|
||||
static char const * const defaultGateway = "sdt-plattestsys1:9102";
|
||||
ms_voiceGateways.push_back(defaultGateway);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConfigChatServer::remove(void)
|
||||
{
|
||||
delete data;
|
||||
data = 0;
|
||||
ConfigServerUtility::remove();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
bool ConfigChatServer::isLoggingEnabled()
|
||||
{
|
||||
return data->loggingEnabled;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -0,0 +1,247 @@
|
||||
// ConfigChatServer.h
|
||||
// copyright 2000 Verant Interactive
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _ConfigChatServer_H
|
||||
#define _ConfigChatServer_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ConfigChatServer
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
const char * backupGatewayServerIP;
|
||||
int backupGatewayServerPort;
|
||||
const char * clusterName;
|
||||
const char * centralServerAddress;
|
||||
int centralServerPort;
|
||||
const char * gameCode;
|
||||
const char * gatewayServerIP;
|
||||
int gatewayServerPort;
|
||||
time_t roomInactivityTimeout;
|
||||
time_t roomUnpopulatedTimeout;
|
||||
const char * gameServiceBindInterface;
|
||||
const char * planetServiceBindInterface;
|
||||
int loginFlowControlRate;
|
||||
int maxRoomQueriesPerFrame;
|
||||
bool loggingEnabled;
|
||||
const char * registrarHost;
|
||||
int registrarPort;
|
||||
int intervalToSendHeadersToClientSeconds;
|
||||
int maxHeadersToSendToClientPerInterval;
|
||||
int chatStatisticsReportIntervalSeconds;
|
||||
int chatSpamLimiterNumCharacters;
|
||||
bool chatSpamLimiterEnabledForFreeTrial;
|
||||
int chatSpamNotifyPlayerWhenLimitedIntervalSeconds;
|
||||
bool voiceChatLoggingEnabled;
|
||||
int voiceChatRoomListRefresh;
|
||||
};
|
||||
|
||||
static const char * getBackupGatewayServerIP ();
|
||||
static const unsigned short getBackupGatewayServerPort ();
|
||||
static const char * getCentralServerAddress ();
|
||||
static const unsigned short getCentralServerPort ();
|
||||
static const char * getClusterName ();
|
||||
static const char * getGameCode ();
|
||||
static const char * getGatewayServerIP ();
|
||||
static const unsigned short getGatewayServerPort ();
|
||||
static const time_t getRoomInactivityTimeout ();
|
||||
static const time_t getRoomUnpopulatedTimeout ();
|
||||
static const char * getGameServiceBindInterface ();
|
||||
static const char * getPlanetServiceBindInterface ();
|
||||
static int getLoginFlowControlRate ();
|
||||
static int getMaxRoomQueriesPerFrame ();
|
||||
static void install ();
|
||||
static void remove ();
|
||||
static bool isLoggingEnabled();
|
||||
static const char * getRegistrarHost ();
|
||||
static int getRegistrarPort ();
|
||||
static int getNumberOfCreateRooms();
|
||||
static char const * getCreateRoom(int index);
|
||||
static int getIntervalToSendHeadersToClientSeconds();
|
||||
static int getMaxHeadersToSendToClientPerInterval();
|
||||
static int getChatStatisticsReportIntervalSeconds();
|
||||
static int getChatSpamLimiterNumCharacters();
|
||||
static bool getChatSpamLimiterEnabledForFreeTrial();
|
||||
static int getChatSpamNotifyPlayerWhenLimitedIntervalSeconds();
|
||||
static bool getVoiceChatLoggingEnabled();
|
||||
static int getVChatRoomListRefresh();
|
||||
static int getNumberOfVoiceChatGateways();
|
||||
static char const * getVoiceChatGateway(int index);
|
||||
|
||||
|
||||
private:
|
||||
static Data * data;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char * ConfigChatServer::getBackupGatewayServerIP()
|
||||
{
|
||||
return data->backupGatewayServerIP;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const unsigned short ConfigChatServer::getBackupGatewayServerPort()
|
||||
{
|
||||
return static_cast<unsigned short>(data->backupGatewayServerPort);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char * ConfigChatServer::getCentralServerAddress()
|
||||
{
|
||||
return data->centralServerAddress;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const unsigned short ConfigChatServer::getCentralServerPort()
|
||||
{
|
||||
return static_cast<unsigned short>(data->centralServerPort);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char * ConfigChatServer::getClusterName()
|
||||
{
|
||||
return data->clusterName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char * ConfigChatServer::getGameCode()
|
||||
{
|
||||
return data->gameCode;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char * ConfigChatServer::getGatewayServerIP()
|
||||
{
|
||||
return data->gatewayServerIP;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const unsigned short ConfigChatServer::getGatewayServerPort()
|
||||
{
|
||||
return static_cast<unsigned short>(data->gatewayServerPort);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const time_t ConfigChatServer::getRoomInactivityTimeout()
|
||||
{
|
||||
return static_cast<time_t>(data->roomInactivityTimeout);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const time_t ConfigChatServer::getRoomUnpopulatedTimeout()
|
||||
{
|
||||
return static_cast<time_t>(data->roomUnpopulatedTimeout);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char * ConfigChatServer::getGameServiceBindInterface()
|
||||
{
|
||||
return data->gameServiceBindInterface;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char * ConfigChatServer::getPlanetServiceBindInterface()
|
||||
{
|
||||
return data->planetServiceBindInterface;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getLoginFlowControlRate()
|
||||
{
|
||||
return data->loginFlowControlRate;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getMaxRoomQueriesPerFrame()
|
||||
{
|
||||
return data->maxRoomQueriesPerFrame;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline const char * ConfigChatServer::getRegistrarHost()
|
||||
{
|
||||
return data->registrarHost;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getRegistrarPort()
|
||||
{
|
||||
return data->registrarPort;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getIntervalToSendHeadersToClientSeconds()
|
||||
{
|
||||
return data->intervalToSendHeadersToClientSeconds;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getMaxHeadersToSendToClientPerInterval()
|
||||
{
|
||||
return data->maxHeadersToSendToClientPerInterval;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getChatStatisticsReportIntervalSeconds()
|
||||
{
|
||||
return data->chatStatisticsReportIntervalSeconds;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getChatSpamLimiterNumCharacters()
|
||||
{
|
||||
return data->chatSpamLimiterNumCharacters;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline bool ConfigChatServer::getChatSpamLimiterEnabledForFreeTrial()
|
||||
{
|
||||
return data->chatSpamLimiterEnabledForFreeTrial;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getChatSpamNotifyPlayerWhenLimitedIntervalSeconds()
|
||||
{
|
||||
return data->chatSpamNotifyPlayerWhenLimitedIntervalSeconds;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline bool ConfigChatServer::getVoiceChatLoggingEnabled()
|
||||
{
|
||||
return data->voiceChatLoggingEnabled;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
inline int ConfigChatServer::getVChatRoomListRefresh()
|
||||
{
|
||||
return data->voiceChatRoomListRefresh;
|
||||
}
|
||||
|
||||
#endif // _ConfigChatServer_H
|
||||
@@ -0,0 +1,480 @@
|
||||
// ConnectionServerConnection.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
#include "FirstChatServer.h"
|
||||
|
||||
#include "ChatInterface.h"
|
||||
#include "ChatServer.h"
|
||||
#include "ChatServerAvatarOwner.h"
|
||||
#include "ConfigChatServer.h"
|
||||
#include "ConnectionServerConnection.h"
|
||||
#include "VChatInterface.h"
|
||||
#include "serverNetworkMessages/ChatConnectAvatar.h"
|
||||
#include "serverNetworkMessages/ChatDisconnectAvatar.h"
|
||||
#include "serverNetworkMessages/GameConnectionServerMessages.h"
|
||||
#include "sharedDebug/Profiler.h"
|
||||
#include "sharedFoundation/NetworkIdArchive.h"
|
||||
#include "sharedLog/Log.h"
|
||||
#include "sharedMessageDispatch/Transceiver.h"
|
||||
#include "sharedNetwork/NetworkSetupData.h"
|
||||
#include "sharedNetworkMessages/ChatAddFriend.h"
|
||||
#include "sharedNetworkMessages/ChatAddModeratorToRoom.h"
|
||||
#include "sharedNetworkMessages/ChatBanAvatarFromRoom.h"
|
||||
#include "sharedNetworkMessages/ChatCreateRoom.h"
|
||||
#include "sharedNetworkMessages/ChatDeletePersistentMessage.h"
|
||||
#include "sharedNetworkMessages/ChatDeleteAllPersistentMessages.h"
|
||||
#include "sharedNetworkMessages/ChatDestroyRoom.h"
|
||||
#include "sharedNetworkMessages/ChatEnterRoom.h"
|
||||
#include "sharedNetworkMessages/ChatEnterRoomById.h"
|
||||
#include "sharedNetworkMessages/ChatInstantMessageToCharacter.h"
|
||||
#include "sharedNetworkMessages/ChatInstantMessageToClient.h"
|
||||
#include "sharedNetworkMessages/ChatInviteAvatarToRoom.h"
|
||||
#include "sharedNetworkMessages/ChatKickAvatarFromRoom.h"
|
||||
#include "sharedNetworkMessages/ChatOnSendInstantMessage.h"
|
||||
#include "sharedNetworkMessages/ChatQueryRoom.h"
|
||||
#include "sharedNetworkMessages/ChatPersistentMessageToClient.h"
|
||||
#include "sharedNetworkMessages/ChatPersistentMessageToServer.h"
|
||||
#include "sharedNetworkMessages/ChatRemoveAvatarFromRoom.h"
|
||||
#include "sharedNetworkMessages/ChatRemoveModeratorFromRoom.h"
|
||||
#include "sharedNetworkMessages/ChatRequestPersistentMessage.h"
|
||||
#include "sharedNetworkMessages/ChatSendToRoom.h"
|
||||
#include "sharedNetworkMessages/ChatUnbanAvatarFromRoom.h"
|
||||
#include "sharedNetworkMessages/ChatUninviteFromRoom.h"
|
||||
#include "sharedNetworkMessages/VerifyPlayerNameMessage.h"
|
||||
#include "sharedNetworkMessages/VerifyPlayerNameResponseMessage.h"
|
||||
#include "sharedNetworkMessages/VoiceChatMiscMessages.h"
|
||||
#include "UnicodeUtils.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ConnectionServerConnection::ConnectionServerConnection(const std::string & a, const unsigned short p) :
|
||||
ServerConnection(a, p, NetworkSetupData()),
|
||||
m_avatars()
|
||||
{
|
||||
ChatServer::fileLog(true, "ConnectionServerConnection", "Connection created...listening on (%s:%d)", a.c_str(), static_cast<int>(p));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
ConnectionServerConnection::~ConnectionServerConnection()
|
||||
{
|
||||
ChatServer::fileLog(true, "ConnectionServerConnection", "~ConnectionServerConnection() - %s:%d", getRemoteAddress().c_str(), getRemotePort());
|
||||
|
||||
std::set<ChatServerAvatarOwner *>::iterator i;
|
||||
for(i = m_avatars.begin(); i != m_avatars.end(); ++i)
|
||||
{
|
||||
(*i)->setPlayerConnection(0);
|
||||
}
|
||||
|
||||
ChatServer::removeConnectionServerConnection(this);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConnectionServerConnection::onConnectionClosed()
|
||||
{
|
||||
ChatServer::fileLog(true, "ConnectionServerConnection", "onConnectionClosed()");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConnectionServerConnection::onConnectionOpened()
|
||||
{
|
||||
ChatServer::fileLog(true, "ConnectionServerConnection", "onConnectionOpened()");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConnectionServerConnection::onReceive(const Archive::ByteStream & message)
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
GameNetworkMessage m(ri);
|
||||
/*
|
||||
static int count = 0;
|
||||
if ((count % 10) == 0)
|
||||
{
|
||||
ChatServer::getChatInterface()->Process();
|
||||
}
|
||||
++count;*/
|
||||
|
||||
ri = message.begin();
|
||||
|
||||
//LOG("ConnectionServerConnection", ("onReceive() message(%s)", m.getCmdName().c_str()));
|
||||
|
||||
if(m.isType("ChatConnectAvatar"))
|
||||
{
|
||||
//printf("ConnectionServerConnection -- ChatConnectAvatar\n");
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatConnectAvatar");
|
||||
ChatConnectAvatar c(ri);
|
||||
// break surname from last name
|
||||
std::string name = c.getCharacterName();
|
||||
size_t pos = name.find_first_of(" ");
|
||||
if(pos != std::string::npos)
|
||||
name = name.substr(0, pos);
|
||||
ChatServer::connectPlayer(this, c.getStationId(), name, c.getCharacterId(), c.getIsSecure(), c.getIsSubscribed());
|
||||
}
|
||||
else if(m.isType("ChatDisconnectAvatar"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatDisconnectAvatar");
|
||||
//printf("ConnectionServerConnection -- ChatDisconnectAvatar\n");
|
||||
static MessageDispatch::Transceiver<const ChatDisconnectAvatar &> disconn;
|
||||
ChatDisconnectAvatar d(ri);
|
||||
disconn.emitMessage(d);
|
||||
ChatServer::disconnectPlayer(d.getCharacterId());
|
||||
}
|
||||
else if(m.isType("GameClientMessage"))
|
||||
{
|
||||
// chat message forwarded by the connection server
|
||||
GameClientMessage c(ri);
|
||||
//deliverMessageToClientObject(c.getNetworkId(), c.getByteStream());
|
||||
Archive::ReadIterator cri = c.getByteStream().begin();
|
||||
GameNetworkMessage cm(cri);
|
||||
std::vector<NetworkId>::const_iterator i;
|
||||
for(i = c.getDistributionList().begin(); i != c.getDistributionList().end(); ++i)
|
||||
{
|
||||
const ChatAvatar * avatar = ChatServer::getAvatarByNetworkId(*i);
|
||||
if (!avatar && cm.isType("ChatInstantMessageToCharacter"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatInstantMessageToCharacter");
|
||||
//printf("!Sending via the shortcut\n");
|
||||
cri = c.getByteStream().begin();
|
||||
|
||||
static const std::string gameType("SWG");
|
||||
if(cm.isType("ChatInstantMessageToCharacter"))
|
||||
{
|
||||
// deliver IM to character
|
||||
ChatInstantMessageToCharacter chat(cri);
|
||||
ChatAvatarId characterName = chat.getCharacterName();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
|
||||
ChatAvatarId fromName;
|
||||
fromName.gameCode = "SWG";
|
||||
fromName.cluster = ConfigChatServer::getClusterName();
|
||||
fromName.name = ChatServer::getChatInterface()->getChatName((*i));
|
||||
|
||||
ChatInstantMessageToClient msg(fromName, chat.getMessage(), chat.getOutOfBand());
|
||||
bool sent = ChatServer::getChatInterface()->sendMessageToPendingAvatar(characterName, msg);
|
||||
if (!sent)
|
||||
{
|
||||
ChatServer::getChatInterface()->sendMessageToAvatar(characterName, msg);
|
||||
}
|
||||
|
||||
ChatOnSendInstantMessage response(chat.getSequence(), 0);
|
||||
ChatServer::getChatInterface()->sendMessageToPendingAvatar(fromName, response);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(avatar)
|
||||
{
|
||||
cri = c.getByteStream().begin();
|
||||
|
||||
static const std::string gameType("SWG");
|
||||
|
||||
if(cm.isType("ChatDeleteAllPersistentMessages"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatDeleteAllPersistentMessages");
|
||||
ChatDeleteAllPersistentMessages chatDeleteAllPersistentMessages(cri);
|
||||
ChatServer::deleteAllPersistentMessages(chatDeleteAllPersistentMessages.getSourceNetworkId(), chatDeleteAllPersistentMessages.getTargetNetworkId());
|
||||
}
|
||||
else if(cm.isType("ChatInstantMessageToCharacter"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatInstantMessageToCharacter");
|
||||
//printf("ConnectionServerConnection -- ChatInstantMessageToCharacter\n");
|
||||
// deliver IM to character
|
||||
ChatInstantMessageToCharacter chat(cri);
|
||||
ChatAvatarId characterName = chat.getCharacterName();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
|
||||
ChatServer::sendInstantMessage(*i, chat.getSequence(), characterName, chat.getMessage(), chat.getOutOfBand());
|
||||
}
|
||||
else if(cm.isType("ChatQueryRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatQueryRoom");
|
||||
//printf("ConnectionServerConnection -- ChatQueryRoom\n");
|
||||
ChatQueryRoom chat(cri);
|
||||
ChatServer::queryRoom((*i), this, chat.getSequence(), chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatPersistentMessageToServer"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatPeristentMessageToServer");
|
||||
//printf("ConnectionServerConnection -- ChatPersistentMessageToServer\n");
|
||||
ChatPersistentMessageToServer chat(cri);
|
||||
ChatAvatarId characterName = chat.getToCharacterName();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
|
||||
ChatServer::sendPersistentMessage((*i), chat.getSequence(), characterName, chat.getSubject(), chat.getMessage(), chat.getOutOfBand());
|
||||
}
|
||||
else if(cm.isType("ChatRequestPersistentMessage"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatRequestPersistentMessage");
|
||||
//printf("ConnectionServerConnection -- ChatRequestPersistentMessage\n");
|
||||
ChatRequestPersistentMessage chat(cri);
|
||||
ChatServer::requestPersistentMessage((*i), chat.getSequence(), chat.getMessageId());
|
||||
}
|
||||
else if(cm.isType("ChatDeletePersistentMessage"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatDeletePersistentMessage");
|
||||
//printf("ConnectionServerConnection -- ChatDeletePersistentMessage\n");
|
||||
ChatDeletePersistentMessage chat(cri);
|
||||
ChatServer::deletePersistentMessage((*i), chat.getMessageId());
|
||||
}
|
||||
else if(cm.isType("ChatCreateRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatCreateRoom");
|
||||
//printf("ConnectionServerConnection -- ChatCreateRoom\n");
|
||||
ChatCreateRoom chat(cri);
|
||||
ChatServer::createRoom((*i), chat.getSequence(), chat.getRoomName(), chat.getIsModerated(), chat.getIsPublic(), chat.getRoomTitle());
|
||||
}
|
||||
else if(cm.isType("ChatEnterRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatEnterRoom");
|
||||
//printf("ConnectionServerConnection -- ChatEnterRoom\n");
|
||||
// entering a room by name
|
||||
ChatEnterRoom chat(cri);
|
||||
ChatServer::enterRoom((*i), chat.getSequence(), chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatEnterRoomById"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatEnterRoomById");
|
||||
//printf("ConnectionServerConnection -- ChatEnterRoomById\n");
|
||||
// entering a room by room id
|
||||
ChatEnterRoomById chat(cri);
|
||||
ChatServer::enterRoom((*i), chat.getSequence(), chat.getRoomId());
|
||||
|
||||
}
|
||||
else if(cm.isType("ChatSendToRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatSendToRoom");
|
||||
//printf("ConnectionServerConnection -- ChatSendToRoom\n");
|
||||
ChatSendToRoom chat(cri);
|
||||
ChatServer::sendRoomMessage((*i), chat.getSequence(), chat.getRoomId(), chat.getMessage(), chat.getOutOfBand());
|
||||
}
|
||||
else if(cm.isType("ChatRequestRoomList"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatRequestRoomList");
|
||||
//printf("ConnectionServerConnection -- ChatRequestRoomList\n");
|
||||
ChatServer::requestRoomList((*i), this);
|
||||
}
|
||||
else if(cm.isType("ChatDestroyRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatDestroyRoom");
|
||||
//printf("ConnectionServerConnection -- ChatDestroyRoom\n");
|
||||
ChatDestroyRoom chat(cri);
|
||||
ChatServer::destroyRoom((*i), chat.getSequence(), chat.getRoomId());
|
||||
}
|
||||
else if(cm.isType("ChatAddModeratorToRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatAddModeratorToRoom");
|
||||
//printf("ConnectionServerConnection -- ChatAddModeratorToRoom\n");
|
||||
ChatAddModeratorToRoom chat(cri);
|
||||
ChatServer::addModeratorToRoom(chat.getSequenceId(), (*i), chat.getAvatarId(), chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatRemoveModeratorFromRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatRemoveModeratorFromRoom");
|
||||
//printf("ConnectionServerConnection -- ChatREmoveModeratorFromRoom\n");
|
||||
ChatRemoveModeratorFromRoom chat(cri);
|
||||
ChatAvatarId characterName = chat.getAvatarId();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
ChatServer::removeModeratorFromRoom(chat.getSequenceId(), (*i), characterName, chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatRemoveAvatarFromRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatRemoveAvatarFromRoom");
|
||||
//printf("ConnectionServerConnection -- ChatREmoveAvatarFromRoom\n");
|
||||
ChatRemoveAvatarFromRoom chat(cri);
|
||||
ChatServer::removeAvatarFromRoom((*i), chat.getAvatarId(), chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatKickAvatarFromRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatKickAvatarFromRoom");
|
||||
//printf("ConnectionServerConnection -- ChatKickAvatarFromRoom\n");
|
||||
ChatKickAvatarFromRoom chat(cri);
|
||||
ChatServer::kickAvatarFromRoom((*i), chat.getAvatarId(), chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatAddFriend"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatAddFriend");
|
||||
//printf("ConnectionServerConnection -- ChatAddFriend\n");
|
||||
ChatAddFriend chat(ri);
|
||||
ChatServer::addFriend((*i), chat.getSequence(), chat.getCharacterName());
|
||||
}
|
||||
else if(cm.isType("ChatInviteAvatarToRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatInviteAvatarToRoom");
|
||||
//printf("ConnectionServerConnection -- ChatInviteAvatarToRoom\n");
|
||||
ChatInviteAvatarToRoom chat(cri);
|
||||
ChatAvatarId characterName = chat.getAvatarId();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
ChatServer::invite((*i), characterName, chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatUninviteFromRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatUninviteFromRoom");
|
||||
//printf("ConnectionServerConnection -- ChatUninviteAvatarToRoom\n");
|
||||
ChatUninviteFromRoom chat(cri);
|
||||
ChatAvatarId characterName = chat.getAvatar();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
ChatServer::uninvite((*i), chat.getSequence(), characterName, chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatBanAvatarFromRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatBanAvatarFromRoom");
|
||||
//printf("ConnectionServerConnection -- ChatBanAvatarFromRoom\n");
|
||||
ChatBanAvatarFromRoom chat(cri);
|
||||
ChatAvatarId characterName = chat.getAvatarId();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
ChatServer::banFromRoom(chat.getSequence(), (*i), characterName, chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("ChatUnbanAvatarFromRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - ChatUnbanAvatarFromRoom");
|
||||
//printf("ConnectionServerConnection -- ChatUnbanAvatarFromRoom\n");
|
||||
ChatUnbanAvatarFromRoom chat(cri);
|
||||
ChatAvatarId characterName = chat.getAvatarId();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
ChatServer::unbanFromRoom(chat.getSequence(), (*i), characterName, chat.getRoomName());
|
||||
}
|
||||
else if(cm.isType("VerifyPlayerNameMessage"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("ConnectionServer - VerifyPlayerNameMessage");
|
||||
VerifyPlayerNameMessage message(cri);
|
||||
|
||||
bool const valid = ChatServer::isValidChatAvatarName(message.getPlayerName());
|
||||
|
||||
VerifyPlayerNameResponseMessage response(valid, message.getPlayerName());
|
||||
|
||||
ChatServer::fileLog(true, "ConnectionServerConnection", "onReceive() message(VerifyPlayerNameMessage) name(%s) valid(%s)", Unicode::wideToNarrow(message.getPlayerName()).c_str(), (valid ? "yes" : "no"));
|
||||
|
||||
sendToClient(message.getSourceNetworkId(), response);
|
||||
}
|
||||
|
||||
//messages to allow personal channels
|
||||
else if (cm.isType(VoiceChatRequestPersonalChannel::cms_name))
|
||||
{
|
||||
VoiceChatRequestPersonalChannel message(cri);
|
||||
|
||||
std::string userName, playerName;
|
||||
if(ChatServer::getVoiceChatLoginInfoFromId(message.getOwner(), userName, playerName))
|
||||
{
|
||||
std::list<std::string> modlist;
|
||||
modlist.push_back(userName);
|
||||
|
||||
if(message.getShouldCreate())
|
||||
{
|
||||
// 400 is the current vivox channel size limit when this was written
|
||||
ChatServer::requestGetChannel(message.getOwner(), ChatServer::getVChatInterface()->buildPersonalChannelName(message.getOwner()), false, false, 400, modlist);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatServer::getVChatInterface()->sendChannelData(message.getOwner(), ChatServer::getVChatInterface()->buildPersonalChannelName(message.getOwner()), "", true, true);
|
||||
}
|
||||
}
|
||||
//@TODO: error message?
|
||||
}
|
||||
else if (cm.isType(VoiceChatInvite::cms_name))
|
||||
{
|
||||
VoiceChatInvite message(cri);
|
||||
if(message.getChannelName() == ChatServer::getVChatInterface()->buildPersonalChannelName(message.getRequester()))
|
||||
{
|
||||
NetworkId targetId = message.getInviteeId();
|
||||
std::string const & targetName = message.getInviteeName();
|
||||
if(targetId.isValid() ||
|
||||
!targetName.empty() && ChatServer::getVoiceChatLoginInfoFromName(targetName, targetId))
|
||||
{
|
||||
ChatServer::requestInvitePlayerToChannel(message.getRequester(), targetId, message.getChannelName());
|
||||
}
|
||||
}
|
||||
//@TODO: error message?
|
||||
}
|
||||
else if (cm.isType(VoiceChatKick::cms_name))
|
||||
{
|
||||
VoiceChatKick message(cri);
|
||||
if(message.getChannelName() == ChatServer::getVChatInterface()->buildPersonalChannelName(message.getRequester()))
|
||||
{
|
||||
NetworkId targetId = message.getKickeeId();
|
||||
std::string const & targetName = message.getKickeeName();
|
||||
if(targetId.isValid() ||
|
||||
!targetName.empty() && ChatServer::getVoiceChatLoginInfoFromName(targetName, targetId))
|
||||
{
|
||||
ChatServer::requestKickPlayerFromChannel(message.getRequester(), targetId, message.getChannelName());
|
||||
}
|
||||
}
|
||||
//@TODO: error message?
|
||||
}
|
||||
else if (cm.isType(VoiceChatRequestChannelInfo::cms_name))
|
||||
{
|
||||
VoiceChatRequestChannelInfo message(cri);
|
||||
ChatServer::requestChannelInfo(message.getRequester(), message.getChannelName());
|
||||
}
|
||||
}
|
||||
|
||||
// @todo : how is a message sent to anyone with a station account?
|
||||
|
||||
else
|
||||
{
|
||||
// defer until avatar is connected to chat backend
|
||||
ChatServer::deferChatMessageFor((*i), message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConnectionServerConnection::sendToClient(const NetworkId & clientId, const GameNetworkMessage & message)
|
||||
{
|
||||
static std::vector<NetworkId> v;
|
||||
v.clear();
|
||||
v.push_back(clientId);
|
||||
GameClientMessage msg(v, true, message);
|
||||
ServerConnection::send(msg, true);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConnectionServerConnection::addAvatar(ChatServerAvatarOwner * a)
|
||||
{
|
||||
m_avatars.insert(a);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void ConnectionServerConnection::removeAvatar(ChatServerAvatarOwner * a)
|
||||
{
|
||||
std::set<ChatServerAvatarOwner *>::iterator f = m_avatars.find(a);
|
||||
if(f != m_avatars.end())
|
||||
m_avatars.erase(f);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
// ConnectionServerConnection.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_ConnectionServerConnection_H
|
||||
#define _INCLUDED_ConnectionServerConnection_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverUtility/ServerConnection.h"
|
||||
#include <set>
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class ChatServerAvatarOwner;
|
||||
class GameNetworkMessage;
|
||||
|
||||
class ConnectionServerConnection : public ServerConnection
|
||||
{
|
||||
public:
|
||||
ConnectionServerConnection(const std::string & remoteAddress, const unsigned short remotePort);
|
||||
~ConnectionServerConnection();
|
||||
|
||||
void addAvatar (ChatServerAvatarOwner * avatar);
|
||||
void onConnectionClosed ();
|
||||
void onConnectionOpened ();
|
||||
void onReceive (const Archive::ByteStream & bs);
|
||||
void removeAvatar (ChatServerAvatarOwner * avatar);
|
||||
void sendToClient (const NetworkId & clientId, const GameNetworkMessage & message);
|
||||
|
||||
private:
|
||||
ConnectionServerConnection & operator = (const ConnectionServerConnection & rhs);
|
||||
ConnectionServerConnection(const ConnectionServerConnection & source);
|
||||
|
||||
std::set<ChatServerAvatarOwner *> m_avatars;
|
||||
|
||||
}; //lint !e1712 default constructor not defined for class
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_ConnectionServerConnection_H
|
||||
@@ -0,0 +1,61 @@
|
||||
// CustomerServiceServerConnection.cpp
|
||||
// Copyright 2004, Sony Online Entertainment Inc., all rights reserved.
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "CustomerServiceServerConnection.h"
|
||||
|
||||
#include "ChatInterface.h"
|
||||
#include "ChatServer.h"
|
||||
#include "sharedLog/Log.h"
|
||||
#include "sharedNetwork/NetworkSetupData.h"
|
||||
#include "sharedNetworkMessages/ChatRequestLog.h"
|
||||
#include "sharedNetworkMessages/ChatOnRequestLog.h"
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
CustomerServiceServerConnection::CustomerServiceServerConnection(const std::string & a, const unsigned short p)
|
||||
: ServerConnection(a, p, NetworkSetupData())
|
||||
{
|
||||
ChatServer::fileLog(true, "CSServerConnection", "Connection created...listening on (%s:%d)", a.c_str(), static_cast<int>(p));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
CustomerServiceServerConnection::~CustomerServiceServerConnection()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void CustomerServiceServerConnection::onConnectionClosed()
|
||||
{
|
||||
ChatServer::fileLog(true, "CSServerConnection", "onConnectionClosed()");
|
||||
|
||||
ChatServer::clearCustomerServiceServerConnection();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void CustomerServiceServerConnection::onConnectionOpened()
|
||||
{
|
||||
ChatServer::fileLog(true, "CSServerConnection", "onConnectionOpened()");
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
void CustomerServiceServerConnection::onReceive(const Archive::ByteStream & message)
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
GameNetworkMessage gameNetworkMessage(ri);
|
||||
|
||||
if (gameNetworkMessage.isType("ChatRequestLog"))
|
||||
{
|
||||
ri = message.begin();
|
||||
ChatRequestLog chatRequestLog(ri);
|
||||
|
||||
std::vector<ChatLogEntry> chatLog;
|
||||
ChatServer::getChatLog(chatRequestLog.getPlayer(), chatLog);
|
||||
|
||||
ChatServer::fileLog(true, "CSServerConnection", "onReceive() message(ChatRequestLog) player(%s) sequenceId(%i) chatLogSize(%i)", Unicode::wideToNarrow(chatRequestLog.getPlayer()).c_str(), chatRequestLog.getSequence(), chatLog.size());
|
||||
|
||||
ChatOnRequestLog chatOnRequestLog(chatRequestLog.getSequence(), chatLog);
|
||||
send(chatOnRequestLog, true);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
@@ -0,0 +1,33 @@
|
||||
// CustomerServiceServerConnection.h
|
||||
// Copyright 2004, Sony Online Entertainment Inc., all rights reserved.
|
||||
|
||||
#ifndef INCLUDED_CustomerServiceServerConnection_H
|
||||
#define INCLUDED_CustomerServiceServerConnection_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverUtility/ServerConnection.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class CustomerServiceServerConnection : public ServerConnection
|
||||
{
|
||||
public:
|
||||
|
||||
CustomerServiceServerConnection(const std::string & remoteAddress, const unsigned short remotePort);
|
||||
virtual ~CustomerServiceServerConnection();
|
||||
|
||||
void onConnectionClosed();
|
||||
void onConnectionOpened();
|
||||
void onReceive(const Archive::ByteStream & bs);
|
||||
|
||||
private:
|
||||
|
||||
CustomerServiceServerConnection();
|
||||
CustomerServiceServerConnection & operator = (const CustomerServiceServerConnection & rhs);
|
||||
CustomerServiceServerConnection(const CustomerServiceServerConnection & source);
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // INCLUDED_CustomerServiceServerConnection_H
|
||||
@@ -0,0 +1,7 @@
|
||||
// FirstChatServer.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
// FirstChatServer.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_FirstChatServer_H
|
||||
#define _INCLUDED_FirstChatServer_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#pragma warning ( disable : 4702 )
|
||||
|
||||
#include "sharedFoundation/FirstSharedFoundation.h"
|
||||
|
||||
// hack for gcc 3.4.x-3.5.0 bug
|
||||
#if defined(__GNUC__) && (__GNUC__ == 3) && (__GNUC_MINOR__ > 3)
|
||||
class TransferCharacterData;
|
||||
namespace Archive
|
||||
{
|
||||
class ByteStream;
|
||||
class ReadIterator;
|
||||
void get(ReadIterator &, TransferCharacterData &);
|
||||
void put(ByteStream &, TransferCharacterData const &);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "Archive/ByteStream.h"
|
||||
#include "sharedFoundation/NetworkId.h"
|
||||
#include "sharedNetwork/Connection.h"
|
||||
#include "ChatAPI/ChatAPI.h"
|
||||
#include <hash_map>
|
||||
#include <string>
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_FirstChatServer_H
|
||||
@@ -0,0 +1,397 @@
|
||||
// GameServerConnection.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "ChatInterface.h"
|
||||
#include "ChatServer.h"
|
||||
#include "ConfigChatServer.h"
|
||||
#include "GameServerConnection.h"
|
||||
#include "VChatInterface.h"
|
||||
#include "sharedDebug/Profiler.h"
|
||||
#include "sharedLog/Log.h"
|
||||
#include "sharedNetworkMessages/ChatAvatarId.h"
|
||||
#include "sharedNetworkMessages/ChatAvatarIdArchive.h"
|
||||
#include "sharedNetworkMessages/ChatChangeFriendStatus.h"
|
||||
#include "sharedNetworkMessages/ChatChangeIgnoreStatus.h"
|
||||
#include "sharedNetworkMessages/ChatCreateRoom.h"
|
||||
#include "sharedNetworkMessages/ChatDeleteAllPersistentMessages.h"
|
||||
#include "sharedNetworkMessages/ChatDestroyRoomByName.h"
|
||||
#include "sharedNetworkMessages/ChatDestroyRoomByName.h"
|
||||
#include "sharedNetworkMessages/ChatGetFriendsList.h"
|
||||
#include "sharedNetworkMessages/ChatGetIgnoreList.h"
|
||||
#include "sharedNetworkMessages/ChatInviteAvatarToRoom.h"
|
||||
#include "sharedNetworkMessages/ChatInviteGroupMembersToRoom.h"
|
||||
#include "sharedNetworkMessages/ChatMessageFromGame.h"
|
||||
#include "sharedNetworkMessages/GameNetworkMessage.h"
|
||||
#include "sharedNetworkMessages/ChatPutAvatarInRoom.h"
|
||||
#include "sharedNetworkMessages/ChatRemoveAvatarFromRoom.h"
|
||||
#include "sharedNetworkMessages/ChatOnRequestLog.h"
|
||||
#include "sharedNetworkMessages/ChatRequestLog.h"
|
||||
#include "sharedNetworkMessages/ChatUninviteFromRoom.h"
|
||||
#include "sharedNetworkMessages/GenericValueTypeMessage.h"
|
||||
#include "UnicodeUtils.h"
|
||||
|
||||
#include "sharedNetworkMessages/VoiceChatChannelInfo.h"
|
||||
#include "sharedNetworkMessages/VoiceChatMiscMessages.h"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
GameServerConnection::GameServerConnection(UdpConnectionMT * u, TcpClient * t) :
|
||||
ServerConnection (u, t),
|
||||
m_gameCode ("SWG"), //@todo: this class must not depend on SWG
|
||||
m_connectionId(0)
|
||||
{
|
||||
ChatServer::fileLog(true, "GameServerConnection", "Connection created...listening on (%s:%d)", getRemoteAddress().c_str(), static_cast<int>(getRemotePort()));
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
GameServerConnection::~GameServerConnection()
|
||||
{
|
||||
if(ChatServer::instance().getGameServerConnectionFromId(m_connectionId))
|
||||
{
|
||||
ChatServer::fileLog(true, "GameServerConnection", "~GameServerConnection still registered myID(%u) %p",m_connectionId, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatServer::fileLog(true, "GameServerConnection", "~GameServerConnection not registered anymore myID(%u) %p",m_connectionId, this);
|
||||
}
|
||||
|
||||
ChatServer::instance().unregisterGameServerConnection(m_connectionId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void GameServerConnection::onConnectionClosed()
|
||||
{
|
||||
ChatServer::fileLog(true, "GameServerConnection", "onConnectionClosed() myID(%u) %p",m_connectionId, this);
|
||||
|
||||
ChatServer::clearGameServerConnection(this);
|
||||
ChatServer::instance().unregisterGameServerConnection(m_connectionId);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void GameServerConnection::onConnectionOpened()
|
||||
{
|
||||
if(m_connectionId == 0)
|
||||
{
|
||||
m_connectionId = ChatServer::instance().registerGameServerConnection(this);
|
||||
ChatServer::fileLog(true, "GameServerConnection", "onConnectionOpened() new registration myID(%u) %p",m_connectionId, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatServer::fileLog(true, "GameServerConnection", "onConnectionOpened() ALREADY REGISTERED myID(%u) %p",m_connectionId, this);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void GameServerConnection::onReceive(const Archive::ByteStream & message)
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
GameNetworkMessage gameNetworkMessage(ri);
|
||||
ri = message.begin();
|
||||
|
||||
static int count = 0;
|
||||
if ((count % 10) == 0)
|
||||
{
|
||||
ChatServer::getChatInterface()->Process();
|
||||
}
|
||||
++count;
|
||||
|
||||
//LOG("GameServerConnection", ("onReceive - %s", gameNetworkMessage.getCmdName().c_str()));
|
||||
//DEBUG_REPORT_LOG(true, ("***ChatServ: GameServerConnection::onReceive() message(%s)\n", gameNetworkMessage.getCmdName().c_str()));
|
||||
|
||||
if(gameNetworkMessage.isType("ChatDeleteAllPersistentMessages"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatDeleteAllPersistentMessages");
|
||||
ChatDeleteAllPersistentMessages chatDeleteAllPersistentMessages(ri);
|
||||
ChatServer::deleteAllPersistentMessages(chatDeleteAllPersistentMessages.getSourceNetworkId(), chatDeleteAllPersistentMessages.getTargetNetworkId());
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatCreateRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatCreateRoom");
|
||||
//printf("GameServerConnection -- ChatCreateRoom\n");
|
||||
ChatCreateRoom chat(ri);
|
||||
unsigned int sequence = chat.getSequence();
|
||||
ChatServer::addGameServerConnection(sequence, this);
|
||||
ChatServer::createRoom(NetworkId::cms_invalid, sequence, chat.getRoomName(), chat.getIsModerated(), chat.getIsPublic(), chat.getRoomTitle());
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatRequestLog"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatRequestLog");
|
||||
ChatRequestLog chatRequestLog(ri);
|
||||
std::vector<ChatLogEntry> chatLog;
|
||||
ChatServer::getChatLog(chatRequestLog.getPlayer(), chatLog);
|
||||
|
||||
ChatOnRequestLog chatOnRequestLog(chatRequestLog.getSequence(), chatLog);
|
||||
|
||||
static Archive::ByteStream a;
|
||||
a.clear();
|
||||
chatOnRequestLog.pack(a);
|
||||
|
||||
(static_cast<Connection *>(this))->send(a, true);
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatDestroyRoomByName"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatDestroyRoomByName");
|
||||
//printf("GameServerConnection -- ChatDestroyRoomByName\n");
|
||||
ChatDestroyRoomByName chat(ri);
|
||||
ChatServer::destroyRoom(chat.getRoomPath());
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatPutAvatarInRoom"))
|
||||
{
|
||||
//printf("GameServerConnection -- ChatPutAvatarInRoom\n");
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatPutAvatarInRoom");
|
||||
ChatPutAvatarInRoom chat(ri);
|
||||
ChatAvatarId id;
|
||||
id.cluster = ConfigChatServer::getClusterName();
|
||||
id.gameCode = m_gameCode;
|
||||
id.name = chat.getAvatarName();
|
||||
size_t pos = id.name.find(" ");
|
||||
if(pos != std::string::npos)
|
||||
id.name = id.name.substr(0, pos);
|
||||
ChatServer::enterRoom(id, chat.getRoomName(), chat.getForceCreate(), chat.getCreatePrivate());
|
||||
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatInviteAvatarToRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatInviteAvatarToRoom");
|
||||
//printf("GameServerConnection -- ChatInviteAvatarToRoom\n");
|
||||
ChatInviteAvatarToRoom chat(ri);
|
||||
ChatAvatarId characterName = chat.getAvatarId();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
ChatServer::invite(NetworkId::cms_invalid, characterName, chat.getRoomName());
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatInviteGroupMembersToRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatInviteGroupMembersToRoom");
|
||||
//printf("GameServerConnection -- ChatInviteGroupMembersToRoom\n");
|
||||
ChatInviteGroupMembersToRoom chat(ri);
|
||||
ChatServer::inviteGroupMembers(chat.getInvitorNetworkId(), chat.getGroupLeaderId(), chat.getRoomName(), chat.getInvitedMembers());
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatUninviteFromRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatUninviteAvatarToRoom");
|
||||
//printf("GameServerConnection -- ChatUninviteAvatarFromRoom\n");
|
||||
ChatUninviteFromRoom chat(ri);
|
||||
ChatAvatarId characterName = chat.getAvatar();
|
||||
if(characterName.gameCode == "")
|
||||
characterName.gameCode = "SWG";
|
||||
if(characterName.cluster == "")
|
||||
characterName.cluster = ConfigChatServer::getClusterName();
|
||||
ChatServer::uninvite(ChatServer::getNetworkIdByAvatarId(characterName), chat.getSequence(), characterName, chat.getRoomName());
|
||||
}
|
||||
else if (gameNetworkMessage.isType("ChatChangeFriendStatus"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatChangeFriendStatus");
|
||||
//printf("GameServerConnection -- ChatChangeFriendStatus\n");
|
||||
ChatChangeFriendStatus chat(ri);
|
||||
|
||||
if (chat.getAdd())
|
||||
{
|
||||
ChatServer::addFriend(
|
||||
ChatServer::getNetworkIdByAvatarId(chat.getCharacterName()),
|
||||
chat.getSequence(), chat.getFriendName());
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatServer::removeFriend(
|
||||
ChatServer::getNetworkIdByAvatarId(chat.getCharacterName()),
|
||||
chat.getSequence(), chat.getFriendName());
|
||||
}
|
||||
|
||||
}
|
||||
else if (gameNetworkMessage.isType("ChatGetFriendsList"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatGetFriendsList");
|
||||
//printf("GameServerConnection -- ChatGetFriendsList\n");
|
||||
ChatGetFriendsList chat(ri);
|
||||
|
||||
ChatServer::getFriendsList(chat.getCharacterName());
|
||||
}
|
||||
else if (gameNetworkMessage.isType("ChatChangeIgnoreStatus"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatChangeIgnoreStatus");
|
||||
//printf("GameServerConnection -- ChatChangeIgnoreStatus\n");
|
||||
ChatChangeIgnoreStatus chat(ri);
|
||||
|
||||
if (chat.getIgnore())
|
||||
{
|
||||
ChatServer::addIgnore(
|
||||
ChatServer::getNetworkIdByAvatarId(chat.getCharacterName()),
|
||||
chat.getSequence(), chat.getIgnoreName());
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatServer::removeIgnore(
|
||||
ChatServer::getNetworkIdByAvatarId(chat.getCharacterName()),
|
||||
chat.getSequence(), chat.getIgnoreName());
|
||||
}
|
||||
|
||||
}
|
||||
else if (gameNetworkMessage.isType("ChatGetIgnoreList"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatGetIgnoreList");
|
||||
//printf("GameServerConnection -- ChatGetIgnoreList\n");
|
||||
ChatGetIgnoreList chat(ri);
|
||||
|
||||
ChatServer::getIgnoreList(chat.getCharacterName());
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatRemoveAvatarFromRoom"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatRemoveAvatarFromRoom");
|
||||
//printf("GameServerConnection -- ChatRemoveAvatarFromRoom\n");
|
||||
ChatRemoveAvatarFromRoom chat(ri);
|
||||
ChatAvatarId id = chat.getAvatarId();
|
||||
size_t pos = id.name.find(" ");
|
||||
if(pos != std::string::npos)
|
||||
id.name = id.name.substr(0, pos);
|
||||
ChatServer::removeAvatarFromRoom(id, chat.getRoomName());
|
||||
}
|
||||
else if(gameNetworkMessage.isType("ChatMessageFromGame"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatMessageFromGame");
|
||||
//printf("GameServerConnection -- ChatMessageFromGame\n");
|
||||
ChatMessageFromGame chat(ri);
|
||||
std::string recipient = chat.getTo();
|
||||
size_t pos = recipient.find(" ");
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
recipient = recipient.substr(0, pos);
|
||||
}
|
||||
switch(chat.getMessageType())
|
||||
{
|
||||
case ChatMessageFromGame::INSTANT:
|
||||
{
|
||||
ChatAvatarId from(chat.getFrom());
|
||||
if (from.cluster.empty())
|
||||
from.cluster = ConfigChatServer::getClusterName();
|
||||
if (from.gameCode.empty())
|
||||
from.gameCode = m_gameCode;
|
||||
|
||||
ChatAvatarId to(recipient);
|
||||
if (to.cluster.empty())
|
||||
to.cluster = ConfigChatServer::getClusterName();
|
||||
if (to.gameCode.empty())
|
||||
to.gameCode = m_gameCode;
|
||||
|
||||
ChatServer::sendInstantMessage(from, to, chat.getMessage(), chat.getOutOfBand());
|
||||
}
|
||||
break;
|
||||
case ChatMessageFromGame::PERSISTENT:
|
||||
{
|
||||
ChatAvatarId from(chat.getFrom());
|
||||
if (from.cluster.empty())
|
||||
from.cluster = ConfigChatServer::getClusterName();
|
||||
if (from.gameCode.empty())
|
||||
from.gameCode = m_gameCode;
|
||||
|
||||
ChatAvatarId to(recipient);
|
||||
if (to.cluster.empty())
|
||||
to.cluster = ConfigChatServer::getClusterName();
|
||||
if (to.gameCode.empty())
|
||||
to.gameCode = m_gameCode;
|
||||
|
||||
ChatServer::sendPersistentMessage(from, to, chat.getSubject(), chat.getMessage(), chat.getOutOfBand());
|
||||
}
|
||||
break;
|
||||
case ChatMessageFromGame::ROOM:
|
||||
{
|
||||
ChatAvatarId from(chat.getFrom());
|
||||
if (from.cluster.empty())
|
||||
from.cluster = ConfigChatServer::getClusterName();
|
||||
if (from.gameCode.empty())
|
||||
from.gameCode = m_gameCode;
|
||||
|
||||
ChatServer::sendStandardRoomMessage(from, chat.getRoom(), chat.getMessage(), chat.getOutOfBand());
|
||||
}
|
||||
break;
|
||||
default:
|
||||
REPORT_LOG(true, ("Unkown Game Chat Message type\n"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (gameNetworkMessage.isType("SetUnsquelchTime"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - SetUnsquelchTime");
|
||||
//printf("GameServerConnection -- SetUnsquelchTime\n");
|
||||
GenericValueTypeMessage<std::pair<NetworkId, int> > setUnsquelchTime(ri);
|
||||
|
||||
ChatServer::setUnsquelchTime(setUnsquelchTime.getValue().first, static_cast<time_t>(setUnsquelchTime.getValue().second));
|
||||
}
|
||||
else if (gameNetworkMessage.isType("ChatStatisticsGS"))
|
||||
{
|
||||
PROFILER_AUTO_BLOCK_DEFINE("GameServerConnection - ChatStatisticsGS");
|
||||
//printf("GameServerConnection -- ChatStatisticsGS\n");
|
||||
GenericValueTypeMessage<std::pair<std::pair<std::pair<NetworkId, int>, int>, std::pair<int, int> > > chatStatistics(ri);
|
||||
|
||||
ChatServer::handleChatStatisticsFromGameServer(chatStatistics.getValue().first.first.first, static_cast<time_t>(chatStatistics.getValue().first.first.second), static_cast<time_t>(chatStatistics.getValue().first.second), chatStatistics.getValue().second.first, chatStatistics.getValue().second.second);
|
||||
}
|
||||
//it eats at my soul to participate in this elseif chain
|
||||
else if (gameNetworkMessage.isType(VoiceChatGetChannel::cms_name))
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
VoiceChatGetChannel createRoomMessage(ri);
|
||||
std::list<std::string> mods;
|
||||
ChatServer::instance().requestGetChannel(ReturnAddress(m_connectionId),createRoomMessage.getRoomName(), createRoomMessage.getIsPublic(), createRoomMessage.getIsPersistant(), createRoomMessage.getLimit(), mods);
|
||||
}
|
||||
else if (gameNetworkMessage.isType(VoiceChatDeleteChannel::cms_name))
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
VoiceChatDeleteChannel destroyRoomMessage(ri);
|
||||
ChatServer::instance().requestDeleteChannel(ReturnAddress(m_connectionId),destroyRoomMessage.getRoomName());
|
||||
}
|
||||
else if (gameNetworkMessage.isType(VoiceChatAddClientToChannel::cms_name))
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
VoiceChatAddClientToChannel addMessage(ri);
|
||||
ChatServer::instance().requestAddClientToChannel(addMessage.getClientId(), addMessage.getClientName(), addMessage.getChannelName(), addMessage.getForceShortlist());
|
||||
}
|
||||
else if (gameNetworkMessage.isType(VoiceChatRemoveClientFromChannel::cms_name))
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
VoiceChatRemoveClientFromChannel msg(ri);
|
||||
ChatServer::instance().requestRemoveClientFromChannel(msg.getClientId(), msg.getClientName(), msg.getChannelName());
|
||||
}
|
||||
else if (gameNetworkMessage.isType(VoiceChatChannelCommand::cms_name))
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
VoiceChatChannelCommand msg(ri);
|
||||
ChatServer::instance().requestChannelCommand(ReturnAddress(m_connectionId), msg.getSourceUserName(),msg.getTargetUserName(),msg.getChannelName(),msg.getCommandType(),msg.getBanTimeout());
|
||||
}
|
||||
else if (gameNetworkMessage.isType("BroadcastGlobalChannel"))
|
||||
{
|
||||
Archive::ReadIterator ri = message.begin();
|
||||
|
||||
typedef std::pair<std::pair<std::string,std::string>, bool> PayloadType;
|
||||
GenericValueTypeMessage<PayloadType> msg(ri);
|
||||
|
||||
PayloadType const & payload = msg.getValue();
|
||||
std::string const & channelName = payload.first.first;
|
||||
std::string const & messageText = payload.first.second;
|
||||
bool const & isRemove = payload.second;
|
||||
|
||||
LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer got BroadcastGlobalChannel on GameServerConnection chan(%s) text(%s) remove(%d)",
|
||||
channelName.c_str(), messageText.c_str(), (isRemove?1:0)));
|
||||
ChatServer::requestBroadcastChannelMessage(channelName, messageText, isRemove);
|
||||
}
|
||||
else if (gameNetworkMessage.isType("ChatDestroyAvatar"))
|
||||
{
|
||||
GenericValueTypeMessage<std::string> const msg(ri);
|
||||
ChatServer::getChatInterface()->DestroyAvatar(msg.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// GameServerConnection.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_GameServerConnection_H
|
||||
#define _INCLUDED_GameServerConnection_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverUtility/ServerConnection.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class GameServerConnection : public ServerConnection
|
||||
{
|
||||
public:
|
||||
GameServerConnection(UdpConnectionMT *, TcpClient *);
|
||||
virtual ~GameServerConnection();
|
||||
|
||||
void onConnectionClosed ();
|
||||
void onConnectionOpened ();
|
||||
void onReceive (const Archive::ByteStream & bs);
|
||||
|
||||
private:
|
||||
GameServerConnection();
|
||||
GameServerConnection & operator = (const GameServerConnection & rhs);
|
||||
GameServerConnection(const GameServerConnection & source);
|
||||
|
||||
std::string m_gameCode;
|
||||
unsigned m_connectionId;
|
||||
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_GameServerConnection_H
|
||||
@@ -0,0 +1,32 @@
|
||||
// PlanetServerConnection.h
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
#ifndef _INCLUDED_PlanetServerConnection_H
|
||||
#define _INCLUDED_PlanetServerConnection_H
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "serverUtility/ServerConnection.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class PlanetServerConnection : public ServerConnection
|
||||
{
|
||||
public:
|
||||
PlanetServerConnection(UdpConnectionMT *, TcpClient *);
|
||||
virtual ~PlanetServerConnection();
|
||||
|
||||
void onConnectionClosed ();
|
||||
void onConnectionOpened ();
|
||||
void onReceive (const Archive::ByteStream & bs);
|
||||
|
||||
private:
|
||||
PlanetServerConnection();
|
||||
PlanetServerConnection & operator = (const PlanetServerConnection & rhs);
|
||||
PlanetServerConnection(const PlanetServerConnection & source);
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_PlanetServerConnection_H
|
||||
@@ -0,0 +1,42 @@
|
||||
// PlanetServerConnection.cpp
|
||||
// Copyright 2000-02, Sony Online Entertainment Inc., all rights reserved.
|
||||
// Author: Justin Randall
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "PlanetServerConnection.h"
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
PlanetServerConnection::PlanetServerConnection(UdpConnectionMT * u, TcpClient * t) :
|
||||
ServerConnection(u, t)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
PlanetServerConnection::~PlanetServerConnection()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void PlanetServerConnection::onConnectionClosed()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void PlanetServerConnection::onConnectionOpened()
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
void PlanetServerConnection::onReceive(const Archive::ByteStream &)
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,915 @@
|
||||
//VChatInterface.cpp
|
||||
|
||||
#include "FirstChatServer.h"
|
||||
#include "VChatInterface.h"
|
||||
|
||||
#include "ChatInterface.h" //included for toLower...
|
||||
#include "ChatServer.h"
|
||||
#include "ConfigChatServer.h"
|
||||
|
||||
#include "sharedFoundation/NetworkIdArchive.h"
|
||||
#include "sharedLog/Log.h"
|
||||
#include "sharedNetworkMessages/GenericValueTypeMessage.h"
|
||||
#include "sharedNetworkMessages/VoiceChatChannelInfo.h"
|
||||
#include "sharedNetworkMessages/VoiceChatOnGetAccount.h"
|
||||
#include "sharedNetworkMessages/VoiceChatMiscMessages.h"
|
||||
|
||||
char const * const ms_logLable = "VChatInterface";
|
||||
std::string const ms_systemAvatarName("SYSTEM");
|
||||
static bool ms_voiceLoggingEnabled = false;
|
||||
static unsigned const timeoutRetryLimit = 1;
|
||||
|
||||
|
||||
//user structures
|
||||
|
||||
//used for GetChannel calls
|
||||
struct GetChannelInfoStruct
|
||||
{
|
||||
ReturnAddress requester;
|
||||
std::string channelName;
|
||||
std::string password;
|
||||
bool isPublic;
|
||||
bool persistant;
|
||||
std::list<std::string> moderators;
|
||||
};
|
||||
|
||||
struct DeleteChannelInfo
|
||||
{
|
||||
ReturnAddress requester;
|
||||
std::string channelName;
|
||||
};
|
||||
|
||||
struct ChannelCommandInfo
|
||||
{
|
||||
ReturnAddress requester;
|
||||
std::string srcUserName;
|
||||
std::string destUserName;
|
||||
std::string destChannelAddress;
|
||||
uint32 command;
|
||||
uint32 banTimeout;
|
||||
};
|
||||
|
||||
struct GetAccountInfo
|
||||
{
|
||||
std::string avatarName;
|
||||
NetworkId id;
|
||||
unsigned suid;
|
||||
unsigned failedAttempts;
|
||||
};
|
||||
|
||||
//used for GetChannelInfo calls
|
||||
struct GetChannelInfoInfo
|
||||
{
|
||||
ReturnAddress requester;
|
||||
std::string channelName;
|
||||
bool isGlobalBroadcast;
|
||||
std::string textMessage;
|
||||
};
|
||||
|
||||
|
||||
VChatInterface::VChatInterface(const char * hostList)
|
||||
: VChatAPI(hostList),
|
||||
m_channelData(),
|
||||
m_globalChannels(),
|
||||
m_connected(false),
|
||||
m_connectionFailedCount(0)
|
||||
{
|
||||
ChatServer::fileLog(true, ms_logLable, "Creating interface hostlist=%s", hostList);
|
||||
ms_voiceLoggingEnabled = ConfigChatServer::getVoiceChatLoggingEnabled();
|
||||
}
|
||||
|
||||
VChatInterface::~VChatInterface()
|
||||
{
|
||||
ChatServer::fileLog(true, ms_logLable, "Destroying interface");
|
||||
}
|
||||
|
||||
std::string systemNameHelper()
|
||||
{
|
||||
std::string temp;
|
||||
VChatSystem::CreateUserName(ms_systemAvatarName, ConfigChatServer::getClusterName(), temp);
|
||||
return temp;
|
||||
}
|
||||
|
||||
std::string const & VChatInterface::getSystemLoginName()
|
||||
{
|
||||
static std::string const adminName (systemNameHelper());
|
||||
return adminName;
|
||||
}
|
||||
|
||||
std::string VChatInterface::buildPersonalChannelName(NetworkId const & ownerId)
|
||||
{
|
||||
std::string ownerLogin, ownerPlayerName;
|
||||
if(!ChatServer::getVoiceChatLoginInfoFromId(ownerId, ownerLogin, ownerPlayerName))
|
||||
{
|
||||
ownerPlayerName = ownerId.getValueString();
|
||||
}
|
||||
|
||||
std::string outstr = ConfigChatServer::getGameCode();
|
||||
outstr += ".";
|
||||
outstr += ConfigChatServer::getClusterName();
|
||||
outstr += ".private.";
|
||||
outstr += ownerPlayerName;
|
||||
|
||||
return outstr;
|
||||
}
|
||||
|
||||
|
||||
bool VChatInterface::findChannelDataByName(std::string const & name, VChatSystem::Channel & data)
|
||||
{
|
||||
ChannelDataMap::iterator i = m_channelData.find(toLower(name));
|
||||
if(i != m_channelData.end())
|
||||
{
|
||||
data = i->second;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void VChatInterface::setChannelData(VChatSystem::Channel const & data)
|
||||
{
|
||||
m_channelData[toLower(data.m_channelName)] = data;
|
||||
}
|
||||
|
||||
bool VChatInterface::eraseChannelData(std::string const & name)
|
||||
{
|
||||
ChannelDataMap::iterator i = m_channelData.find(toLower(name));
|
||||
if(i != m_channelData.end())
|
||||
{
|
||||
m_channelData.erase(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void VChatInterface::requestInvite(NetworkId const & sourceId, NetworkId const & targetId, std::string const & channelName)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "requestInvite roomName(%s) sourceId(%s) targetId(%s)",
|
||||
channelName.c_str(), sourceId.getValueString().c_str(), targetId.getValueString().c_str());
|
||||
|
||||
std::string srcUserName, targetUserName, tmp;
|
||||
if(ChatServer::getVoiceChatLoginInfoFromId(sourceId, srcUserName, tmp) && ChatServer::getVoiceChatLoginInfoFromId(targetId, targetUserName, tmp))
|
||||
{
|
||||
//@TODO: if this fails clients will be confused
|
||||
requestChannelCommand(ReturnAddress(), srcUserName, targetUserName, channelName, VChatSystem::COMMAND_ADD_ACL, 0);
|
||||
}
|
||||
|
||||
VChatSystem::Channel data;
|
||||
if(findChannelDataByName(channelName,data))
|
||||
{
|
||||
VoiceChatInvite msg(sourceId, targetId, channelName, data.m_channelURI);
|
||||
ChatServer::sendToClient(targetId, msg);
|
||||
}
|
||||
}
|
||||
|
||||
void VChatInterface::requestKick(NetworkId const & sourceId, NetworkId const & targetId, std::string const & channelName)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "requestKick roomName(%s) sourceId(%s) targetId(%s)",
|
||||
channelName.c_str(), sourceId.getValueString().c_str(), targetId.getValueString().c_str());
|
||||
|
||||
std::string srcUserName, targetUserName, tmp;
|
||||
if(ChatServer::getVoiceChatLoginInfoFromId(sourceId, srcUserName, tmp) && ChatServer::getVoiceChatLoginInfoFromId(targetId, targetUserName, tmp))
|
||||
{
|
||||
//@TODO: if this fails clients will be confused
|
||||
requestChannelCommand(ReturnAddress(), srcUserName, targetUserName, channelName, VChatSystem::COMMAND_DELETE_ACL, 0);
|
||||
requestChannelCommand(ReturnAddress(), srcUserName, targetUserName, channelName, VChatSystem::COMMAND_HANGUP, 0);
|
||||
}
|
||||
|
||||
VChatSystem::Channel data;
|
||||
if(findChannelDataByName(channelName,data))
|
||||
{
|
||||
VoiceChatKick msg(sourceId, targetId, channelName);
|
||||
ChatServer::sendToClient(targetId, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool VChatInterface::addClientToChannel(std::string const & roomName, NetworkId const & id, std::string const & playerName, bool forceShortlist)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "AddClientToChannel roomName(%s) clientId(%s) playerName(%s) forceShortlist(%i)",
|
||||
roomName.c_str(), id.getValueString().c_str(), playerName.c_str(), forceShortlist ? 1 : 0);
|
||||
|
||||
std::string userName, tmp;
|
||||
if(!ChatServer::getVoiceChatLoginInfoFromId(id, userName, tmp))
|
||||
{
|
||||
//try to recover with the passed in player name
|
||||
VChatSystem::CreateUserName(playerName, ConfigChatServer::getClusterName(), userName);
|
||||
}
|
||||
requestChannelCommand(ReturnAddress(), "", userName, roomName, VChatSystem::COMMAND_ADD_ACL, 0);
|
||||
|
||||
VChatSystem::Channel data;
|
||||
if(findChannelDataByName(roomName,data))
|
||||
{
|
||||
uint32 flags = forceShortlist ? VoiceChatChannelInfo::CIF_ForcedShortlist : VoiceChatChannelInfo::CIF_None;
|
||||
VoiceChatChannelInfo msg(data.m_channelName, data.m_channelName, data.m_channelURI, data.m_channelPassword, "", flags);
|
||||
ChatServer::sendToClient(id, msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//no channel data...
|
||||
//TODO: get the channel and add the client?
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VChatInterface::removeClientFromChannel(std::string const & roomName, NetworkId const & id, std::string const & playerName)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "removeClientFromChannel roomName(%s) clientId(%s) playerName(%s)",
|
||||
roomName.c_str(), id.getValueString().c_str(), playerName.c_str());
|
||||
|
||||
std::string userName, tmp;
|
||||
if(!ChatServer::getVoiceChatLoginInfoFromId(id, userName, tmp))
|
||||
{
|
||||
//try to recover with the passed in player name
|
||||
VChatSystem::CreateUserName(playerName, ConfigChatServer::getClusterName(), userName);
|
||||
}
|
||||
requestChannelCommand(ReturnAddress(), "", userName, roomName, VChatSystem::COMMAND_DELETE_ACL, 0);
|
||||
requestChannelCommand(ReturnAddress(), "", userName, roomName, VChatSystem::COMMAND_HANGUP, 0);
|
||||
|
||||
VChatSystem::Channel data;
|
||||
if(findChannelDataByName(roomName,data))
|
||||
{
|
||||
uint32 flags = VoiceChatChannelInfo::CIF_AutoJoin | VoiceChatChannelInfo::CIF_LeaveChannel;
|
||||
VoiceChatChannelInfo msg(data.m_channelName, data.m_channelName, data.m_channelURI, data.m_channelPassword, "", flags);
|
||||
ChatServer::sendToClient(id, msg);
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//we couldn't find the channel, but for a removal we just need the name anyhow
|
||||
uint32 flags = VoiceChatChannelInfo::CIF_AutoJoin | VoiceChatChannelInfo::CIF_LeaveChannel | VoiceChatChannelInfo::CIF_ChannelDoesNotExist;
|
||||
VoiceChatChannelInfo msg(roomName, roomName, "", "", "", flags);
|
||||
ChatServer::sendToClient(id, msg);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void VChatInterface::sendChannelData(ReturnAddress const & toWhom, std::string const & channelName, std::string const & messageText, bool targetIsModerator, bool notifyIfNoChannel, bool doGetChannelInfo)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "sendChannelData roomName(%s) target(%s)",
|
||||
channelName.c_str(), toWhom.debugString().c_str());
|
||||
|
||||
VChatSystem::Channel data;
|
||||
if(findChannelDataByName(channelName, data))
|
||||
{
|
||||
uint32 flags = targetIsModerator ? VoiceChatChannelInfo::CIF_TargetModerator : VoiceChatChannelInfo::CIF_None;
|
||||
VoiceChatChannelInfo msg(data.m_channelName, data.m_channelName, data.m_channelURI, data.m_channelPassword, messageText, flags);
|
||||
ChatServer::instance().sendResponse(toWhom, msg);
|
||||
}
|
||||
else if (doGetChannelInfo)
|
||||
{
|
||||
requestChannelInfo(channelName, toWhom, false, messageText);
|
||||
}
|
||||
else if (notifyIfNoChannel)
|
||||
{
|
||||
uint32 flags = VoiceChatChannelInfo::CIF_ChannelDoesNotExist;
|
||||
if(targetIsModerator) flags |= VoiceChatChannelInfo::CIF_TargetModerator;
|
||||
VoiceChatChannelInfo msg(channelName, channelName, "", "", messageText, flags);
|
||||
ChatServer::instance().sendResponse(toWhom, msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
unsigned VChatInterface::requestGetChannel(const std::string &channelName,
|
||||
const std::string &description,
|
||||
const std::string &password,
|
||||
unsigned limit,
|
||||
bool isPublic,
|
||||
bool persistent,
|
||||
std::list<std::string> const & moderators,
|
||||
ReturnAddress const & requester)
|
||||
{
|
||||
if(requester.type == ReturnAddress::RAT_gameserver && requester.gameServerId == 0)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "requestGetChannel called with a bad return address(%s)", requester.debugString().c_str());
|
||||
}
|
||||
|
||||
PendingGetChannelRequest newReq;
|
||||
newReq.m_channelName = channelName;
|
||||
newReq.m_description = description;
|
||||
newReq.m_password = password;
|
||||
newReq.m_limit = limit;
|
||||
newReq.m_isPublic = isPublic;
|
||||
newReq.m_persistent = persistent;
|
||||
newReq.m_moderators = moderators;
|
||||
newReq.m_requester = requester;
|
||||
|
||||
PendingGetChannelRequestMap::iterator itr = m_pendingGetChannelRequests.find(channelName);
|
||||
if(itr != m_pendingGetChannelRequests.end() && !itr->second.empty())
|
||||
{
|
||||
itr->second.push_back(newReq);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pendingGetChannelRequests[channelName].push_back(newReq);
|
||||
}
|
||||
|
||||
return internalGetChannel(channelName, description, password, limit, isPublic, persistent, moderators, requester);
|
||||
}
|
||||
|
||||
unsigned VChatInterface::internalGetChannel(const std::string &channelName,
|
||||
const std::string &description,
|
||||
const std::string &password,
|
||||
unsigned limit,
|
||||
bool isPublic,
|
||||
bool persistent,
|
||||
std::list<std::string> const & moderators,
|
||||
ReturnAddress const & requester)
|
||||
{
|
||||
GetChannelInfoStruct * info = new GetChannelInfoStruct;
|
||||
info->requester = requester;
|
||||
info->channelName = channelName;
|
||||
info->password = password;
|
||||
info->isPublic = isPublic;
|
||||
info->persistant = persistent;
|
||||
info->moderators = moderators;
|
||||
|
||||
//This is dumb. vchat should be consistant about qualifying channel names.
|
||||
std::string shortName, server, game;
|
||||
VChatSystem::GetChannelComponents(channelName,shortName,server,game);
|
||||
DEBUG_WARNING(game != ConfigChatServer::getGameCode(),("Channel create request with mismatched game code %s (should be %s)", game.c_str(), ConfigChatServer::getGameCode()));
|
||||
DEBUG_WARNING(server != ConfigChatServer::getClusterName(),("Channel create request with mismatched cluster name %s (should be %s)", server.c_str(), ConfigChatServer::getClusterName()));
|
||||
|
||||
unsigned track = VChatAPI::GetChannelV2(shortName, game, server, description, password, limit, persistent, (void*)info);
|
||||
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "requestGetChannel track(%d) requester(%s) name(%s) desc(%s) pass(%s) public(%s) persist(%s)",
|
||||
track, requester.debugString().c_str(), channelName.c_str(), description.c_str(), password.c_str(), isPublic?"true":"false", persistent?"true":"false");
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
unsigned VChatInterface::requestDeleteChannel(std::string const &channelName, ReturnAddress const & requester)
|
||||
{
|
||||
if(requester.type == ReturnAddress::RAT_gameserver && requester.gameServerId == 0)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "requestDeleteChannel called with a bad return address");
|
||||
}
|
||||
|
||||
DeleteChannelInfo * info = new DeleteChannelInfo;
|
||||
info->requester = requester;
|
||||
info->channelName = channelName;
|
||||
|
||||
//dumb
|
||||
std::string shortName, server, game;
|
||||
VChatSystem::GetChannelComponents(channelName,shortName,server,game);
|
||||
DEBUG_WARNING(game != ConfigChatServer::getGameCode(),("Channel delete request with mismatched game code %s (should be %s)", game.c_str(), ConfigChatServer::getGameCode()));
|
||||
DEBUG_WARNING(server != ConfigChatServer::getClusterName(),("Channel delete request with mismatched cluster name %s (should be %s)", server.c_str(), ConfigChatServer::getClusterName()));
|
||||
|
||||
unsigned track = VChatAPI::DeleteChannel(shortName, game, server, info);
|
||||
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "requestDeleteChannel track(%d) requester(%s) name(%s)",
|
||||
track, requester.debugString().c_str(), channelName.c_str());
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
unsigned VChatInterface::requestChannelCommand(ReturnAddress const & requester,
|
||||
const std::string &srcUserName,
|
||||
const std::string &destUserName,
|
||||
const std::string &destChannelAddress,
|
||||
unsigned command,
|
||||
unsigned banTimeout)
|
||||
{
|
||||
ChannelCommandInfo * info = new ChannelCommandInfo;
|
||||
info->requester = requester;
|
||||
info->srcUserName = srcUserName;
|
||||
info->destUserName = destUserName;
|
||||
info->destChannelAddress = destChannelAddress;
|
||||
info->command = command;
|
||||
info->banTimeout = banTimeout;
|
||||
|
||||
if(command == VChatSystem::COMMAND_ADD_ACL)
|
||||
checkForCharacterChannelAdd(destUserName, destChannelAddress);
|
||||
else if (command == VChatSystem::COMMAND_DELETE_ACL)
|
||||
checkForCharacterChannelRemove(destUserName, destChannelAddress);
|
||||
|
||||
uint32 track = VChatAPI::ChannelCommand(srcUserName, destUserName, destChannelAddress, command, banTimeout, info);
|
||||
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "requestChannelCommand: track(%u) returnAddress(%s) src(%s) dest(%s) chan(%s) cmd(%u) banTimeout(%u)",
|
||||
track, requester.debugString().c_str(), srcUserName.c_str(), destUserName.c_str(), destChannelAddress.c_str(), command, banTimeout);
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
unsigned VChatInterface::requestConnectPlayer(unsigned suid, std::string const & characterName, NetworkId const & netId, unsigned previousAttempts)
|
||||
{
|
||||
GetAccountInfo *info = new GetAccountInfo;
|
||||
info->avatarName = characterName;
|
||||
info->id = netId;
|
||||
info->suid = suid;
|
||||
info->failedAttempts = previousAttempts;
|
||||
|
||||
uint32 track = VChatAPI::GetAccount(characterName, ConfigChatServer::getGameCode(), ConfigChatServer::getClusterName(), suid, 0,(void*)info);
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled,ms_logLable, "requestConnectPlayer: track(%d) suid(%u) name(%s) netId(%s) failedAttempts(%u)",
|
||||
track, suid, characterName.c_str(), netId.getValueString().c_str(), previousAttempts);
|
||||
return track;
|
||||
}
|
||||
|
||||
unsigned VChatInterface::requestChannelInfo(std::string const & channelName, ReturnAddress const & requester, bool isGlobalBroadcast, std::string const & broadcastMessage)
|
||||
{
|
||||
GetChannelInfoInfo *info = new GetChannelInfoInfo;
|
||||
info->requester = requester;
|
||||
info->channelName = channelName;
|
||||
info->isGlobalBroadcast = isGlobalBroadcast;
|
||||
info->textMessage = broadcastMessage;
|
||||
|
||||
//split the name since we can't request any random channel...
|
||||
std::string shortName, server, game;
|
||||
VChatSystem::GetChannelComponents(info->channelName, shortName, server, game);
|
||||
|
||||
uint32 track = VChatAPI::GetChannelInfo(shortName, game, server, (void*)info);
|
||||
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "requestChannelInfo: track(%d) channel(%s) requester(%s)",
|
||||
track, info->channelName.c_str(), info->requester.debugString().c_str());
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
void VChatInterface::OnConnectionOpened( const char * address )
|
||||
{
|
||||
m_connected = true;
|
||||
m_connectionFailedCount = 0;
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnConnectionOpened: %s", address);
|
||||
|
||||
|
||||
uint32 track = VChatAPI::GetAccount(ms_systemAvatarName, ConfigChatServer::getGameCode(), ConfigChatServer::getClusterName(), 0, 0, NULL);
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "Creating system avatar: %s track(%u)", getSystemLoginName().c_str(), track);
|
||||
}
|
||||
|
||||
void VChatInterface::OnConnectionFailed( const char * address )
|
||||
{
|
||||
m_connected = false;
|
||||
++m_connectionFailedCount;
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnConnectionFailed: %s failedCount(%d)",
|
||||
address, m_connectionFailedCount);
|
||||
}
|
||||
|
||||
void VChatInterface::OnConnectionClosed( const char * address, const char * reason )
|
||||
{
|
||||
m_connected = false;
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnConnectionClosed: %s, %s", address, reason);
|
||||
}
|
||||
|
||||
void VChatInterface::OnConnectionShutdownNotified( const char * address, unsigned outstandingRequests )
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnConnectionShutdownNotified: address: %s, outstanding requests: %u", address, outstandingRequests);
|
||||
}
|
||||
|
||||
void VChatInterface::OnGetAccount(unsigned track, unsigned result, unsigned userID, unsigned accountID,
|
||||
const std::string &voicePassword, const std::string &encodedVoiceAccount,
|
||||
const std::string &URI, void *user)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnGetAccount() track(%u) result(%u) userID(%u) accountID(%u) password(%s) encoded(%s) uri(%s)",
|
||||
track, result, userID, accountID, voicePassword.c_str(), encodedVoiceAccount.c_str(), URI.c_str());
|
||||
|
||||
GetAccountInfo *info = (GetAccountInfo *)user;
|
||||
if(!info)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (result == VChatSystem::RESULT_TIMEOUT)
|
||||
{
|
||||
if(info->failedAttempts < timeoutRetryLimit)
|
||||
{
|
||||
requestConnectPlayer(info->suid,info->avatarName,info->id, info->failedAttempts+1);
|
||||
delete info;
|
||||
info = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned msgResult = result == VChatSystem::RESULT_SUCCESS ? VoiceChatOnGetAccount::GAR_SUCCESS : VoiceChatOnGetAccount::GAR_FAILURE;
|
||||
|
||||
ChatServer::voiceChatGotLoginInfo(info->id, encodedVoiceAccount, info->avatarName);
|
||||
|
||||
VoiceChatOnGetAccount const msg(msgResult, encodedVoiceAccount, voicePassword, URI);
|
||||
ChatServer::sendToClient(info->id, msg);
|
||||
|
||||
//send the private channel if it exists (but don't create it at this point)
|
||||
std::list<std::string> modlist;
|
||||
modlist.push_back(encodedVoiceAccount);
|
||||
sendChannelData(info->id, buildPersonalChannelName(info->id), "", true, false, false);
|
||||
|
||||
//send the current global channels
|
||||
for(GlobalChannelMap::const_iterator i = m_globalChannels.begin(); i != m_globalChannels.end(); ++i)
|
||||
{
|
||||
sendChannelData(info->id, (*i).first, (*i).second, false, false, true);
|
||||
}
|
||||
|
||||
delete info;
|
||||
info = NULL;
|
||||
}
|
||||
|
||||
void VChatInterface::OnGetChannelV2(unsigned track, unsigned result,
|
||||
const std::string &channelName, const std::string &channelURI,
|
||||
unsigned channelID, unsigned isNewChannel, void *user)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnGetChannel: track(%u) result(%u) chanName(%s) chanURI(%s) chanID(%d)",
|
||||
track, result, channelName.c_str(), channelURI.c_str(), channelID);
|
||||
|
||||
GetChannelInfoStruct * info = (GetChannelInfoStruct*)user;
|
||||
if (info)
|
||||
{
|
||||
bool success = (result == VChatSystem::RESULT_SUCCESS);
|
||||
|
||||
//we might have gotten good data even if creation failed...interesting...
|
||||
VChatSystem::Channel data;
|
||||
if (!channelURI.empty())
|
||||
{
|
||||
|
||||
// If a channel is persisted, we want to add it to our character channel list. Currently the only persisted channel in SWG is guilds.
|
||||
if(info->persistant)
|
||||
{
|
||||
// Do we already have this channel on record?
|
||||
VoiceChannelIdMap::iterator iter = m_voiceChatChannelNameToNetworkIdMap.find(toLower(channelName));
|
||||
if(iter == m_voiceChatChannelNameToNetworkIdMap.end())
|
||||
{
|
||||
// Create a new record for this channel.
|
||||
m_voiceChatChannelNameToNetworkIdMap.insert(std::make_pair(toLower(channelName), std::vector<NetworkId>()));
|
||||
}
|
||||
}
|
||||
|
||||
//if this is a newly created channel add the system avatar to it
|
||||
if (isNewChannel)
|
||||
{
|
||||
requestChannelCommand(ReturnAddress(), "", getSystemLoginName(), channelName, VChatSystem::COMMAND_ADD_ACL, 0);
|
||||
}
|
||||
|
||||
//Always add the moderators just in case something failed in the past and we are now in a bad state
|
||||
for(std::list<std::string>::const_iterator i = info->moderators.begin(); i != info->moderators.end(); ++i)
|
||||
{
|
||||
requestChannelCommand(ReturnAddress(), "", *i, channelName, VChatSystem::COMMAND_ADD_MODERATOR, 0);
|
||||
requestChannelCommand(ReturnAddress(), "", *i, channelName, VChatSystem::COMMAND_ADD_ACL, 0);
|
||||
}
|
||||
|
||||
data.m_channelName = channelName;
|
||||
data.m_channelPassword = info->password;
|
||||
data.m_channelURI = channelURI;
|
||||
data.m_channelID = channelID;
|
||||
setChannelData(data);
|
||||
}
|
||||
|
||||
VoiceChatOnGetChannel response(channelName, channelURI, info->password, info->isPublic, info->persistant, success);
|
||||
|
||||
ChatServer::instance().sendResponse(info->requester, response);
|
||||
|
||||
delete info;
|
||||
}
|
||||
|
||||
//check for any queued requests for this channel so we can fire them off now
|
||||
PendingGetChannelRequestMap::iterator itr = m_pendingGetChannelRequests.find(channelName);
|
||||
if(itr != m_pendingGetChannelRequests.end())
|
||||
{
|
||||
//If we don't make it in here then something is very messed up in the request list as
|
||||
// any request that is outstanding should be the front of the list.
|
||||
|
||||
std::list<PendingGetChannelRequest> & thelist = itr->second;
|
||||
|
||||
if(!thelist.empty())
|
||||
{
|
||||
//We should always hit this block. If we didn't, something is VERY wrong.
|
||||
thelist.pop_front();
|
||||
}
|
||||
else
|
||||
WARNING(true, ("OnGetChannelV2: Received a response for a channel that has no pending request! This is bad!!!"));
|
||||
|
||||
std::list<PendingGetChannelRequest>::iterator nextItr = thelist.begin();
|
||||
if(nextItr != thelist.end())
|
||||
{
|
||||
PendingGetChannelRequest const & req = *nextItr;
|
||||
internalGetChannel(req.m_channelName, req.m_description, req.m_password, req.m_limit, req.m_isPublic, req.m_persistent, req.m_moderators, req.m_requester);
|
||||
}
|
||||
|
||||
if(thelist.empty())
|
||||
{
|
||||
m_pendingGetChannelRequests.erase(itr);
|
||||
}
|
||||
}
|
||||
else
|
||||
WARNING(true, ("OnGetChannelV2: Received a response for a channel that isn't in our pending request map! BAD!"));
|
||||
}
|
||||
|
||||
void VChatInterface::OnChannelCommand(unsigned track, unsigned result, void *user)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnChannelCommand: track(%u) result(%u)", track, result);
|
||||
|
||||
|
||||
ChannelCommandInfo * info = (ChannelCommandInfo*)user;
|
||||
if(info)
|
||||
{
|
||||
VoiceChatOnChannelCommand response(info->srcUserName,info->destUserName,info->destChannelAddress,info->command,info->banTimeout,result);
|
||||
ChatServer::instance().sendResponse(info->requester, response);
|
||||
|
||||
delete info;
|
||||
}
|
||||
}
|
||||
|
||||
void VChatInterface::OnGetAllChannels(unsigned track, unsigned result, const VChatSystem::ChannelVec_t & channels, void *user)
|
||||
{
|
||||
UNREF(user);
|
||||
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "====OnGetAllChannels==== track(%u) count(%u)", track, channels.size());
|
||||
|
||||
static uint32 failedCount = 0;
|
||||
|
||||
if(result == VChatSystem::RESULT_SUCCESS)
|
||||
{
|
||||
failedCount = 0;
|
||||
m_channelData.clear();
|
||||
|
||||
for(VChatSystem::ChannelVec_t::const_iterator i = channels.begin(); i != channels.end(); ++i)
|
||||
{
|
||||
VChatSystem::Channel const & data = *i;
|
||||
setChannelData(data);
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "name(%s) uri(%s) pass(%s) id(%d) type(%d)",
|
||||
data.m_channelName.c_str(), data.m_channelURI.c_str(), data.m_channelPassword.c_str(), data.m_channelID, data.m_channelType);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
bool shouldRetry = result == VChatSystem::RESULT_TIMEOUT && failedCount < timeoutRetryLimit;
|
||||
|
||||
++failedCount;
|
||||
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "failed, code(%u) count(%d) retry(%s)", result, failedCount, shouldRetry?"yes":"no");
|
||||
|
||||
if(shouldRetry)
|
||||
{
|
||||
GetAllChannels(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "========================");
|
||||
}
|
||||
|
||||
void VChatInterface::OnDeleteChannel(unsigned track, unsigned result, void *user)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnDeleteChannel: track(%u) result(%u)", track, result);
|
||||
|
||||
DeleteChannelInfo * info = (DeleteChannelInfo*)user;
|
||||
if(info)
|
||||
{
|
||||
//TODO: send the response
|
||||
eraseChannelData(info->channelName);
|
||||
|
||||
delete info;
|
||||
}
|
||||
}
|
||||
|
||||
void VChatInterface::OnGetChannelInfo(unsigned track, unsigned result, const std::string & channelName,
|
||||
const std::string & channelURI, unsigned channelID, void * user)
|
||||
{
|
||||
ChatServer::fileLog(ms_voiceLoggingEnabled, ms_logLable, "OnGetChannelInfo: track(%u) result(%u) chanName(%s) chanURI(%s) chanID(%d)",
|
||||
track, result, channelName.c_str(), channelURI.c_str(), channelID);
|
||||
|
||||
GetChannelInfoInfo * info = (GetChannelInfoInfo*)user;
|
||||
if(info)
|
||||
{
|
||||
bool const channelExists = result == VChatSystem::RESULT_SUCCESS; //?
|
||||
|
||||
uint32 flags = channelExists ? VoiceChatChannelInfo::CIF_None : VoiceChatChannelInfo::CIF_ChannelDoesNotExist;
|
||||
|
||||
VoiceChatChannelInfo msg (channelName, channelName, channelURI, "", info->textMessage, flags);
|
||||
|
||||
if(info->isGlobalBroadcast)
|
||||
{
|
||||
LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer: sending to all clients chan(%s) text(%s)", channelName.c_str(), info->textMessage.c_str()));
|
||||
ChatServer::instance().sendToAllConnectionServers(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatServer::instance().sendResponse(info->requester, msg);
|
||||
}
|
||||
|
||||
// cache the channel data
|
||||
if(channelExists)
|
||||
{
|
||||
VChatSystem::Channel data;
|
||||
data.m_channelName = channelName;
|
||||
data.m_channelPassword = ""; // none of the channels have passwords at this point so this is a safe assumption
|
||||
data.m_channelURI = channelURI;
|
||||
data.m_channelID = channelID;
|
||||
setChannelData(data);
|
||||
}
|
||||
|
||||
delete info;
|
||||
info = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void VChatInterface::broadcastGlobalChannelMessage(std::string const & channelName, std::string const & textMessage, bool isRemove)
|
||||
{
|
||||
if(channelName.empty())
|
||||
{
|
||||
LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer: no channel, sending text only message chan(%s) text(%s) remove(%d)",
|
||||
channelName.c_str(), textMessage.c_str(),(isRemove?1:0)));
|
||||
GenericValueTypeMessage<std::string> msg("VCBroadcastMessage",textMessage);
|
||||
ChatServer::instance().sendToAllConnectionServers(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalChannelMap::iterator entryItr = m_globalChannels.find(channelName);
|
||||
|
||||
if(entryItr == m_globalChannels.end())
|
||||
{
|
||||
if(!isRemove)
|
||||
{
|
||||
m_globalChannels.insert(std::make_pair(channelName, textMessage));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isRemove)
|
||||
{
|
||||
m_globalChannels.erase(entryItr);
|
||||
}
|
||||
}
|
||||
|
||||
VChatSystem::Channel data;
|
||||
if(findChannelDataByName(channelName, data))
|
||||
{
|
||||
uint32 flags = isRemove ? VoiceChatChannelInfo::CIF_LeaveChannel | VoiceChatChannelInfo::CIF_AutoJoin : VoiceChatChannelInfo::CIF_None;
|
||||
VoiceChatChannelInfo msg (data.m_channelName, data.m_channelName, data.m_channelURI, data.m_channelPassword, textMessage, flags);
|
||||
|
||||
LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer found channel data. sending to all clients chan(%s) text(%s) remove(%d)",
|
||||
channelName.c_str(), textMessage.c_str(),(isRemove?1:0)));
|
||||
ChatServer::instance().sendToAllConnectionServers(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isRemove)
|
||||
{
|
||||
uint32 flags = VoiceChatChannelInfo::CIF_LeaveChannel | VoiceChatChannelInfo::CIF_AutoJoin;
|
||||
VoiceChatChannelInfo msg (channelName, channelName, "", "", textMessage, flags);
|
||||
LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer: didn't find channel data sending remove to all clients chan(%s) text(%s)", channelName.c_str(), textMessage.c_str()));
|
||||
ChatServer::instance().sendToAllConnectionServers(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG("CustomerService", ("BroadcastVoiceChannel: ChatServer: didn't find channel data asking vchat for channel chan(%s) text(%s)", channelName.c_str(), textMessage.c_str()));
|
||||
requestChannelInfo(channelName, ReturnAddress(), true, textMessage);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VChatInterface::OnAddCharacterChannel(unsigned int /*track*/, unsigned int /*result*/, void * /*user*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VChatInterface::OnRemoveCharacterChannel(unsigned int /*track*/, unsigned int /*result*/, void * /*user*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VChatInterface::OnGetCharacterChannel(unsigned int /*track*/, unsigned int /*result*/, const VChatSystem::CharacterChannelVec_t & /*characterChannels*/, void * /*user*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VChatInterface::OnUpdateCharacterChannel(unsigned int /*track*/, unsigned int /*result*/, void * /*user*/)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void VChatInterface::checkForCharacterChannelAdd(std::string const & name, std::string const & channelName)
|
||||
{
|
||||
|
||||
// No persistant channels right now. Skip the add check.
|
||||
if(m_voiceChatChannelNameToNetworkIdMap.empty())
|
||||
return;
|
||||
|
||||
// Can we get a valid player OID?
|
||||
NetworkId playerOID = NetworkId::cms_invalid;
|
||||
if(ChatServer::getVoiceChatLoginInfoFromLoginName(name, playerOID) && playerOID != NetworkId::cms_invalid)
|
||||
{
|
||||
// Are we tracking this channel?
|
||||
if(m_voiceChatChannelNameToNetworkIdMap.find(toLower(channelName)) == m_voiceChatChannelNameToNetworkIdMap.end())
|
||||
return;
|
||||
|
||||
VChatSystem::Channel data;
|
||||
if(findChannelDataByName(channelName, data)) // See if we can get valid channel data.
|
||||
{
|
||||
const ChatAvatar * avatar = ChatServer::getAvatarByNetworkId(playerOID);
|
||||
if(avatar)
|
||||
{
|
||||
// Store the OIDs of players in our channel.
|
||||
bool insert = true;
|
||||
VoiceChannelIdMap::iterator iter = m_voiceChatChannelNameToNetworkIdMap.find(toLower(channelName));
|
||||
if(iter != m_voiceChatChannelNameToNetworkIdMap.end())
|
||||
{
|
||||
// do we have the OID on record?
|
||||
std::vector<NetworkId>::iterator OIDIter = (*iter).second.begin();
|
||||
for(; OIDIter != (*iter).second.end(); ++OIDIter) // Holy crap does this suck.
|
||||
{
|
||||
if((*OIDIter) == playerOID)
|
||||
{
|
||||
// Yup.
|
||||
insert = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if((*iter).second.empty())
|
||||
insert = true;
|
||||
|
||||
if(insert) // Nope, add it and send off the create character channel message.
|
||||
{
|
||||
AddCharacterChannel(avatar->getUserID(),
|
||||
avatar->getAvatarID(),
|
||||
std::string(avatar->getName().c_str()),
|
||||
parseWorldName(std::string(avatar->getServer().c_str())),
|
||||
"SWG",
|
||||
"guild",
|
||||
data.m_channelName, //"A Guild chat channel."
|
||||
data.m_channelPassword,
|
||||
data.m_channelURI,
|
||||
"en_US",
|
||||
NULL);
|
||||
|
||||
(*iter).second.push_back(playerOID);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VChatInterface::checkForCharacterChannelRemove(std::string const & name, std::string const & channelName)
|
||||
{
|
||||
// No persistant channels right now. Skip the clean up.
|
||||
if(m_voiceChatChannelNameToNetworkIdMap.empty())
|
||||
return;
|
||||
|
||||
NetworkId playerOID = NetworkId::cms_invalid;
|
||||
// Verify we can get an OID for this user.
|
||||
if(ChatServer::getVoiceChatLoginInfoFromLoginName(name, playerOID) && playerOID != NetworkId::cms_invalid)
|
||||
{
|
||||
// Clean up any character channels this player may have.
|
||||
|
||||
// Do we have a record for this channel?
|
||||
VoiceChannelIdMap::iterator chanIter = m_voiceChatChannelNameToNetworkIdMap.find(toLower(channelName));
|
||||
if(chanIter != m_voiceChatChannelNameToNetworkIdMap.end())
|
||||
{
|
||||
// Is this user in our OID list?
|
||||
std::vector<NetworkId>::iterator iter = (*chanIter).second.begin();
|
||||
for(; iter != (*chanIter).second.end(); )
|
||||
{
|
||||
if((*iter) == playerOID) // Yup, let's remove him.
|
||||
{
|
||||
const ChatAvatar * avatar = ChatServer::getAvatarByNetworkId(playerOID);
|
||||
if(avatar)
|
||||
{
|
||||
RemoveCharacterChannel(avatar->getUserID(),
|
||||
avatar->getAvatarID(),
|
||||
std::string(avatar->getName().c_str()),
|
||||
parseWorldName(std::string(avatar->getServer().c_str())),
|
||||
"SWG",
|
||||
"guild",
|
||||
NULL);
|
||||
}
|
||||
|
||||
iter = (*chanIter).second.erase(iter);
|
||||
|
||||
if((*chanIter).second.empty())
|
||||
{
|
||||
// No more OIDs to track, clean this channel up.
|
||||
m_voiceChatChannelNameToNetworkIdMap.erase(chanIter);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else
|
||||
++iter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string VChatInterface::parseWorldName(std::string const & input)
|
||||
{
|
||||
static std::string const worldCode = "SWG+";
|
||||
std::string output;
|
||||
|
||||
std::string::size_type findIndex = input.find(worldCode);
|
||||
if(findIndex != std::string::npos)
|
||||
{
|
||||
findIndex += strlen(worldCode.c_str());
|
||||
output = input.substr(findIndex);
|
||||
}
|
||||
else
|
||||
output = input;
|
||||
|
||||
return output;
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
// VChatInterface.h
|
||||
|
||||
#ifndef _INCLUDED_VChatInterface_H
|
||||
#define _INCLUDED_VChatInterface_H
|
||||
|
||||
#include "sharedFoundation/NetworkId.h"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
|
||||
#pragma warning(disable:4100 4244)
|
||||
#include "VChatAPI/VChatAPI.h"
|
||||
#pragma warning(default:4100 4244)
|
||||
|
||||
struct ReturnAddress
|
||||
{
|
||||
enum ReturnAddressType
|
||||
{
|
||||
RAT_invalid,
|
||||
RAT_client,
|
||||
RAT_gameserver,
|
||||
};
|
||||
|
||||
ReturnAddressType type;
|
||||
NetworkId clientId;
|
||||
unsigned gameServerId;
|
||||
|
||||
ReturnAddress() : type(RAT_invalid), clientId(), gameServerId(0) {}
|
||||
ReturnAddress(NetworkId const & id):type(RAT_client), clientId(id), gameServerId(0) {}
|
||||
ReturnAddress(unsigned const id) : type(RAT_gameserver), clientId(), gameServerId(id) {}
|
||||
inline std::string ReturnAddress::debugString() const
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case RAT_invalid: return "invalid"; break;
|
||||
case RAT_client: return std::string("client") + clientId.getValueString(); break;
|
||||
case RAT_gameserver:
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "gameserver";
|
||||
ss << gameServerId;
|
||||
return ss.str();
|
||||
}
|
||||
break;
|
||||
default: return "unknown type";
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
class VChatInterface : public VChatSystem::VChatAPI
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
VChatInterface(const char * hostList);
|
||||
virtual ~VChatInterface();
|
||||
|
||||
//functions that need looking at before this goes final
|
||||
bool addClientToChannel(std::string const & roomName, NetworkId const & id, std::string const & playerName, bool forceShortlist = false);
|
||||
bool removeClientFromChannel(std::string const & roomName, NetworkId const & id, std::string const & playerName);
|
||||
|
||||
void sendChannelData(ReturnAddress const & toWhom, std::string const & channelName, std::string const & messageText, bool targetIsModerator, bool notifyIfNoChannel, bool doGetChannelInfo = false);
|
||||
|
||||
//personal channel stuff
|
||||
std::string buildPersonalChannelName(NetworkId const & ownerId);
|
||||
void requestInvite(NetworkId const & sourceId, NetworkId const & targetId, std::string const & channelName);
|
||||
void requestKick(NetworkId const & sourceId, NetworkId const & targetId, std::string const & channelName);
|
||||
|
||||
void broadcastGlobalChannelMessage(std::string const & channelName, std::string const & textMessage, bool isRemove);
|
||||
|
||||
//end questionable functions
|
||||
|
||||
inline bool isConnected() { return m_connected; }
|
||||
|
||||
//////////////
|
||||
// Requests //
|
||||
//////////////
|
||||
|
||||
unsigned requestGetChannel(const std::string &channelName,
|
||||
const std::string &description,
|
||||
const std::string &password,
|
||||
unsigned limit,
|
||||
bool isPublic,
|
||||
bool persistent,
|
||||
std::list<std::string> const & moderators,
|
||||
ReturnAddress const & requester);
|
||||
|
||||
unsigned requestDeleteChannel(const std::string &channelName, ReturnAddress const & requester);
|
||||
|
||||
unsigned requestChannelCommand(ReturnAddress const & request,
|
||||
const std::string &srcUserName,
|
||||
const std::string &destUserName,
|
||||
const std::string &destChannelAddress,
|
||||
unsigned command,
|
||||
unsigned banTimeout);
|
||||
|
||||
unsigned requestConnectPlayer(unsigned suid, std::string const & characterName, NetworkId const & netId, unsigned previousAttempts = 0);
|
||||
|
||||
unsigned requestChannelInfo(std::string const & channelName, ReturnAddress const & requester, bool isForGlobalBroadcast = false, std::string const & messageText = "");
|
||||
|
||||
///////////////
|
||||
// Callbacks //
|
||||
///////////////
|
||||
virtual void OnConnectionOpened( const char * address );
|
||||
virtual void OnConnectionFailed( const char * address );
|
||||
virtual void OnConnectionClosed( const char * address, const char * reason );
|
||||
virtual void OnConnectionShutdownNotified( const char * address, unsigned outstandingRequests );
|
||||
|
||||
virtual void OnGetAccount(unsigned track,
|
||||
unsigned result,
|
||||
unsigned userID,
|
||||
unsigned accountID,
|
||||
const std::string &voicePassword,
|
||||
const std::string &encodedVoiceAccount,
|
||||
const std::string &URI,
|
||||
void *user);
|
||||
|
||||
virtual void OnGetChannelV2(unsigned track,
|
||||
unsigned result,
|
||||
const std::string &channelName,
|
||||
const std::string &channelURI,
|
||||
unsigned channelID,
|
||||
unsigned isNewChannel,
|
||||
void *user);
|
||||
|
||||
virtual void OnChannelCommand(unsigned track,
|
||||
unsigned result,
|
||||
void *user);
|
||||
|
||||
virtual void OnGetAllChannels(unsigned track,
|
||||
unsigned result,
|
||||
const VChatSystem::ChannelVec_t & channels,
|
||||
void *user);
|
||||
|
||||
virtual void OnDeleteChannel(unsigned track,
|
||||
unsigned result,
|
||||
void *user);
|
||||
|
||||
virtual void OnGetChannelInfo(unsigned track,
|
||||
unsigned result,
|
||||
const std::string & channelName,
|
||||
const std::string & channelURI,
|
||||
unsigned channelID,
|
||||
void * user);
|
||||
|
||||
virtual void OnAddCharacterChannel(unsigned int track,
|
||||
unsigned int result,
|
||||
void * user);
|
||||
|
||||
virtual void OnRemoveCharacterChannel(unsigned track,
|
||||
unsigned result,
|
||||
void *user);
|
||||
|
||||
virtual void OnGetCharacterChannel(unsigned track,
|
||||
unsigned result,
|
||||
const VChatSystem::CharacterChannelVec_t &characterChannels,
|
||||
void * user);
|
||||
|
||||
virtual void OnUpdateCharacterChannel(unsigned track,
|
||||
unsigned result,
|
||||
void *user);
|
||||
|
||||
//callbacks for things we don't care about but have to implement
|
||||
//because they are virtual in vchatapi
|
||||
virtual void OnGetProximityChannel (unsigned /*track*/,
|
||||
unsigned /*result*/,
|
||||
const std::string & /*channelName*/,
|
||||
const std::string & /*channelURI*/,
|
||||
unsigned /*channelID*/,
|
||||
void * /*user*/) {};
|
||||
|
||||
|
||||
virtual void OnDeactivateVoiceAccount(unsigned /*track*/,
|
||||
unsigned /*result*/,
|
||||
void * /*user*/) {};
|
||||
|
||||
virtual void OnChangePassword(unsigned /*track*/,
|
||||
unsigned /*result*/,
|
||||
void * /*user*/) {};
|
||||
|
||||
virtual void OnSetUserData( unsigned /*track*/,
|
||||
unsigned /*result*/,
|
||||
void * /*user*/) {};
|
||||
|
||||
virtual void OnSetBanStatus(unsigned /*track*/,
|
||||
unsigned /*result*/,
|
||||
void * /*user*/) {};
|
||||
|
||||
virtual void OnGetChannel(unsigned /*track*/,
|
||||
unsigned /*result*/,
|
||||
const std::string & /*channelName*/,
|
||||
const std::string & /*channelURI*/,
|
||||
unsigned /*channelID*/,
|
||||
void * /*user*/) {};
|
||||
|
||||
private:
|
||||
|
||||
std::string const & getSystemLoginName();
|
||||
std::string parseWorldName(std::string const & input);
|
||||
|
||||
// these functions all convert the name to lower case for the lookup
|
||||
// but preserves case in the data
|
||||
bool findChannelDataByName(std::string const & name, VChatSystem::Channel & data);
|
||||
void setChannelData(VChatSystem::Channel const & data);
|
||||
bool eraseChannelData(std::string const & name);
|
||||
|
||||
//Helper functions for character channel management.
|
||||
void checkForCharacterChannelAdd(std::string const & name, std::string const & channelName);
|
||||
void checkForCharacterChannelRemove(std::string const & name, std::string const & channelName);
|
||||
|
||||
unsigned internalGetChannel(const std::string &channelName,
|
||||
const std::string &description,
|
||||
const std::string &password,
|
||||
unsigned limit,
|
||||
bool isPublic,
|
||||
bool persistent,
|
||||
std::list<std::string> const & moderators,
|
||||
ReturnAddress const & requester);
|
||||
|
||||
|
||||
typedef std::map<std::string,VChatSystem::Channel> ChannelDataMap;
|
||||
ChannelDataMap m_channelData;
|
||||
typedef std::map<std::string, std::string> GlobalChannelMap;
|
||||
GlobalChannelMap m_globalChannels;
|
||||
bool m_connected;
|
||||
uint32 m_connectionFailedCount;
|
||||
typedef std::map<std::string, std::vector<NetworkId> > VoiceChannelIdMap;
|
||||
VoiceChannelIdMap m_voiceChatChannelNameToNetworkIdMap;
|
||||
|
||||
struct PendingGetChannelRequest
|
||||
{
|
||||
std::string m_channelName;
|
||||
std::string m_description;
|
||||
std::string m_password;
|
||||
unsigned int m_limit;
|
||||
bool m_isPublic;
|
||||
bool m_persistent;
|
||||
std::list<std::string> m_moderators;
|
||||
ReturnAddress m_requester;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, std::list<PendingGetChannelRequest> > PendingGetChannelRequestMap;
|
||||
PendingGetChannelRequestMap m_pendingGetChannelRequests;
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
|
||||
#endif // _INCLUDED_VChatInterface_H
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "FirstChatServer.h"
|
||||
#include "ConfigChatServer.h"
|
||||
#include "ChatServer.h"
|
||||
#include "sharedCompression/SetupSharedCompression.h"
|
||||
#include "sharedDebug/SetupSharedDebug.h"
|
||||
#include "sharedFoundation/SetupSharedFoundation.h"
|
||||
#include "sharedNetworkMessages/SetupSharedNetworkMessages.h"
|
||||
#include "sharedThread/SetupSharedThread.h"
|
||||
|
||||
#include <string>
|
||||
#include <time.h>
|
||||
|
||||
int main( int argc, char ** argv )
|
||||
{
|
||||
SetupSharedThread::install();
|
||||
SetupSharedDebug::install(1024);
|
||||
|
||||
//-- setup foundation
|
||||
SetupSharedFoundation::Data setupFoundationData(SetupSharedFoundation::Data::D_game);
|
||||
|
||||
//setupFoundationData.hInstance = hInstance;
|
||||
setupFoundationData.argc = argc;
|
||||
setupFoundationData.argv = argv;
|
||||
setupFoundationData.createWindow = false;
|
||||
setupFoundationData.clockUsesSleep = true;
|
||||
|
||||
SetupSharedFoundation::install (setupFoundationData);
|
||||
|
||||
SetupSharedCompression::install();
|
||||
|
||||
SetupSharedNetworkMessages::install();
|
||||
|
||||
//-- setup game server
|
||||
ConfigChatServer::install ();
|
||||
|
||||
//-- run game
|
||||
SetupSharedFoundation::callbackWithExceptionHandling(ChatServer::run);
|
||||
|
||||
SetupSharedFoundation::remove();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Vendored
+1
@@ -1,3 +1,4 @@
|
||||
|
||||
add_subdirectory(platform)
|
||||
add_subdirectory(soePlatform)
|
||||
add_subdirectory(udplibrary)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
add_subdirectory(ChatAPI)
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/projects
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/utils
|
||||
)
|
||||
|
||||
add_subdirectory(projects)
|
||||
@@ -0,0 +1,2 @@
|
||||
|
||||
add_subdirectory(ChatMono)
|
||||
+478
@@ -0,0 +1,478 @@
|
||||
#include "AvatarIteratorCore.h"
|
||||
#include "ChatAvatar.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
// AVATAR ITERATOR CORE
|
||||
|
||||
AvatarIteratorCore::AvatarIteratorCore()
|
||||
: m_map(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
AvatarIteratorCore::AvatarIteratorCore(std::map<unsigned, ChatAvatar *> *mapIn, std::map<unsigned, ChatAvatar *>::iterator iter)
|
||||
: m_map(mapIn),
|
||||
m_mapIter(iter)
|
||||
{
|
||||
}
|
||||
|
||||
AvatarIteratorCore::~AvatarIteratorCore()
|
||||
{
|
||||
}
|
||||
|
||||
AvatarIteratorCore &AvatarIteratorCore::operator=(const AvatarIteratorCore& rhs)
|
||||
{
|
||||
m_map = rhs.m_map;
|
||||
m_mapIter = rhs.m_mapIter;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
ChatAvatar *AvatarIteratorCore::getCurAvatar()
|
||||
{
|
||||
ChatAvatar *returnVal = NULL;
|
||||
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = (*m_mapIter).second;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool AvatarIteratorCore::increment()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_mapIter++;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool AvatarIteratorCore::decrement()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_mapIter--;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool AvatarIteratorCore::outOfBounds()
|
||||
{
|
||||
bool returnVal = true;
|
||||
|
||||
if (m_map)
|
||||
{
|
||||
if (m_mapIter != m_map->end())
|
||||
{
|
||||
returnVal = false;
|
||||
}
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
// MODERATOR ITERATOR CORE
|
||||
|
||||
ModeratorIteratorCore::ModeratorIteratorCore()
|
||||
: m_set(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ModeratorIteratorCore::ModeratorIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter)
|
||||
: m_set(setIn),
|
||||
m_setIter(iter)
|
||||
{
|
||||
}
|
||||
|
||||
ModeratorIteratorCore::~ModeratorIteratorCore()
|
||||
{
|
||||
}
|
||||
|
||||
ModeratorIteratorCore &ModeratorIteratorCore::operator=(const ModeratorIteratorCore& rhs)
|
||||
{
|
||||
m_set = rhs.m_set;
|
||||
m_setIter = rhs.m_setIter;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
ChatAvatar *ModeratorIteratorCore::getCurAvatar()
|
||||
{
|
||||
ChatAvatar *returnVal = NULL;
|
||||
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = (*m_setIter);
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool ModeratorIteratorCore::increment()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter++;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool ModeratorIteratorCore::decrement()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter--;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool ModeratorIteratorCore::outOfBounds()
|
||||
{
|
||||
bool returnVal = true;
|
||||
|
||||
if (m_set)
|
||||
{
|
||||
if (m_setIter != m_set->end())
|
||||
{
|
||||
returnVal = false;
|
||||
}
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
// TEMPORARY MODERATOR ITERATOR CORE
|
||||
|
||||
TemporaryModeratorIteratorCore::TemporaryModeratorIteratorCore()
|
||||
: m_set(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
TemporaryModeratorIteratorCore::TemporaryModeratorIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter)
|
||||
: m_set(setIn),
|
||||
m_setIter(iter)
|
||||
{
|
||||
}
|
||||
|
||||
TemporaryModeratorIteratorCore::~TemporaryModeratorIteratorCore()
|
||||
{
|
||||
}
|
||||
|
||||
TemporaryModeratorIteratorCore &TemporaryModeratorIteratorCore::operator=(const TemporaryModeratorIteratorCore& rhs)
|
||||
{
|
||||
m_set = rhs.m_set;
|
||||
m_setIter = rhs.m_setIter;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
ChatAvatar *TemporaryModeratorIteratorCore::getCurAvatar()
|
||||
{
|
||||
ChatAvatar *returnVal = NULL;
|
||||
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = (*m_setIter);
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool TemporaryModeratorIteratorCore::increment()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter++;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool TemporaryModeratorIteratorCore::decrement()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter--;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool TemporaryModeratorIteratorCore::outOfBounds()
|
||||
{
|
||||
bool returnVal = true;
|
||||
|
||||
if (m_set)
|
||||
{
|
||||
if (m_setIter != m_set->end())
|
||||
{
|
||||
returnVal = false;
|
||||
}
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
// VOICE ITERATOR CORE
|
||||
|
||||
VoiceIteratorCore::VoiceIteratorCore()
|
||||
: m_set(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
VoiceIteratorCore::VoiceIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter)
|
||||
: m_set(setIn),
|
||||
m_setIter(iter)
|
||||
{
|
||||
}
|
||||
|
||||
VoiceIteratorCore::~VoiceIteratorCore()
|
||||
{
|
||||
}
|
||||
|
||||
VoiceIteratorCore &VoiceIteratorCore::operator=(const VoiceIteratorCore& rhs)
|
||||
{
|
||||
m_set = rhs.m_set;
|
||||
m_setIter = rhs.m_setIter;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
ChatAvatar *VoiceIteratorCore::getCurAvatar()
|
||||
{
|
||||
ChatAvatar *returnVal = NULL;
|
||||
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = (*m_setIter);
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool VoiceIteratorCore::increment()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter++;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool VoiceIteratorCore::decrement()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter--;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool VoiceIteratorCore::outOfBounds()
|
||||
{
|
||||
bool returnVal = true;
|
||||
|
||||
if (m_set)
|
||||
{
|
||||
if (m_setIter != m_set->end())
|
||||
{
|
||||
returnVal = false;
|
||||
}
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
// INVITE ITERATOR CORE
|
||||
|
||||
InviteIteratorCore::InviteIteratorCore()
|
||||
: m_set(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
InviteIteratorCore::InviteIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter)
|
||||
: m_set(setIn),
|
||||
m_setIter(iter)
|
||||
{
|
||||
}
|
||||
|
||||
InviteIteratorCore::~InviteIteratorCore()
|
||||
{
|
||||
}
|
||||
|
||||
InviteIteratorCore &InviteIteratorCore::operator=(const InviteIteratorCore& rhs)
|
||||
{
|
||||
m_set = rhs.m_set;
|
||||
m_setIter = rhs.m_setIter;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
ChatAvatar *InviteIteratorCore::getCurAvatar()
|
||||
{
|
||||
ChatAvatar *returnVal = NULL;
|
||||
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = (*m_setIter);
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool InviteIteratorCore::increment()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter++;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool InviteIteratorCore::decrement()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter--;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool InviteIteratorCore::outOfBounds()
|
||||
{
|
||||
bool returnVal = true;
|
||||
|
||||
if (m_set)
|
||||
{
|
||||
if (m_setIter != m_set->end())
|
||||
{
|
||||
returnVal = false;
|
||||
}
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
// BAN ITERATOR CORE
|
||||
|
||||
BanIteratorCore::BanIteratorCore()
|
||||
: m_set(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
BanIteratorCore::BanIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter)
|
||||
: m_set(setIn),
|
||||
m_setIter(iter)
|
||||
{
|
||||
}
|
||||
|
||||
BanIteratorCore::~BanIteratorCore()
|
||||
{
|
||||
}
|
||||
|
||||
BanIteratorCore &BanIteratorCore::operator=(const BanIteratorCore& rhs)
|
||||
{
|
||||
m_set = rhs.m_set;
|
||||
m_setIter = rhs.m_setIter;
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
ChatAvatar *BanIteratorCore::getCurAvatar()
|
||||
{
|
||||
ChatAvatar *returnVal = NULL;
|
||||
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = (*m_setIter);
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool BanIteratorCore::increment()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter++;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool BanIteratorCore::decrement()
|
||||
{
|
||||
bool returnVal = false;
|
||||
|
||||
m_setIter--;
|
||||
if (!outOfBounds())
|
||||
{
|
||||
returnVal = true;
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
bool BanIteratorCore::outOfBounds()
|
||||
{
|
||||
bool returnVal = true;
|
||||
|
||||
if (m_set)
|
||||
{
|
||||
if (m_setIter != m_set->end())
|
||||
{
|
||||
returnVal = false;
|
||||
}
|
||||
}
|
||||
|
||||
return returnVal;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+159
@@ -0,0 +1,159 @@
|
||||
#if !defined (AVATARITERATORCORE_H_)
|
||||
#define AVATARITERATORCORE_H_
|
||||
|
||||
#pragma warning (disable : 4786)
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
class ChatAvatar;
|
||||
|
||||
class AvatarIteratorCore
|
||||
{
|
||||
public:
|
||||
AvatarIteratorCore();
|
||||
AvatarIteratorCore(std::map<unsigned, ChatAvatar *> *mapIn, std::map<unsigned, ChatAvatar *>::iterator iter);
|
||||
~AvatarIteratorCore();
|
||||
|
||||
AvatarIteratorCore & operator=(const AvatarIteratorCore& rhs);
|
||||
|
||||
ChatAvatar *getCurAvatar();
|
||||
|
||||
// navigation functions return true while iterator points to a map node,
|
||||
// else false if reached the end.
|
||||
bool increment();
|
||||
bool decrement();
|
||||
|
||||
// have we reached the end?
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
std::map<unsigned, ChatAvatar *> *m_map;
|
||||
std::map<unsigned, ChatAvatar *>::iterator m_mapIter;
|
||||
};
|
||||
|
||||
class ModeratorIteratorCore
|
||||
{
|
||||
public:
|
||||
ModeratorIteratorCore();
|
||||
ModeratorIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter);
|
||||
~ModeratorIteratorCore();
|
||||
|
||||
ModeratorIteratorCore & operator=(const ModeratorIteratorCore& rhs);
|
||||
|
||||
ChatAvatar *getCurAvatar();
|
||||
|
||||
// navigation functions return true while iterator points to a map node,
|
||||
// else false if reached the end.
|
||||
bool increment();
|
||||
bool decrement();
|
||||
|
||||
// have we reached the end?
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
std::set<ChatAvatar *> *m_set;
|
||||
std::set<ChatAvatar *>::iterator m_setIter;
|
||||
};
|
||||
|
||||
class TemporaryModeratorIteratorCore
|
||||
{
|
||||
public:
|
||||
TemporaryModeratorIteratorCore();
|
||||
TemporaryModeratorIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter);
|
||||
~TemporaryModeratorIteratorCore();
|
||||
|
||||
TemporaryModeratorIteratorCore & operator=(const TemporaryModeratorIteratorCore& rhs);
|
||||
|
||||
ChatAvatar *getCurAvatar();
|
||||
|
||||
// navigation functions return true while iterator points to a map node,
|
||||
// else false if reached the end.
|
||||
bool increment();
|
||||
bool decrement();
|
||||
|
||||
// have we reached the end?
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
std::set<ChatAvatar *> *m_set;
|
||||
std::set<ChatAvatar *>::iterator m_setIter;
|
||||
};
|
||||
|
||||
class VoiceIteratorCore
|
||||
{
|
||||
public:
|
||||
VoiceIteratorCore();
|
||||
VoiceIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter);
|
||||
~VoiceIteratorCore();
|
||||
|
||||
VoiceIteratorCore & operator=(const VoiceIteratorCore& rhs);
|
||||
|
||||
ChatAvatar *getCurAvatar();
|
||||
|
||||
// navigation functions return true while iterator points to a map node,
|
||||
// else false if reached the end.
|
||||
bool increment();
|
||||
bool decrement();
|
||||
|
||||
// have we reached the end?
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
std::set<ChatAvatar *> *m_set;
|
||||
std::set<ChatAvatar *>::iterator m_setIter;
|
||||
};
|
||||
|
||||
class InviteIteratorCore
|
||||
{
|
||||
public:
|
||||
InviteIteratorCore();
|
||||
InviteIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter);
|
||||
~InviteIteratorCore();
|
||||
|
||||
InviteIteratorCore & operator=(const InviteIteratorCore& rhs);
|
||||
|
||||
ChatAvatar *getCurAvatar();
|
||||
|
||||
// navigation functions return true while iterator points to a map node,
|
||||
// else false if reached the end.
|
||||
bool increment();
|
||||
bool decrement();
|
||||
|
||||
// have we reached the end?
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
std::set<ChatAvatar *> *m_set;
|
||||
std::set<ChatAvatar *>::iterator m_setIter;
|
||||
};
|
||||
|
||||
class BanIteratorCore
|
||||
{
|
||||
public:
|
||||
BanIteratorCore();
|
||||
BanIteratorCore(std::set<ChatAvatar *> *setIn, std::set<ChatAvatar *>::iterator iter);
|
||||
~BanIteratorCore();
|
||||
|
||||
BanIteratorCore & operator=(const BanIteratorCore& rhs);
|
||||
|
||||
ChatAvatar *getCurAvatar();
|
||||
|
||||
// navigation functions return true while iterator points to a map node,
|
||||
// else false if reached the end.
|
||||
bool increment();
|
||||
bool decrement();
|
||||
|
||||
// have we reached the end?
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
std::set<ChatAvatar *> *m_set;
|
||||
std::set<ChatAvatar *>::iterator m_setIter;
|
||||
};
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#if !defined (AVATARLISTITEM_H_)
|
||||
#define AVATARLISTITEM_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
class AvatarListItemCore;
|
||||
|
||||
class AvatarListItem
|
||||
{
|
||||
public:
|
||||
AvatarListItem();
|
||||
~AvatarListItem();
|
||||
const ChatUnicodeString &getName() const { return m_name; }
|
||||
const ChatUnicodeString &getAddress() const { return m_address; }
|
||||
|
||||
friend class AvatarListItemCore;
|
||||
private:
|
||||
ChatUnicodeString m_name;
|
||||
ChatUnicodeString m_address;
|
||||
|
||||
AvatarListItemCore *m_core;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#include "AvatarListItemCore.h"
|
||||
#include "AvatarListItem.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
using namespace Base;
|
||||
using namespace Plat_Unicode;
|
||||
|
||||
AvatarListItem::AvatarListItem()
|
||||
: m_core(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
AvatarListItem::~AvatarListItem()
|
||||
{
|
||||
}
|
||||
|
||||
AvatarListItemCore::AvatarListItemCore()
|
||||
: m_interface(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
AvatarListItemCore::~AvatarListItemCore()
|
||||
{
|
||||
}
|
||||
|
||||
void AvatarListItemCore::load(Base::ByteStream::ReadIterator &iter, AvatarListItem *inf)
|
||||
{
|
||||
m_interface = inf;
|
||||
inf->m_core = this;
|
||||
get(iter, m_name);
|
||||
get(iter, m_address);
|
||||
|
||||
m_interface->m_name = m_name;
|
||||
m_interface->m_address = m_address;
|
||||
}
|
||||
};
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#if !defined (AVATARLISTITEMCORE_H_)
|
||||
#define AVATARLISTITEMCORE_H_
|
||||
|
||||
#include <Base/Archive.h>
|
||||
#include <Unicode/Unicode.h>
|
||||
#include <Unicode/UnicodeUtils.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
|
||||
class AvatarListItem;
|
||||
|
||||
class AvatarListItemCore
|
||||
{
|
||||
public:
|
||||
AvatarListItemCore();
|
||||
~AvatarListItemCore();
|
||||
|
||||
const Plat_Unicode::String &getName() const { return m_name; }
|
||||
const Plat_Unicode::String &getAddress() const { return m_address; }
|
||||
|
||||
void load(Base::ByteStream::ReadIterator &iter, AvatarListItem *inf);
|
||||
|
||||
private:
|
||||
AvatarListItem *m_interface;
|
||||
Plat_Unicode::String m_name;
|
||||
Plat_Unicode::String m_address;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,106 @@
|
||||
#if !defined (CHATAPICORE_H_)
|
||||
#define CHATAPICORE_H_
|
||||
|
||||
#pragma warning (disable : 4786)
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <Unicode/Unicode.h>
|
||||
#include <Unicode/UnicodeUtils.h>
|
||||
|
||||
#include <GenericAPI/GenericApiCore.h>
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
class ChatAvatar;
|
||||
class ChatAvatarCore;
|
||||
class ChatRoomCore;
|
||||
class ChatRoom;
|
||||
class ChatAPI;
|
||||
class ChatUnicodeString;
|
||||
|
||||
class ChatAPICore : public GenericAPI::GenericAPICore
|
||||
{
|
||||
public:
|
||||
ChatAPICore(const char *registrar_host, short registrar_port, const char *server_host, short server_port);
|
||||
virtual ~ChatAPICore();
|
||||
|
||||
void setRequestTimeout(unsigned requestTimeout) { m_requestTimeout = requestTimeout; }
|
||||
|
||||
unsigned RequestCreateAvatar(const char *name);
|
||||
unsigned RequestDestroyAvatar(ChatAvatar *avatar);
|
||||
|
||||
virtual void responseCallback(GenericAPI::GenericResponse *res);
|
||||
virtual void responseCallback(short type, Base::ByteStream::ReadIterator &iter);
|
||||
void clearRequestCount() { m_requestCount = 0; }
|
||||
|
||||
virtual void OnConnect(const char *host, short port);
|
||||
virtual void OnDisconnect(const char *host, short port);
|
||||
|
||||
void setAPI(ChatAPI *api) { m_api = api; }
|
||||
ChatAvatar *getAvatar(const ChatUnicodeString &avatarName, const ChatUnicodeString &avatarAddress);
|
||||
ChatAvatar *getAvatar(unsigned avatarID);
|
||||
ChatRoom *getRoom(const ChatUnicodeString &roomAddress);
|
||||
ChatRoom *getRoom(unsigned roomID);
|
||||
|
||||
static ChatUnicodeString getErrorString(unsigned resultCode);
|
||||
|
||||
bool isUID(Plat_Unicode::String &uid) { return (m_uidSet.find(Plat_Unicode::toUpper(uid)) != m_uidSet.end()); }
|
||||
|
||||
// calls GenericAPICore::processAPI() after doing any necessary work
|
||||
void processAPI();
|
||||
|
||||
private:
|
||||
void cacheRoom(ChatRoomCore *roomCore);
|
||||
ChatRoomCore *decacheRoom(unsigned roomID);
|
||||
|
||||
ChatRoomCore *getRoomCore(unsigned roomID);
|
||||
|
||||
void cacheAvatar(ChatAvatarCore *avatarCore);
|
||||
ChatAvatarCore *decacheAvatar(unsigned avatarID);
|
||||
|
||||
ChatAvatarCore *getAvatarCore(unsigned avatarID);
|
||||
|
||||
bool areEqualChatStrings(const ChatUnicodeString &str1, const ChatUnicodeString &str2);
|
||||
|
||||
void failoverReloginAvatars();
|
||||
void failoverReloginOneAvatar(ChatAvatarCore * avatarCore);
|
||||
|
||||
void failoverRecreateRooms();
|
||||
|
||||
std::map<unsigned, ChatAvatarCore *> m_avatarCoreCache;
|
||||
std::map<unsigned, ChatAvatar *> m_avatarCache;
|
||||
std::map<unsigned, ChatRoomCore *> m_roomCoreCache;
|
||||
std::map<unsigned, ChatRoom *> m_roomCache;
|
||||
|
||||
std::set<Plat_Unicode::String> m_uidSet;
|
||||
|
||||
bool m_connected;
|
||||
bool m_sentVersion;
|
||||
bool m_inFailoverMode;
|
||||
unsigned m_failoverAvatarResRemain;
|
||||
unsigned m_failoverRoomResRemain;
|
||||
unsigned m_requestCount;
|
||||
|
||||
bool m_setToRegistrar;
|
||||
std::string m_registrarHost;
|
||||
std::string m_defaultServerHost;
|
||||
std::string m_assignedServerHost;
|
||||
short m_registrarPort;
|
||||
short m_defaultServerPort;
|
||||
short m_assignedServerPort;
|
||||
|
||||
time_t m_timeSinceLastDisconnect;
|
||||
bool m_rcvdRegistrarResponse;
|
||||
|
||||
static const char * const ms_errorStringsEnglish[];
|
||||
static unsigned ms_numErrorStrings;
|
||||
|
||||
ChatAPI *m_api;
|
||||
|
||||
protected:
|
||||
bool m_shouldSendVersion;
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
#include "ChatAvatar.h"
|
||||
#include "ChatAvatarCore.h"
|
||||
#include "Base/MD5.h"
|
||||
#include "Unicode/utf8.h"
|
||||
#include <numeric>
|
||||
#include <cctype>
|
||||
#include <algorithm>
|
||||
|
||||
const unsigned MOD_NUMBER = 256;
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
ChatAvatar::ChatAvatar()
|
||||
: m_core(new ChatAvatarCore())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ChatAvatar::ChatAvatar(unsigned avatarID, unsigned userID, const ChatUnicodeString &name, const ChatUnicodeString &address, const ChatUnicodeString &gateway, const ChatUnicodeString &server, unsigned gatewayID, unsigned serverID)
|
||||
: m_core(new ChatAvatarCore(avatarID, userID, name, address, gateway, server, gatewayID, serverID, ChatUnicodeString(), 0)),
|
||||
m_cServer(m_core->getServer().data(), m_core->getServer().size()),
|
||||
m_cGateway(m_core->getGateway().data(), m_core->getGateway().size()),
|
||||
m_cName(m_core->getName().data(), m_core->getName().size()),
|
||||
m_cAddress(m_core->getAddress().data(), m_core->getAddress().size()),
|
||||
m_cLoginLocation(m_core->getLoginLocation().data(), m_core->getLoginLocation().size())
|
||||
{
|
||||
}
|
||||
|
||||
ChatAvatar::ChatAvatar(unsigned avatarID, unsigned userID, const ChatUnicodeString &name, const ChatUnicodeString &address, const ChatUnicodeString &gateway, const ChatUnicodeString &server, unsigned gatewayID, unsigned serverID, const ChatUnicodeString &loginLocation, unsigned attributes)
|
||||
: m_core(new ChatAvatarCore(avatarID, userID, name, address, gateway, server, gatewayID, serverID, loginLocation, attributes)),
|
||||
m_cServer(m_core->getServer().data(), m_core->getServer().size()),
|
||||
m_cGateway(m_core->getGateway().data(), m_core->getGateway().size()),
|
||||
m_cName(m_core->getName().data(), m_core->getName().size()),
|
||||
m_cAddress(m_core->getAddress().data(), m_core->getAddress().size()),
|
||||
m_cLoginLocation(m_core->getLoginLocation().data(), m_core->getLoginLocation().size())
|
||||
{
|
||||
}
|
||||
|
||||
ChatAvatar::ChatAvatar(const ChatAvatar &rhs)
|
||||
: m_core(new ChatAvatarCore(*(rhs.m_core)))
|
||||
{
|
||||
}
|
||||
|
||||
ChatAvatar::~ChatAvatar()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
ChatAvatar &ChatAvatar::operator=(const ChatAvatar &rhs)
|
||||
{
|
||||
delete m_core;
|
||||
m_core = new ChatAvatarCore(rhs.m_core->getAvatarID(),
|
||||
rhs.m_core->getUserID(),
|
||||
rhs.m_core->getName(),
|
||||
rhs.m_core->getAddress(),
|
||||
rhs.m_core->getGateway(),
|
||||
rhs.m_core->getServer(),
|
||||
rhs.m_core->getGatewayID(),
|
||||
rhs.m_core->getServerID(),
|
||||
rhs.m_core->getLoginLocation(),
|
||||
rhs.getAttributes());
|
||||
|
||||
m_cServer = m_core->getServer();
|
||||
m_cGateway= m_core->getGateway();
|
||||
m_cName = m_core->getName();
|
||||
m_cAddress = m_core->getAddress();
|
||||
|
||||
return(*this);
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatAvatar::getName() const
|
||||
{
|
||||
m_cName = m_core->getName();
|
||||
return m_cName;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatAvatar::getAddress() const
|
||||
{
|
||||
m_cAddress = m_core->getAddress();
|
||||
return m_cAddress;
|
||||
}
|
||||
|
||||
unsigned ChatAvatar::getUserID() const
|
||||
{
|
||||
return m_core->getUserID();
|
||||
}
|
||||
|
||||
unsigned ChatAvatar::getAvatarID() const
|
||||
{
|
||||
return m_core->getAvatarID();
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatAvatar::getLoginLocation() const
|
||||
{
|
||||
m_cLoginLocation = m_core->getLoginLocation();
|
||||
|
||||
return m_cLoginLocation;
|
||||
}
|
||||
|
||||
int ChatAvatar::getLoginPriority() const
|
||||
{
|
||||
return m_core->getLoginPriority();
|
||||
}
|
||||
|
||||
unsigned ChatAvatar::getInboxLimit() const
|
||||
{
|
||||
return m_core->getInboxLimit();
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatAvatar::getForwardingEmail() const
|
||||
{
|
||||
m_cForwardingEmail = m_core->getEmail();
|
||||
|
||||
return m_cForwardingEmail;
|
||||
}
|
||||
|
||||
unsigned ChatAvatar::getAttributes() const
|
||||
{
|
||||
return m_core->getAttributes();
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatAvatar::getServer() const
|
||||
{
|
||||
m_cServer = m_core->getServer();
|
||||
return m_cServer;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatAvatar::getGateway() const
|
||||
{
|
||||
m_cGateway = m_core->getGateway();
|
||||
return m_cGateway;
|
||||
}
|
||||
|
||||
unsigned ChatAvatar::getServerID() const
|
||||
{
|
||||
return m_core->getServerID();
|
||||
}
|
||||
|
||||
unsigned ChatAvatar::getGatewayID() const
|
||||
{
|
||||
return m_core->getGatewayID();
|
||||
}
|
||||
|
||||
const ChatUnicodeString& ChatAvatar::getStatusMessage() const
|
||||
{
|
||||
m_cStatusMessage = m_core->getStatusMessage();
|
||||
return m_cStatusMessage;
|
||||
}
|
||||
|
||||
void ChatAvatar::setAttributes(unsigned long attributes)
|
||||
{
|
||||
m_core->setAttributes(attributes);
|
||||
}
|
||||
|
||||
void ChatAvatar::setLoginPriority(int loginPriority)
|
||||
{
|
||||
m_core->setLoginPriority(loginPriority);
|
||||
}
|
||||
|
||||
void ChatAvatar::setInboxLimit(unsigned inboxLimit)
|
||||
{
|
||||
m_core->setInboxLimit(inboxLimit);
|
||||
}
|
||||
|
||||
void ChatAvatar::setForwardingEmail(const ChatUnicodeString &forwardingEmail)
|
||||
{
|
||||
m_core->setEmail(forwardingEmail.data());
|
||||
}
|
||||
|
||||
void ChatAvatar::setStatusMessage(const ChatUnicodeString& statusMessage)
|
||||
{
|
||||
m_core->setStatusMessage( statusMessage.data() );
|
||||
}
|
||||
|
||||
|
||||
ChatUnicodeString ChatAvatar::CreateAddressFromName(const ChatUnicodeString & name, const std::string & gameCode)
|
||||
{
|
||||
// convert to utf8
|
||||
char utf8Buff[256];
|
||||
memset(utf8Buff, 0, 256);
|
||||
Plat_Unicode::UTF16_convertToUTF8( (Plat_Unicode::UTF16 *)name.data(), utf8Buff, 256);
|
||||
|
||||
std::string utf8String(utf8Buff);
|
||||
|
||||
std::transform(utf8String.begin(), utf8String.end(), utf8String.begin(), tolower);
|
||||
|
||||
// hash the username
|
||||
Base::MD5 md5r(utf8String);
|
||||
std::string hexName = md5r.asHex();
|
||||
|
||||
// get the sum of each character
|
||||
unsigned sum = std::accumulate(hexName.begin(), hexName.end(), 0);
|
||||
|
||||
// mod to a world ID.
|
||||
unsigned short worldID = (sum % MOD_NUMBER);
|
||||
|
||||
char buff[256];
|
||||
memset(buff, 0, 256);
|
||||
unsigned len = 0;
|
||||
|
||||
if (gameCode.length() < 230)
|
||||
{
|
||||
len = sprintf (buff, "SOE+%s+World%03d", gameCode.c_str(), worldID);
|
||||
}
|
||||
|
||||
return ChatUnicodeString(buff, len);
|
||||
}
|
||||
|
||||
|
||||
}; // end ChatSystem namespace
|
||||
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#if !defined (CHATAVATAR_H_)
|
||||
#define CHATAVATAR_H_
|
||||
|
||||
#pragma warning (disable : 4786)
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
enum AvatarAttributes
|
||||
{
|
||||
AVATARATTR_INVISIBLE = 1 << 0,
|
||||
AVATARATTR_GM = 1 << 1,
|
||||
AVATARATTR_SUPERGM = 1 << 2,
|
||||
AVATARATTR_SUPERSNOOP = 1 << 3,
|
||||
AVATARATTR_EXTENDED = 1 << 4
|
||||
};
|
||||
|
||||
class ChatAvatarCore;
|
||||
|
||||
// class ChatAvatar
|
||||
//
|
||||
// Description:
|
||||
// This class stores the information about an avatar in the ChatSystem that
|
||||
// is relevant to the API.
|
||||
//
|
||||
// Usage:
|
||||
// Typically a ChatAvatar will originate from an API callback method.
|
||||
// The ChatAvatar object can be copied for local storage and the data
|
||||
// members can be retrieved from the available get__ methods below.
|
||||
class ChatAvatar
|
||||
{
|
||||
public:
|
||||
ChatAvatar();
|
||||
ChatAvatar(unsigned avatarID, unsigned userID, const ChatUnicodeString &name, const ChatUnicodeString &address, const ChatUnicodeString &gateway, const ChatUnicodeString &server, unsigned gatewayID, unsigned serverID);
|
||||
ChatAvatar(unsigned avatarID, unsigned userID, const ChatUnicodeString &name, const ChatUnicodeString &address, const ChatUnicodeString &gateway, const ChatUnicodeString &server, unsigned gatewayID, unsigned serverID, const ChatUnicodeString &loginLocation, unsigned attributes);
|
||||
ChatAvatar(const ChatAvatar &rhs);
|
||||
~ChatAvatar();
|
||||
|
||||
ChatAvatar &operator=(const ChatAvatar &rhs);
|
||||
|
||||
const ChatUnicodeString &getName() const;
|
||||
const ChatUnicodeString &getAddress() const;
|
||||
|
||||
unsigned getUserID() const;
|
||||
unsigned getAvatarID() const;
|
||||
|
||||
const ChatUnicodeString &getServer() const;
|
||||
const ChatUnicodeString &getGateway() const;
|
||||
|
||||
unsigned getServerID() const;
|
||||
unsigned getGatewayID() const;
|
||||
|
||||
const ChatUnicodeString &getLoginLocation() const;
|
||||
int getLoginPriority() const;
|
||||
unsigned getAttributes() const;
|
||||
unsigned getInboxLimit() const;
|
||||
const ChatUnicodeString &getForwardingEmail() const;
|
||||
const ChatUnicodeString& getStatusMessage() const;
|
||||
|
||||
void setAttributes(unsigned long attributes);
|
||||
void setLoginPriority(int loginPriority);
|
||||
void setInboxLimit(unsigned inboxLimit);
|
||||
void setForwardingEmail(const ChatUnicodeString &forwardingEmail);
|
||||
void setStatusMessage(const ChatUnicodeString& statusMessage);
|
||||
|
||||
static ChatUnicodeString CreateAddressFromName(const ChatUnicodeString & name, const std::string & gameCode);
|
||||
|
||||
private:
|
||||
ChatAvatarCore *m_core;
|
||||
mutable ChatUnicodeString m_cServer;
|
||||
mutable ChatUnicodeString m_cGateway;
|
||||
mutable ChatUnicodeString m_cName;
|
||||
mutable ChatUnicodeString m_cAddress;
|
||||
mutable ChatUnicodeString m_cLoginLocation;
|
||||
mutable ChatUnicodeString m_cForwardingEmail;
|
||||
mutable ChatUnicodeString m_cStatusMessage;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+186
@@ -0,0 +1,186 @@
|
||||
#include "ChatAvatarCore.h"
|
||||
#include "ChatAvatar.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
using namespace Plat_Unicode;
|
||||
using namespace Base;
|
||||
|
||||
ChatAvatarCore::ChatAvatarCore()
|
||||
: m_inboxLimit(0),
|
||||
m_loginPriority(0),
|
||||
m_userID(0),
|
||||
m_avatarID(0),
|
||||
m_serverID(0),
|
||||
m_gatewayID(0)
|
||||
{
|
||||
}
|
||||
|
||||
ChatAvatarCore::ChatAvatarCore(unsigned avatarID, unsigned userID, const unsigned short *name, const unsigned short *address, const unsigned short *gateway, const unsigned short *server, unsigned gatewayID, unsigned serverID, const unsigned short *loginLocation, unsigned attributes)
|
||||
: m_name(name),
|
||||
m_address(address),
|
||||
m_server(server),
|
||||
m_gateway(gateway),
|
||||
m_loginLocation(loginLocation),
|
||||
m_attributes(attributes),
|
||||
m_inboxLimit(0),
|
||||
m_loginPriority(0),
|
||||
m_userID(userID),
|
||||
m_avatarID(avatarID),
|
||||
m_serverID(serverID),
|
||||
m_gatewayID(gatewayID)
|
||||
{
|
||||
}
|
||||
|
||||
ChatAvatarCore::ChatAvatarCore(unsigned avatarID, unsigned userID, const ChatUnicodeString &name, const ChatUnicodeString &address, const ChatUnicodeString &gateway, const ChatUnicodeString &server, unsigned gatewayID, unsigned serverID, const ChatUnicodeString &loginLocation, unsigned attributes)
|
||||
: m_name(name.string_data, name.string_length),
|
||||
m_address(address.string_data, address.string_length),
|
||||
m_server(server.string_data, server.string_length),
|
||||
m_gateway(gateway.string_data, gateway.string_length),
|
||||
m_loginLocation(loginLocation.string_data, loginLocation.string_length),
|
||||
m_attributes(attributes),
|
||||
m_inboxLimit(0),
|
||||
m_loginPriority(0),
|
||||
m_userID(userID),
|
||||
m_avatarID(avatarID),
|
||||
m_serverID(serverID),
|
||||
m_gatewayID(gatewayID)
|
||||
{
|
||||
}
|
||||
|
||||
ChatAvatarCore::ChatAvatarCore(unsigned avatarID, unsigned userID, const String &name, const String &address, const String &gateway, const String &server, unsigned gatewayID, unsigned serverID, const Plat_Unicode::String &loginLocation, unsigned attributes)
|
||||
: m_name(name),
|
||||
m_address(address),
|
||||
m_server(server),
|
||||
m_gateway(gateway),
|
||||
m_loginLocation(loginLocation),
|
||||
m_attributes(attributes),
|
||||
m_inboxLimit(0),
|
||||
m_loginPriority(0),
|
||||
m_userID(userID),
|
||||
m_avatarID(avatarID),
|
||||
m_serverID(serverID),
|
||||
m_gatewayID(gatewayID)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
ChatAvatarCore::ChatAvatarCore(ByteStream::ReadIterator &iter)
|
||||
{
|
||||
get(iter, m_avatarID);
|
||||
get(iter, m_userID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_name));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_address));
|
||||
get(iter, (uint32 &)m_attributes);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_loginLocation));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_server));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_gateway));
|
||||
get(iter, m_serverID);
|
||||
get(iter, m_gatewayID);
|
||||
|
||||
m_loginPriority = 0;
|
||||
m_inboxLimit = 0;
|
||||
}
|
||||
|
||||
ChatAvatarCore::ChatAvatarCore(const ChatAvatarCore &rhs)
|
||||
: m_name(rhs.m_name),
|
||||
m_address(rhs.m_address),
|
||||
m_server(rhs.m_server),
|
||||
m_gateway(rhs.m_gateway),
|
||||
m_loginLocation(rhs.m_loginLocation),
|
||||
m_email(rhs.m_email),
|
||||
m_statusMessage(rhs.m_statusMessage),
|
||||
m_attributes(rhs.m_attributes),
|
||||
m_inboxLimit(rhs.m_inboxLimit),
|
||||
m_loginPriority(rhs.m_loginPriority),
|
||||
m_userID(rhs.m_userID),
|
||||
m_avatarID(rhs.m_avatarID),
|
||||
m_serverID(rhs.m_serverID),
|
||||
m_gatewayID(rhs.m_gatewayID)
|
||||
{
|
||||
}
|
||||
|
||||
ChatAvatarCore &ChatAvatarCore::operator=(const ChatAvatarCore &rhs)
|
||||
{
|
||||
m_name = rhs.m_name;
|
||||
m_address = rhs.m_address;
|
||||
m_userID = rhs.m_userID;
|
||||
m_avatarID = rhs.m_avatarID;
|
||||
m_server = rhs.m_server;
|
||||
m_gateway = rhs.m_gateway;
|
||||
m_serverID = rhs.m_serverID;
|
||||
m_gatewayID = rhs.m_gatewayID;
|
||||
m_attributes = rhs.m_attributes;
|
||||
m_inboxLimit = rhs.m_inboxLimit;
|
||||
m_loginPriority = rhs.m_loginPriority;
|
||||
m_loginLocation = rhs.m_loginLocation;
|
||||
m_email = rhs.m_email;
|
||||
m_inboxLimit = rhs.m_inboxLimit;
|
||||
m_statusMessage = rhs.m_statusMessage;
|
||||
|
||||
return(*this);
|
||||
}
|
||||
|
||||
ChatAvatar *ChatAvatarCore::getNewChatAvatar() const
|
||||
{
|
||||
ChatUnicodeString addr(m_address.data(), m_address.size());
|
||||
ChatUnicodeString name(m_name.data(), m_name.size());
|
||||
ChatUnicodeString gateway(m_gateway.data(), m_gateway.size());
|
||||
ChatUnicodeString server(m_server.data(), m_server.size());
|
||||
|
||||
ChatAvatar *newChatAvatar = new ChatAvatar(m_avatarID,
|
||||
m_userID,
|
||||
name,
|
||||
addr,
|
||||
gateway,
|
||||
server,
|
||||
m_gatewayID,
|
||||
m_serverID,
|
||||
m_loginLocation,
|
||||
m_attributes);
|
||||
|
||||
newChatAvatar->setLoginPriority(m_loginPriority);
|
||||
newChatAvatar->setInboxLimit(m_inboxLimit);
|
||||
newChatAvatar->setForwardingEmail(m_email);
|
||||
newChatAvatar->setStatusMessage(m_statusMessage);
|
||||
|
||||
return (newChatAvatar);
|
||||
}
|
||||
|
||||
void ChatAvatarCore::serialize(Base::ByteStream &msg)
|
||||
{
|
||||
put(msg, m_avatarID);
|
||||
put(msg, m_userID);
|
||||
put(msg, m_name);
|
||||
put(msg, m_address);
|
||||
put(msg, (uint32)m_attributes);
|
||||
put(msg, m_loginLocation);
|
||||
}
|
||||
|
||||
void ChatAvatarCore::setAttributes(unsigned long attributes)
|
||||
{
|
||||
m_attributes = attributes;
|
||||
}
|
||||
|
||||
void ChatAvatarCore::setLoginPriority(int loginPriority)
|
||||
{
|
||||
m_loginPriority = loginPriority;
|
||||
}
|
||||
|
||||
void ChatAvatarCore::setEmail(const Plat_Unicode::String email)
|
||||
{
|
||||
m_email = email;
|
||||
}
|
||||
|
||||
void ChatAvatarCore::setInboxLimit(unsigned inboxLimit)
|
||||
{
|
||||
m_inboxLimit = inboxLimit;
|
||||
}
|
||||
|
||||
void ChatAvatarCore::setStatusMessage(const Plat_Unicode::String statusMessage)
|
||||
{
|
||||
m_statusMessage = statusMessage;
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,79 @@
|
||||
#if !defined (CHATAVATARCORE_H_)
|
||||
#define CHATAVATARCORE_H_
|
||||
|
||||
#pragma warning (disable : 4786)
|
||||
|
||||
#include <Base/Archive.h>
|
||||
#include <Unicode/Unicode.h>
|
||||
#include <Unicode/UnicodeUtils.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
|
||||
class ChatAvatar;
|
||||
|
||||
class ChatAvatarCore
|
||||
{
|
||||
public:
|
||||
ChatAvatarCore();
|
||||
ChatAvatarCore(Base::ByteStream::ReadIterator &iter);
|
||||
ChatAvatarCore(unsigned avatarID, unsigned userID, const unsigned short *name, const unsigned short *address, const unsigned short *gateway, const unsigned short *server, unsigned gatewayID, unsigned serverID, const unsigned short *loginLocation, unsigned attributes);
|
||||
ChatAvatarCore(unsigned avatarID, unsigned userID, const ChatUnicodeString &name, const ChatUnicodeString &address, const ChatUnicodeString &gateway, const ChatUnicodeString &server, unsigned gatewayID, unsigned serverID, const ChatUnicodeString &loginLocation, unsigned attributes);
|
||||
ChatAvatarCore(unsigned avatarID, unsigned userID, const Plat_Unicode::String &name, const Plat_Unicode::String &address, const Plat_Unicode::String &gateway, const Plat_Unicode::String &server, unsigned gatewayID, unsigned serverID, const Plat_Unicode::String &loginLocation, unsigned attributes);
|
||||
|
||||
|
||||
ChatAvatarCore(const ChatAvatarCore &rhs);
|
||||
~ChatAvatarCore() {};
|
||||
|
||||
const Plat_Unicode::String &getName() const { return m_name; }
|
||||
const Plat_Unicode::String &getAddress() const { return m_address; }
|
||||
unsigned getUserID() const { return m_userID; }
|
||||
unsigned getAvatarID() const { return m_avatarID; }
|
||||
const Plat_Unicode::String &getLoginLocation() const { return m_loginLocation; }
|
||||
int getLoginPriority() const { return m_loginPriority; }
|
||||
unsigned getAttributes() const { return m_attributes; }
|
||||
const Plat_Unicode::String &getEmail() const { return m_email; }
|
||||
unsigned getInboxLimit() const { return m_inboxLimit; }
|
||||
const Plat_Unicode::String &getServer() const { return m_server; }
|
||||
const Plat_Unicode::String &getGateway() const { return m_gateway; }
|
||||
unsigned getServerID() const { return m_serverID; }
|
||||
unsigned getGatewayID() const { return m_gatewayID; }
|
||||
const Plat_Unicode::String& getStatusMessage() { return m_statusMessage; }
|
||||
|
||||
ChatAvatar *getNewChatAvatar() const;
|
||||
|
||||
void setAttributes(unsigned long attributes);
|
||||
void setLoginPriority(int loginPriority);
|
||||
void setEmail(const Plat_Unicode::String email);
|
||||
void setInboxLimit(unsigned inboxLimit);
|
||||
void setStatusMessage(const Plat_Unicode::String statusMessage);
|
||||
|
||||
ChatAvatarCore &operator=(const ChatAvatarCore &rhs);
|
||||
|
||||
void serialize(Base::ByteStream &msg);
|
||||
private:
|
||||
Plat_Unicode::String m_name;
|
||||
Plat_Unicode::String m_address;
|
||||
Plat_Unicode::String m_server;
|
||||
Plat_Unicode::String m_gateway;
|
||||
Plat_Unicode::String m_loginLocation;
|
||||
Plat_Unicode::String m_email;
|
||||
Plat_Unicode::String m_statusMessage;
|
||||
|
||||
unsigned long m_attributes;
|
||||
unsigned long m_inboxLimit;
|
||||
int m_loginPriority;
|
||||
|
||||
unsigned m_userID;
|
||||
unsigned m_avatarID;
|
||||
unsigned m_serverID;
|
||||
unsigned m_gatewayID;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
#include "ChatEnum.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace ChatSystem {
|
||||
|
||||
using namespace std;
|
||||
using namespace Plat_Unicode;
|
||||
|
||||
Plat_Unicode::String ChatUnicodeString::getEmptyString()
|
||||
{
|
||||
return narrowToWide("");
|
||||
}
|
||||
|
||||
ChatUnicodeString::ChatUnicodeString()
|
||||
{
|
||||
m_wideString = getEmptyString();
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
}
|
||||
|
||||
ChatUnicodeString::ChatUnicodeString(const unsigned short *data, unsigned length)
|
||||
{
|
||||
m_wideString.assign(data, length);
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
}
|
||||
|
||||
ChatUnicodeString::ChatUnicodeString(const char *nData, unsigned length)
|
||||
{
|
||||
m_cString.assign(nData, length);
|
||||
m_wideString = narrowToWide(m_cString);
|
||||
}
|
||||
|
||||
ChatUnicodeString::ChatUnicodeString(const Plat_Unicode::String& src)
|
||||
{
|
||||
m_wideString = src;
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
}
|
||||
|
||||
ChatUnicodeString::ChatUnicodeString(const std::string& nSrc)
|
||||
{
|
||||
m_cString = nSrc;
|
||||
m_wideString = narrowToWide(m_cString);
|
||||
}
|
||||
|
||||
ChatUnicodeString::ChatUnicodeString(const char *nStrSrc)
|
||||
{
|
||||
if (nStrSrc==NULL)
|
||||
{
|
||||
m_wideString = getEmptyString();
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_cString.assign(nStrSrc);
|
||||
m_wideString = narrowToWide(m_cString);
|
||||
}
|
||||
}
|
||||
|
||||
ChatUnicodeString::ChatUnicodeString(const ChatUnicodeString& src)
|
||||
{
|
||||
m_wideString = src.m_wideString;
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
}
|
||||
|
||||
// = operator
|
||||
ChatUnicodeString& ChatUnicodeString::operator=(const Plat_Unicode::String& src)
|
||||
{
|
||||
m_wideString = src;
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ChatUnicodeString& ChatUnicodeString::operator=(const std::string& nSrc)
|
||||
{
|
||||
m_cString = nSrc;
|
||||
m_wideString = narrowToWide(m_cString);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ChatUnicodeString& ChatUnicodeString::operator=(const char * nStrSrc)
|
||||
{
|
||||
m_cString = nStrSrc;
|
||||
m_wideString = narrowToWide(m_cString);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
ChatUnicodeString& ChatUnicodeString::operator=(const ChatUnicodeString& src)
|
||||
{
|
||||
if (this != &src) {
|
||||
m_wideString = src.m_wideString;
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// += operator
|
||||
ChatUnicodeString& ChatUnicodeString::operator+=(const ChatUnicodeString& src)
|
||||
{
|
||||
m_wideString += src.m_wideString;
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// + operator
|
||||
ChatUnicodeString ChatUnicodeString::operator+(const ChatUnicodeString& src)
|
||||
{
|
||||
ChatUnicodeString tmp;
|
||||
|
||||
tmp.m_wideString = m_wideString + src.m_wideString;
|
||||
m_cString = wideToNarrow(m_wideString);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
const char *ChatUnicodeString::c_str() const {
|
||||
return m_cString.c_str();
|
||||
}
|
||||
|
||||
AvatarSnoopPair::AvatarSnoopPair(const Plat_Unicode::String &name, const Plat_Unicode::String &address)
|
||||
: m_name(name),
|
||||
m_address(address)
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,214 @@
|
||||
#if !defined (CHATENUM_H_)
|
||||
#define CHATENUM_H_
|
||||
|
||||
#include <Unicode/Unicode.h>
|
||||
#include <Unicode/UnicodeUtils.h>
|
||||
|
||||
#pragma warning ( disable : 4786 )
|
||||
|
||||
// Defining _chatdebug_
|
||||
#ifdef _DEBUG
|
||||
#ifdef WIN32
|
||||
#define _chatdebug_ ::printf
|
||||
#else
|
||||
#define _chatdebug_ ::printf
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _DEBUG
|
||||
#ifdef WIN32
|
||||
#define _chatdebug_
|
||||
#else
|
||||
#define _chatdebug_
|
||||
#endif
|
||||
#endif
|
||||
// END: "Defining _chatdebug_"
|
||||
|
||||
|
||||
// Use AVATAR_PRIORITY_NOFORCELOGOUT on RequestAvatarLogin if you want to override the
|
||||
// "last login wins" rule, switching that given avatar's session to use "first login wins"
|
||||
#define AVATAR_PRIORITY_NOFORCELOGOUT ((int) 0x80000000) /*-2147483648*/
|
||||
|
||||
#define ASSERT_VALID_STRING_LENGTH(X) if (X ==0) return;
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
enum eResultCodes
|
||||
{
|
||||
CHATRESULT_SUCCESS,
|
||||
|
||||
CHATRESULT_TIMEOUT = 1,
|
||||
CHATRESULT_DUPLICATELOGIN,
|
||||
CHATRESULT_SRCAVATARDOESNTEXIST,
|
||||
CHATRESULT_DESTAVATARDOESNTEXIST,
|
||||
CHATRESULT_ADDRESSDOESNTEXIST, // 5
|
||||
CHATRESULT_ADDRESSNOTROOM,
|
||||
CHATRESULT_ADDRESSNOTAID,
|
||||
CHATRESULT_FRIENDNOTFOUND,
|
||||
CHATRESULT_ROOM_UNKNOWNFAILURE,
|
||||
CHATRESULT_ROOM_SRCNOTINROOM, // 10
|
||||
CHATRESULT_ROOM_DESTNOTINROOM,
|
||||
CHATRESULT_ROOM_BANNEDAVATAR,
|
||||
CHATRESULT_ROOM_PRIVATEROOM,
|
||||
CHATRESULT_ROOM_MODERATEDROOM,
|
||||
CHATRESULT_ROOM_NOTINROOM, // 15
|
||||
CHATRESULT_ROOM_NOPRIVILEGES,
|
||||
CHATRESULT_DATABASE,
|
||||
CHATRESULT_CANNOTGETAVATARID,
|
||||
CHATRESULT_CANNOTGETNODEID,
|
||||
CHATRESULT_CANNOTGETPMSGID, // 20
|
||||
CHATRESULT_PMSGNOTFOUND,
|
||||
CHATRESULT_ROOMMAXAVATARSREACHED,
|
||||
CHATRESULT_IGNORING,
|
||||
CHATRESULT_ROOM_ALREADYEXISTS,
|
||||
CHATRESULT_NOTHINGTOCONFIRM, // 25
|
||||
CHATRESULT_DUPLICATEFRIEND,
|
||||
CHATRESULT_IGNORENOTFOUND,
|
||||
CHATRESULT_DUPLICATEIGNORE,
|
||||
CHATRESULT_DBFAIL,
|
||||
CHATRESULT_ROOM_DESTAVATARNOTMODERATOR, // 30
|
||||
CHATRESULT_ROOM_DESTAVATARNOTINVITED,
|
||||
CHATRESULT_ROOM_DESTAVATARNOTBANNED,
|
||||
CHATRESULT_ROOM_DUPLICATEBAN,
|
||||
CHATRESULT_ROOM_DUPLICATEMODERATOR,
|
||||
CHATRESULT_ROOM_DUPLICATEINVITE, // 35
|
||||
CHATRESULT_ROOM_ALREADYINROOM,
|
||||
CHATRESULT_ROOM_PARENTNONPERSISTENT,
|
||||
CHATRESULT_ROOM_PARENTBADNODETYPE,
|
||||
CHATRESULT_NOFANCLUBHANDLE,
|
||||
CHATRESULT_AIDALREADYEXISTS, // 40
|
||||
CHATRESULT_UIDALREADYEXISTS,
|
||||
CHATRESULT_WRONGCHATSERVERFORREQUEST,
|
||||
CHATRESULT_SUCCESSBADDATA,
|
||||
CHATRESULT_NULLNAMELOGIN,
|
||||
CHATRESULT_SERVER_IDENTITY_EMPTY, // 45
|
||||
CHATRESULT_SERVER_IDENTITY_TAKEN,
|
||||
CHATRESULT_REMOTESERVERDOWN,
|
||||
CHATRESULT_NODEIDCONFLICT,
|
||||
CHATRESULT_INVALIDNODENAME,
|
||||
CHATRESULT_INSUFFICIENTGMPRIVS, // 50
|
||||
CHATRESULT_SNOOPALREADYADDED,
|
||||
CHATRESULT_NOTSNOOPING,
|
||||
CHATRESULT_ROOM_DESTAVATARNOTTEMPORARYMODERATOR,
|
||||
CHATRESULT_ROOM_DESTAVATARNOTVOICE,
|
||||
CHATRESULT_ROOM_DUPLICATETEMPORARYMODERATOR, // 55
|
||||
CHATRESULT_ROOM_DUPLICATEVOICE,
|
||||
CHATRESULT_AVATARMUSTBELOGGEDOUT,
|
||||
CHATRESULT_NOTHINGTODO,
|
||||
CHATRESULT_TRANSFERNAMENULL,
|
||||
CHATRESULT_TRANSFERUSERIDZERO, // 60
|
||||
CHATRESULT_TRANSFERADDRESSNULL,
|
||||
CHATRESULT_OUTOFIDS,
|
||||
CHATRESULT_ROOM_LOCALROOM,
|
||||
CHATRESULT_ROOM_GAMEROOM,
|
||||
CHATRESULT_ROOM_DESTAVATARNOTENTERING, // 65
|
||||
CHATRESULT_INSUFFICIENTPRIORITY,
|
||||
CHATRESULT_ROOM_WAITINGFORENTRY,
|
||||
CHATRESULT_INBOXLIMITEXCEEDED,
|
||||
CHATRESULT_DUPLICATEDESTINATION,
|
||||
CHATRESULT_CATEGORYLIMITEXCEEDED, // 70
|
||||
CHATRESULT_MESSAGE_FILTER_FAILURE,
|
||||
CHATRESULT_INVALID_INPUT,
|
||||
|
||||
};
|
||||
|
||||
// Status for PersistentHeader objects as found in PersistentMessage.h
|
||||
enum PersistentStatus
|
||||
{
|
||||
PERSISTENT_NEW = 1,
|
||||
PERSISTENT_UNREAD,
|
||||
PERSISTENT_READ,
|
||||
PERSISTENT_TRASH,
|
||||
PERSISTENT_DELETED
|
||||
};
|
||||
|
||||
// Bit flags for persistent message alterations. These are used in RequestAlterPersistentMessage
|
||||
enum PersistentAlterationTypes
|
||||
{
|
||||
ALTER_SENDER = 1,
|
||||
ALTER_SUBJECT = 2,
|
||||
ALTER_MSG = 4,
|
||||
ALTER_OOB = 8,
|
||||
ALTER_SENT_TIME = 16,
|
||||
ALTER_CATEGORY = 32
|
||||
};
|
||||
|
||||
// Types of Snoop messages for OnReceiveSnoopMessage() callback in ChatAPI.h
|
||||
enum SnoopTypes
|
||||
{
|
||||
SNOOP_INSTANTMESSAGE,
|
||||
SNOOP_ROOMMESSAGE,
|
||||
SNOOP_PERSISTENTMESSAGE,
|
||||
SNOOP_END
|
||||
};
|
||||
|
||||
#define CHATUNICODESTRING_COMP_OPER_DECL(__oper__) \
|
||||
inline bool operator __oper__(const ChatUnicodeString &src) const \
|
||||
{ \
|
||||
return (m_wideString __oper__ src.m_wideString); \
|
||||
}
|
||||
|
||||
#define string_data data()
|
||||
#define string_length length()
|
||||
|
||||
class ChatUnicodeString {
|
||||
|
||||
private:
|
||||
Plat_Unicode::String m_wideString;
|
||||
Plat_Unicode::String getEmptyString();
|
||||
|
||||
std::string m_cString;
|
||||
|
||||
// const unsigned short *string_data;
|
||||
// unsigned string_length;
|
||||
|
||||
public:
|
||||
|
||||
ChatUnicodeString();
|
||||
ChatUnicodeString(const unsigned short *data, unsigned length);
|
||||
ChatUnicodeString(const char *nData, unsigned length);
|
||||
ChatUnicodeString(const Plat_Unicode::String& src);
|
||||
ChatUnicodeString(const std::string& nSrc);
|
||||
ChatUnicodeString(const char *nStrSrc);
|
||||
ChatUnicodeString(const ChatUnicodeString& src);
|
||||
|
||||
ChatUnicodeString& operator=(const std::string& nSrc);
|
||||
ChatUnicodeString& operator=(const Plat_Unicode::String& src);
|
||||
ChatUnicodeString& operator=(const char *nStrSrc);
|
||||
ChatUnicodeString& operator=(const ChatUnicodeString& src);
|
||||
|
||||
ChatUnicodeString& operator+=(const ChatUnicodeString& src);
|
||||
ChatUnicodeString operator+(const ChatUnicodeString& src);
|
||||
CHATUNICODESTRING_COMP_OPER_DECL(<)
|
||||
CHATUNICODESTRING_COMP_OPER_DECL(<=)
|
||||
CHATUNICODESTRING_COMP_OPER_DECL(==)
|
||||
CHATUNICODESTRING_COMP_OPER_DECL(!=)
|
||||
CHATUNICODESTRING_COMP_OPER_DECL(>=)
|
||||
CHATUNICODESTRING_COMP_OPER_DECL(>)
|
||||
inline unsigned length() const { return (unsigned)m_wideString.length(); }
|
||||
inline const unsigned short * data() const { return m_wideString.data(); }
|
||||
const char * c_str() const;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// class for OnGetSnoopList() callback to summarize a name/address pair
|
||||
class AvatarSnoopPair
|
||||
{
|
||||
public:
|
||||
AvatarSnoopPair(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
~AvatarSnoopPair() {}
|
||||
|
||||
const ChatUnicodeString &getAvatarName() const { return m_name; }
|
||||
const ChatUnicodeString &getAvatarAddress() const { return m_address; }
|
||||
|
||||
private:
|
||||
ChatUnicodeString m_name;
|
||||
ChatUnicodeString m_address;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#if !defined (CHATFRIENDSTATUS_H_)
|
||||
#define CHATFRIENDSTATUS_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
class ChatFriendStatusCore;
|
||||
|
||||
class ChatFriendStatus
|
||||
{
|
||||
public:
|
||||
ChatFriendStatus();
|
||||
~ChatFriendStatus();
|
||||
const ChatUnicodeString &getName() const;
|
||||
const ChatUnicodeString &getAddress() const;
|
||||
const ChatUnicodeString &getComment() const;
|
||||
short getStatus() const; // 0 = offline, else = online
|
||||
|
||||
friend class ChatFriendStatusCore;
|
||||
private:
|
||||
ChatUnicodeString m_name;
|
||||
ChatUnicodeString m_address;
|
||||
ChatUnicodeString m_comment;
|
||||
|
||||
ChatFriendStatusCore *m_core;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
#include "ChatFriendStatusCore.h"
|
||||
#include "ChatFriendStatus.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
using namespace Base;
|
||||
using namespace Plat_Unicode;
|
||||
ChatFriendStatusCore::ChatFriendStatusCore()
|
||||
: m_interface(NULL),
|
||||
m_status(0)
|
||||
{
|
||||
}
|
||||
|
||||
void ChatFriendStatusCore::load(ByteStream::ReadIterator &iter, ChatFriendStatus *inf)
|
||||
{
|
||||
m_interface = inf;
|
||||
inf->m_core = this;
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_name));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_address));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_comment));
|
||||
get(iter, m_status);
|
||||
|
||||
m_interface->m_name = m_name;
|
||||
m_interface->m_address = m_address;
|
||||
m_interface->m_comment = m_comment;
|
||||
}
|
||||
|
||||
ChatFriendStatusCore::~ChatFriendStatusCore()
|
||||
{
|
||||
}
|
||||
|
||||
ChatFriendStatus::ChatFriendStatus()
|
||||
: m_core(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ChatFriendStatus::~ChatFriendStatus()
|
||||
{
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatFriendStatus::getName() const
|
||||
{
|
||||
return m_name;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatFriendStatus::getAddress() const
|
||||
{
|
||||
return m_address;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatFriendStatus::getComment() const
|
||||
{
|
||||
return m_comment;
|
||||
}
|
||||
|
||||
short ChatFriendStatus::getStatus() const
|
||||
{
|
||||
return m_core->getStatus();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
#if !defined (CHATFRIENDSTATUSCORE_H_)
|
||||
#define CHATFRIENDSTATUSCORE_H_
|
||||
|
||||
#include <Base/Archive.h>
|
||||
#include <Unicode/Unicode.h>
|
||||
#include <Unicode/UnicodeUtils.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
|
||||
class ChatFriendStatus;
|
||||
|
||||
class ChatFriendStatusCore
|
||||
{
|
||||
public:
|
||||
ChatFriendStatusCore();
|
||||
~ChatFriendStatusCore();
|
||||
|
||||
const Plat_Unicode::String &getName() const { return m_name; }
|
||||
const Plat_Unicode::String &getAddress() const { return m_address; }
|
||||
short getStatus() const { return m_status; }
|
||||
|
||||
void load(Base::ByteStream::ReadIterator &iter, ChatFriendStatus *inf);
|
||||
|
||||
private:
|
||||
ChatFriendStatus *m_interface;
|
||||
Plat_Unicode::String m_name;
|
||||
Plat_Unicode::String m_address;
|
||||
Plat_Unicode::String m_comment;
|
||||
|
||||
short m_status;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#if !defined (CHATIGNORESTATUS_H_)
|
||||
#define CHATIGNORESTATUS_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
class ChatIgnoreStatusCore;
|
||||
|
||||
class ChatIgnoreStatus
|
||||
{
|
||||
public:
|
||||
ChatIgnoreStatus();
|
||||
~ChatIgnoreStatus();
|
||||
const ChatUnicodeString &getName() const { return m_name; }
|
||||
const ChatUnicodeString &getAddress() const { return m_address; }
|
||||
|
||||
friend class ChatIgnoreStatusCore;
|
||||
private:
|
||||
ChatUnicodeString m_name;
|
||||
ChatUnicodeString m_address;
|
||||
|
||||
ChatIgnoreStatusCore *m_core;
|
||||
};
|
||||
};
|
||||
|
||||
#endif
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#include "ChatIgnoreStatusCore.h"
|
||||
#include "ChatIgnoreStatus.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
using namespace Base;
|
||||
using namespace Plat_Unicode;
|
||||
|
||||
ChatIgnoreStatus::ChatIgnoreStatus()
|
||||
: m_core(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ChatIgnoreStatus::~ChatIgnoreStatus()
|
||||
{
|
||||
}
|
||||
|
||||
ChatIgnoreStatusCore::ChatIgnoreStatusCore()
|
||||
: m_interface(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
ChatIgnoreStatusCore::~ChatIgnoreStatusCore()
|
||||
{
|
||||
}
|
||||
|
||||
void ChatIgnoreStatusCore::load(Base::ByteStream::ReadIterator &iter, ChatIgnoreStatus *inf)
|
||||
{
|
||||
m_interface = inf;
|
||||
inf->m_core = this;
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_name));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_address));
|
||||
|
||||
m_interface->m_name = m_name;
|
||||
m_interface->m_address = m_address;
|
||||
}
|
||||
};
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
#if !defined (CHATIGNORESTATUSCORE_H_)
|
||||
#define CHATIGNORESTATUSCORE_H_
|
||||
|
||||
#include <Base/Archive.h>
|
||||
#include <Unicode/Unicode.h>
|
||||
#include <Unicode/UnicodeUtils.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
|
||||
class ChatIgnoreStatus;
|
||||
|
||||
class ChatIgnoreStatusCore
|
||||
{
|
||||
public:
|
||||
ChatIgnoreStatusCore();
|
||||
~ChatIgnoreStatusCore();
|
||||
|
||||
const Plat_Unicode::String &getName() const { return m_name; }
|
||||
const Plat_Unicode::String &getAddress() const { return m_address; }
|
||||
|
||||
void load(Base::ByteStream::ReadIterator &iter, ChatIgnoreStatus *inf);
|
||||
|
||||
private:
|
||||
ChatIgnoreStatus *m_interface;
|
||||
Plat_Unicode::String m_name;
|
||||
Plat_Unicode::String m_address;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,777 @@
|
||||
#include "ChatRoom.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "AvatarIteratorCore.h"
|
||||
#include "ChatRoomCore.h"
|
||||
#include "ChatAvatar.h"
|
||||
#include "ChatAvatarCore.h"
|
||||
#include "RoomParamsCore.h"
|
||||
#include "RoomSummaryCore.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
using namespace Plat_Unicode;
|
||||
using namespace std;
|
||||
|
||||
|
||||
// AVATAR ITERATOR
|
||||
|
||||
AvatarIterator::AvatarIterator()
|
||||
{
|
||||
m_core = new AvatarIteratorCore();
|
||||
}
|
||||
|
||||
AvatarIterator::AvatarIterator(const AvatarIteratorCore &core)
|
||||
{
|
||||
m_core = new AvatarIteratorCore();
|
||||
|
||||
(*m_core) = core;
|
||||
}
|
||||
|
||||
AvatarIterator::~AvatarIterator()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
AvatarIterator &AvatarIterator::operator=(const AvatarIterator &rhs)
|
||||
{
|
||||
(*m_core) = *(rhs.m_core);
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void AvatarIterator::operator++()
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void AvatarIterator::operator++(int dummyForPostfix)
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void AvatarIterator::operator--()
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
void AvatarIterator::operator--(int dummyForPostfix)
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
ChatAvatar *AvatarIterator::operator*()
|
||||
{
|
||||
return (m_core->getCurAvatar());
|
||||
}
|
||||
|
||||
bool AvatarIterator::outOfBounds()
|
||||
{
|
||||
return (m_core->outOfBounds());
|
||||
}
|
||||
|
||||
// MODERATOR ITERATOR
|
||||
|
||||
ModeratorIterator::ModeratorIterator()
|
||||
{
|
||||
m_core = new ModeratorIteratorCore();
|
||||
}
|
||||
|
||||
ModeratorIterator::ModeratorIterator(const ModeratorIteratorCore &core)
|
||||
{
|
||||
m_core = new ModeratorIteratorCore();
|
||||
|
||||
(*m_core) = core;
|
||||
}
|
||||
|
||||
ModeratorIterator::~ModeratorIterator()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
ModeratorIterator &ModeratorIterator::operator=(const ModeratorIterator &rhs)
|
||||
{
|
||||
(*m_core) = *(rhs.m_core);
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void ModeratorIterator::operator++()
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void ModeratorIterator::operator++(int dummyForPostfix)
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void ModeratorIterator::operator--()
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
void ModeratorIterator::operator--(int dummyForPostfix)
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
ChatAvatar *ModeratorIterator::operator*()
|
||||
{
|
||||
return (m_core->getCurAvatar());
|
||||
}
|
||||
|
||||
bool ModeratorIterator::outOfBounds()
|
||||
{
|
||||
return (m_core->outOfBounds());
|
||||
}
|
||||
|
||||
// TEMPORARY MODERATOR ITERATOR
|
||||
|
||||
TemporaryModeratorIterator::TemporaryModeratorIterator()
|
||||
{
|
||||
m_core = new TemporaryModeratorIteratorCore();
|
||||
}
|
||||
|
||||
TemporaryModeratorIterator::TemporaryModeratorIterator(const TemporaryModeratorIteratorCore &core)
|
||||
{
|
||||
m_core = new TemporaryModeratorIteratorCore();
|
||||
|
||||
(*m_core) = core;
|
||||
}
|
||||
|
||||
TemporaryModeratorIterator::~TemporaryModeratorIterator()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
TemporaryModeratorIterator &TemporaryModeratorIterator::operator=(const TemporaryModeratorIterator &rhs)
|
||||
{
|
||||
(*m_core) = *(rhs.m_core);
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void TemporaryModeratorIterator::operator++()
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void TemporaryModeratorIterator::operator++(int dummyForPostfix)
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void TemporaryModeratorIterator::operator--()
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
void TemporaryModeratorIterator::operator--(int dummyForPostfix)
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
ChatAvatar *TemporaryModeratorIterator::operator*()
|
||||
{
|
||||
return (m_core->getCurAvatar());
|
||||
}
|
||||
|
||||
bool TemporaryModeratorIterator::outOfBounds()
|
||||
{
|
||||
return (m_core->outOfBounds());
|
||||
}
|
||||
|
||||
// VOICE ITERATOR
|
||||
|
||||
VoiceIterator::VoiceIterator()
|
||||
{
|
||||
m_core = new VoiceIteratorCore();
|
||||
}
|
||||
|
||||
VoiceIterator::VoiceIterator(const VoiceIteratorCore &core)
|
||||
{
|
||||
m_core = new VoiceIteratorCore();
|
||||
|
||||
(*m_core) = core;
|
||||
}
|
||||
|
||||
VoiceIterator::~VoiceIterator()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
VoiceIterator &VoiceIterator::operator=(const VoiceIterator &rhs)
|
||||
{
|
||||
(*m_core) = *(rhs.m_core);
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void VoiceIterator::operator++()
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void VoiceIterator::operator++(int dummyForPostfix)
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void VoiceIterator::operator--()
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
void VoiceIterator::operator--(int dummyForPostfix)
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
ChatAvatar *VoiceIterator::operator*()
|
||||
{
|
||||
return (m_core->getCurAvatar());
|
||||
}
|
||||
|
||||
bool VoiceIterator::outOfBounds()
|
||||
{
|
||||
return (m_core->outOfBounds());
|
||||
}
|
||||
|
||||
// INVITE ITERATOR
|
||||
|
||||
InviteIterator::InviteIterator()
|
||||
{
|
||||
m_core = new InviteIteratorCore();
|
||||
}
|
||||
|
||||
InviteIterator::InviteIterator(const InviteIteratorCore &core)
|
||||
{
|
||||
m_core = new InviteIteratorCore();
|
||||
|
||||
(*m_core) = core;
|
||||
}
|
||||
|
||||
InviteIterator::~InviteIterator()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
InviteIterator &InviteIterator::operator=(const InviteIterator &rhs)
|
||||
{
|
||||
(*m_core) = *(rhs.m_core);
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void InviteIterator::operator++()
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void InviteIterator::operator++(int dummyForPostfix)
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void InviteIterator::operator--()
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
void InviteIterator::operator--(int dummyForPostfix)
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
ChatAvatar *InviteIterator::operator*()
|
||||
{
|
||||
return (m_core->getCurAvatar());
|
||||
}
|
||||
|
||||
bool InviteIterator::outOfBounds()
|
||||
{
|
||||
return (m_core->outOfBounds());
|
||||
}
|
||||
|
||||
// BAN ITERATOR
|
||||
|
||||
BanIterator::BanIterator()
|
||||
{
|
||||
m_core = new BanIteratorCore();
|
||||
}
|
||||
|
||||
BanIterator::BanIterator(const BanIteratorCore &core)
|
||||
{
|
||||
m_core = new BanIteratorCore();
|
||||
|
||||
(*m_core) = core;
|
||||
}
|
||||
|
||||
BanIterator::~BanIterator()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
BanIterator &BanIterator::operator=(const BanIterator &rhs)
|
||||
{
|
||||
(*m_core) = *(rhs.m_core);
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void BanIterator::operator++()
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void BanIterator::operator++(int dummyForPostfix)
|
||||
{
|
||||
m_core->increment();
|
||||
}
|
||||
|
||||
void BanIterator::operator--()
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
void BanIterator::operator--(int dummyForPostfix)
|
||||
{
|
||||
m_core->decrement();
|
||||
}
|
||||
|
||||
ChatAvatar *BanIterator::operator*()
|
||||
{
|
||||
return (m_core->getCurAvatar());
|
||||
}
|
||||
|
||||
bool BanIterator::outOfBounds()
|
||||
{
|
||||
return (m_core->outOfBounds());
|
||||
}
|
||||
|
||||
|
||||
// ROOM PARAMS
|
||||
|
||||
RoomParams::RoomParams()
|
||||
{
|
||||
m_core = new struct RoomParamsCore;
|
||||
m_core->m_attributes = 0;
|
||||
m_core->m_size = 0;
|
||||
}
|
||||
|
||||
|
||||
RoomParams::RoomParams(const ChatUnicodeString &name, const ChatUnicodeString &topic, unsigned attributes, unsigned maxSize)
|
||||
{
|
||||
m_core = new struct RoomParamsCore;
|
||||
|
||||
m_core->m_name.assign(name.string_data, name.string_length);
|
||||
m_cName = m_core->m_name;
|
||||
|
||||
m_core->m_topic.assign(topic.string_data, topic.string_length);
|
||||
m_cTopic = m_core->m_topic;
|
||||
|
||||
m_cPassword = m_core->m_password;
|
||||
|
||||
m_core->m_attributes = attributes;
|
||||
m_core->m_size = maxSize;
|
||||
}
|
||||
|
||||
RoomParams::RoomParams(const ChatUnicodeString &name, const ChatUnicodeString &topic, const ChatUnicodeString &password, unsigned attributes, unsigned maxSize)
|
||||
{
|
||||
m_core = new struct RoomParamsCore;
|
||||
|
||||
m_core->m_name.assign(name.string_data, name.string_length);
|
||||
m_cName = m_core->m_name;
|
||||
|
||||
m_core->m_topic.assign(topic.string_data, topic.string_length);
|
||||
m_cTopic = m_core->m_topic;
|
||||
|
||||
m_core->m_password.assign(password.string_data, password.string_length);
|
||||
m_cPassword = m_core->m_password;
|
||||
|
||||
m_core->m_attributes = attributes;
|
||||
m_core->m_size = maxSize;
|
||||
}
|
||||
|
||||
RoomParams::RoomParams(const RoomParams &orig) : m_core(new struct RoomParamsCore)
|
||||
{
|
||||
this->setRoomName(orig.getRoomName());
|
||||
this->setRoomTopic(orig.getRoomTopic());
|
||||
this->setRoomPassword(orig.getRoomPassword());
|
||||
this->setRoomAttributes(orig.getRoomAttributes());
|
||||
this->setRoomMaxSize(orig.getRoomMaxSize());
|
||||
}
|
||||
|
||||
RoomParams::~RoomParams()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
RoomParams &RoomParams::operator=(const RoomParams &rhs)
|
||||
{
|
||||
this->setRoomName(rhs.getRoomName());
|
||||
this->setRoomTopic(rhs.getRoomTopic());
|
||||
this->setRoomPassword(rhs.getRoomPassword());
|
||||
this->setRoomAttributes(rhs.getRoomAttributes());
|
||||
this->setRoomMaxSize(rhs.getRoomMaxSize());
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void RoomParams::setRoomName(const ChatUnicodeString &name)
|
||||
{
|
||||
m_core->m_name.assign(name.string_data, name.string_length);
|
||||
m_cName = m_core->m_name;
|
||||
}
|
||||
|
||||
void RoomParams::setRoomTopic(const ChatUnicodeString &topic)
|
||||
{
|
||||
m_core->m_topic.assign(topic.string_data, topic.string_length);
|
||||
m_cTopic = m_core->m_topic;
|
||||
}
|
||||
|
||||
void RoomParams::setRoomPassword(const ChatUnicodeString &password)
|
||||
{
|
||||
m_core->m_password.assign(password.string_data, password.string_length);
|
||||
m_cPassword = m_core->m_password;
|
||||
}
|
||||
|
||||
void RoomParams::setRoomAttributes(unsigned attributes)
|
||||
{
|
||||
m_core->m_attributes = attributes;
|
||||
}
|
||||
|
||||
void RoomParams::setRoomMaxSize(unsigned size)
|
||||
{
|
||||
m_core->m_size = size;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &RoomParams::getRoomName() const
|
||||
{
|
||||
m_cName = m_core->m_name;
|
||||
return (m_cName);
|
||||
}
|
||||
|
||||
const ChatUnicodeString &RoomParams::getRoomTopic() const
|
||||
{
|
||||
m_cTopic = m_core->m_topic;
|
||||
return (m_cTopic);
|
||||
}
|
||||
|
||||
const ChatUnicodeString &RoomParams::getRoomPassword() const
|
||||
{
|
||||
m_cPassword = m_core->m_password;
|
||||
return (m_cPassword);
|
||||
}
|
||||
|
||||
unsigned RoomParams::getRoomAttributes() const
|
||||
{
|
||||
return (m_core->m_attributes);
|
||||
}
|
||||
|
||||
unsigned RoomParams::getRoomMaxSize() const
|
||||
{
|
||||
return (m_core->m_size);
|
||||
}
|
||||
|
||||
// ROOM SUMMARY
|
||||
|
||||
RoomSummary::RoomSummary()
|
||||
{
|
||||
m_core = new struct RoomSummaryCore;
|
||||
m_core->m_attributes = 0;
|
||||
m_core->m_curSize = 0;
|
||||
m_core->m_maxSize = 0;
|
||||
}
|
||||
|
||||
RoomSummary::RoomSummary(const ChatUnicodeString &address, const ChatUnicodeString &topic, unsigned attributes, unsigned curSize, unsigned maxSize)
|
||||
{
|
||||
m_core = new struct RoomSummaryCore;
|
||||
|
||||
m_core->m_address.assign(address.string_data, address.string_length);
|
||||
m_cAddress = m_core->m_address;
|
||||
|
||||
m_core->m_topic.assign(address.string_data, address.string_length);
|
||||
m_cTopic = m_core->m_address;
|
||||
|
||||
m_core->m_attributes = attributes;
|
||||
m_core->m_curSize = curSize;
|
||||
m_core->m_maxSize = maxSize;
|
||||
}
|
||||
|
||||
RoomSummary::~RoomSummary()
|
||||
{
|
||||
delete m_core;
|
||||
}
|
||||
|
||||
RoomSummary &RoomSummary::operator=(const RoomSummary &rhs)
|
||||
{
|
||||
this->setRoomAddress(rhs.getRoomAddress());
|
||||
m_cAddress= m_core->m_address;
|
||||
|
||||
this->setRoomTopic(rhs.getRoomTopic());
|
||||
m_cTopic = m_core->m_address;
|
||||
|
||||
this->setRoomAttributes(rhs.getRoomAttributes());
|
||||
this->setRoomCurSize(rhs.getRoomCurSize());
|
||||
this->setRoomMaxSize(rhs.getRoomMaxSize());
|
||||
|
||||
return (*this);
|
||||
}
|
||||
|
||||
void RoomSummary::setRoomAddress(const ChatUnicodeString &address)
|
||||
{
|
||||
m_core->m_address.assign(address.string_data, address.string_length);
|
||||
m_cAddress = m_core->m_address;
|
||||
|
||||
}
|
||||
|
||||
void RoomSummary::setRoomTopic(const ChatUnicodeString &topic)
|
||||
{
|
||||
m_core->m_topic.assign(topic.string_data, topic.string_length);
|
||||
m_cTopic = m_core->m_address;
|
||||
}
|
||||
|
||||
void RoomSummary::setRoomAttributes(unsigned attributes)
|
||||
{
|
||||
m_core->m_attributes = attributes;
|
||||
}
|
||||
|
||||
void RoomSummary::setRoomCurSize(unsigned curSize)
|
||||
{
|
||||
m_core->m_curSize = curSize;
|
||||
}
|
||||
|
||||
void RoomSummary::setRoomMaxSize(unsigned maxSize)
|
||||
{
|
||||
m_core->m_maxSize = maxSize;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &RoomSummary::getRoomAddress() const
|
||||
{
|
||||
m_cAddress = m_core->m_address;
|
||||
|
||||
return (m_cAddress);
|
||||
}
|
||||
|
||||
const ChatUnicodeString &RoomSummary::getRoomTopic() const
|
||||
{
|
||||
m_cTopic = m_core->m_topic;
|
||||
|
||||
return (m_cTopic);
|
||||
}
|
||||
|
||||
unsigned RoomSummary::getRoomAttributes() const
|
||||
{
|
||||
return (m_core->m_attributes);
|
||||
}
|
||||
|
||||
unsigned RoomSummary::getRoomCurSize() const
|
||||
{
|
||||
return (m_core->m_curSize);
|
||||
}
|
||||
|
||||
unsigned RoomSummary::getRoomMaxSize() const
|
||||
{
|
||||
return (m_core->m_maxSize);
|
||||
}
|
||||
|
||||
|
||||
// CHAT ROOM
|
||||
|
||||
ChatRoom::ChatRoom()
|
||||
{
|
||||
m_core = NULL;
|
||||
}
|
||||
|
||||
ChatRoom::ChatRoom(ChatRoomCore *core)
|
||||
: m_core(core)
|
||||
{
|
||||
}
|
||||
|
||||
ChatRoom::~ChatRoom()
|
||||
{
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatRoom::getCreatorName() const
|
||||
{
|
||||
m_cCreatorName = m_core->getCreatorName();
|
||||
|
||||
return (m_cCreatorName);
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatRoom::getCreatorAddress() const
|
||||
{
|
||||
m_cCreatorAddress = m_core->getCreatorAddress();
|
||||
|
||||
return (m_cCreatorAddress);
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getCreatorID() const
|
||||
{
|
||||
return (m_core->getCreatorID());
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getRoomID() const
|
||||
{
|
||||
return (m_core->getRoomID());
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatRoom::getRoomName() const
|
||||
{
|
||||
m_cRoomName = m_core->getRoomName();
|
||||
|
||||
return(m_cRoomName);
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatRoom::getRoomTopic() const
|
||||
{
|
||||
m_cRoomTopic = m_core->getRoomTopic();
|
||||
|
||||
return(m_cRoomTopic);
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatRoom::getRoomPassword() const
|
||||
{
|
||||
m_cRoomPassword = m_core->getRoomPassword();
|
||||
|
||||
return(m_cRoomPassword);
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getRoomAttributes() const
|
||||
{
|
||||
return (m_core->getRoomAttributes());
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getMaxRoomSize() const
|
||||
{
|
||||
return (m_core->getMaxRoomSize());
|
||||
}
|
||||
|
||||
const ChatUnicodeString &ChatRoom::getAddress() const
|
||||
{
|
||||
m_cRoomAddress = m_core->getAddress();
|
||||
|
||||
return (m_cRoomAddress);
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getAvatarCount() const
|
||||
{
|
||||
return (m_core->getAvatarCount());
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getBanCount() const
|
||||
{
|
||||
return (m_core->getBanCount());
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getInviteCount() const
|
||||
{
|
||||
return (m_core->getInviteCount());
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getModeratorCount() const
|
||||
{
|
||||
return (m_core->getModeratorCount());
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getTemporaryModeratorCount() const
|
||||
{
|
||||
return (m_core->getTemporaryModeratorCount());
|
||||
}
|
||||
|
||||
unsigned ChatRoom::getVoiceCount() const
|
||||
{
|
||||
return (m_core->getVoiceCount());
|
||||
}
|
||||
|
||||
AvatarIterator ChatRoom::getFirstAvatar() const
|
||||
{
|
||||
return (AvatarIterator(m_core->getFirstAvatar()));
|
||||
}
|
||||
|
||||
AvatarIterator ChatRoom::findAvatar(unsigned avatarID) const
|
||||
{
|
||||
return (AvatarIterator(m_core->findAvatar(avatarID)));
|
||||
}
|
||||
|
||||
AvatarIterator ChatRoom::findAvatar(const ChatUnicodeString &name, const ChatUnicodeString &address) const
|
||||
{
|
||||
String uni_name(name.string_data, name.string_length);
|
||||
String uni_addr(address.string_data, address.string_length);
|
||||
|
||||
return (AvatarIterator(m_core->findAvatar(uni_name, uni_addr)));
|
||||
}
|
||||
|
||||
ModeratorIterator ChatRoom::getFirstModerator() const
|
||||
{
|
||||
return (ModeratorIterator(m_core->getFirstModerator()));
|
||||
}
|
||||
|
||||
ModeratorIterator ChatRoom::findModerator(const ChatUnicodeString &name, const ChatUnicodeString &address) const
|
||||
{
|
||||
String uni_name(name.string_data, name.string_length);
|
||||
String uni_addr(address.string_data, address.string_length);
|
||||
|
||||
return (ModeratorIterator(m_core->findModerator(uni_name, uni_addr)));
|
||||
}
|
||||
|
||||
TemporaryModeratorIterator ChatRoom::getFirstTemporaryModerator() const
|
||||
{
|
||||
return (TemporaryModeratorIterator(m_core->getFirstTemporaryModerator()));
|
||||
}
|
||||
|
||||
TemporaryModeratorIterator ChatRoom::findTemporaryModerator(const ChatUnicodeString &name, const ChatUnicodeString &address) const
|
||||
{
|
||||
String uni_name(name.string_data, name.string_length);
|
||||
String uni_addr(address.string_data, address.string_length);
|
||||
|
||||
return (TemporaryModeratorIterator(m_core->findTemporaryModerator(uni_name, uni_addr)));
|
||||
}
|
||||
|
||||
BanIterator ChatRoom::getFirstBanned() const
|
||||
{
|
||||
return (BanIterator(m_core->getFirstBanned()));
|
||||
}
|
||||
|
||||
BanIterator ChatRoom::findBanned(const ChatUnicodeString &name, const ChatUnicodeString &address) const
|
||||
{
|
||||
String uni_name(name.string_data, name.string_length);
|
||||
String uni_addr(address.string_data, address.string_length);
|
||||
|
||||
return (BanIterator(m_core->findBanned(uni_name, uni_addr)));
|
||||
}
|
||||
|
||||
InviteIterator ChatRoom::getFirstInvited() const
|
||||
{
|
||||
return (InviteIterator(m_core->getFirstInvited()));
|
||||
}
|
||||
|
||||
InviteIterator ChatRoom::findInvited(const ChatUnicodeString &name, const ChatUnicodeString &address) const
|
||||
{
|
||||
String uni_name(name.string_data, name.string_length);
|
||||
String uni_addr(address.string_data, address.string_length);
|
||||
|
||||
return (InviteIterator(m_core->findInvited(uni_name, uni_addr)));
|
||||
}
|
||||
|
||||
VoiceIterator ChatRoom::getFirstVoice() const
|
||||
{
|
||||
return (VoiceIterator(m_core->getFirstVoice()));
|
||||
}
|
||||
|
||||
VoiceIterator ChatRoom::findVoice(const ChatUnicodeString &name, const ChatUnicodeString &address) const
|
||||
{
|
||||
String uni_name(name.string_data, name.string_length);
|
||||
String uni_addr(address.string_data, address.string_length);
|
||||
|
||||
return (VoiceIterator(m_core->findVoice(uni_name, uni_addr)));
|
||||
}
|
||||
|
||||
void ChatRoom::setRoomMessageID(unsigned roomMessageID)
|
||||
{
|
||||
m_core->setRoomMessageID(roomMessageID);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,422 @@
|
||||
#if !defined (CHATROOM_H_)
|
||||
#define CHATROOM_H_
|
||||
|
||||
#pragma warning (disable : 4786)
|
||||
#pragma warning (disable : 4620)
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
|
||||
class ChatAvatar;
|
||||
class ChatRoomCore;
|
||||
class AvatarIteratorCore;
|
||||
class ModeratorIteratorCore;
|
||||
class TemporaryModeratorIteratorCore;
|
||||
class VoiceIteratorCore;
|
||||
class InviteIteratorCore;
|
||||
class BanIteratorCore;
|
||||
struct RoomParamsCore;
|
||||
struct RoomSummaryCore;
|
||||
|
||||
|
||||
// Room attribute test macros
|
||||
// example: IS_SET(myRoomAttributes, ROOMATTR_PERSISTENT)
|
||||
inline unsigned IS_SET(unsigned var, unsigned bit)
|
||||
{
|
||||
return (var & bit);
|
||||
}
|
||||
|
||||
inline unsigned SET_BIT(unsigned &var, unsigned bit)
|
||||
{
|
||||
var |= bit;
|
||||
return(var);
|
||||
}
|
||||
|
||||
inline unsigned REMOVE_BIT(unsigned &var, unsigned bit)
|
||||
{
|
||||
var &= ~bit;
|
||||
return(var);
|
||||
}
|
||||
|
||||
enum RoomAttributes
|
||||
{
|
||||
ROOMATTR_PRIVATE = 1<<0,
|
||||
ROOMATTR_MODERATED = 1<<1,
|
||||
ROOMATTR_PERSISTENT = 1<<2,
|
||||
ROOMATTR_LOCAL_WORLD = 1<<4,
|
||||
ROOMATTR_LOCAL_GAME = 1<<5
|
||||
};
|
||||
|
||||
|
||||
// class RoomParams
|
||||
//
|
||||
// Description:
|
||||
// This class stores the basic room parameters for creating a room.
|
||||
//
|
||||
// Usage:
|
||||
// A RoomParams object is required for creating a room.
|
||||
// It can be copied and there are get__ and set__ methods for retrieving
|
||||
// and storing values.
|
||||
//
|
||||
class RoomParams
|
||||
{
|
||||
public:
|
||||
RoomParams();
|
||||
RoomParams(const ChatUnicodeString &name, const ChatUnicodeString &topic, unsigned attributes, unsigned maxSize);
|
||||
RoomParams(const ChatUnicodeString &name, const ChatUnicodeString &topic, const ChatUnicodeString &password, unsigned attributes, unsigned maxSize);
|
||||
RoomParams(const RoomParams &orig);
|
||||
~RoomParams();
|
||||
|
||||
RoomParams & operator=(const RoomParams &rhs);
|
||||
|
||||
void setRoomName(const ChatUnicodeString &name);
|
||||
void setRoomTopic(const ChatUnicodeString &topic);
|
||||
void setRoomPassword(const ChatUnicodeString &name);
|
||||
void setRoomAttributes(unsigned attributes);
|
||||
void setRoomMaxSize(unsigned size);
|
||||
|
||||
const ChatUnicodeString &getRoomName() const;
|
||||
const ChatUnicodeString &getRoomTopic() const;
|
||||
const ChatUnicodeString &getRoomPassword() const;
|
||||
unsigned getRoomAttributes() const;
|
||||
unsigned getRoomMaxSize() const;
|
||||
|
||||
private:
|
||||
RoomParamsCore *m_core;
|
||||
mutable ChatUnicodeString m_cName;
|
||||
mutable ChatUnicodeString m_cTopic;
|
||||
mutable ChatUnicodeString m_cPassword;
|
||||
};
|
||||
|
||||
|
||||
// class RoomSummary
|
||||
//
|
||||
// Description:
|
||||
// This class stores the basic room parameters to describe a room.
|
||||
// It is useful for describing a room with less byte resources than
|
||||
// a full ChatRoom.
|
||||
//
|
||||
// Usage:
|
||||
// A RoomSummary object is passed through OnGetRoomSummaries().
|
||||
// It can be copied and there are get__ and set__ methods for retrieving
|
||||
// and storing values.
|
||||
//
|
||||
class RoomSummary
|
||||
{
|
||||
public:
|
||||
RoomSummary();
|
||||
RoomSummary(const ChatUnicodeString &name, const ChatUnicodeString &topic, unsigned attributes, unsigned curSize, unsigned maxSize);
|
||||
~RoomSummary();
|
||||
|
||||
RoomSummary & operator=(const RoomSummary &rhs);
|
||||
|
||||
void setRoomAddress(const ChatUnicodeString &address);
|
||||
void setRoomTopic(const ChatUnicodeString &topic);
|
||||
void setRoomAttributes(unsigned attributes);
|
||||
void setRoomCurSize(unsigned curSize);
|
||||
void setRoomMaxSize(unsigned maxSize);
|
||||
|
||||
const ChatUnicodeString &getRoomAddress() const;
|
||||
const ChatUnicodeString &getRoomTopic() const;
|
||||
unsigned getRoomAttributes() const;
|
||||
unsigned getRoomCurSize() const;
|
||||
unsigned getRoomMaxSize() const;
|
||||
|
||||
private:
|
||||
RoomSummaryCore *m_core;
|
||||
mutable ChatUnicodeString m_cAddress;
|
||||
mutable ChatUnicodeString m_cTopic;
|
||||
|
||||
};
|
||||
|
||||
|
||||
// class AvatarIterator
|
||||
//
|
||||
// Description:
|
||||
// This class implements an iterator for the ChatRoom avatar container.
|
||||
//
|
||||
// Usage:
|
||||
// An AvatarIterator will originate from getFirstAvatar() or findAvatar().
|
||||
// It can be copied, incremented, decremented, and dereferenced to get the
|
||||
// ChatAvatar* it points to. To check the validity of the iterator while
|
||||
// iterating to know whether the end of the container has been reached,
|
||||
// use outOfBounds() method.
|
||||
// example:
|
||||
// AvatarIterator iter;
|
||||
// for (iter = room->getFirstAvatar(); iter.outOfBounds() == false; iter++)
|
||||
// {
|
||||
// ChatAvatar *avatar = (*iter);
|
||||
// // do stuff with avatar info
|
||||
// }
|
||||
//
|
||||
class AvatarIterator
|
||||
{
|
||||
public:
|
||||
AvatarIterator();
|
||||
AvatarIterator(const AvatarIteratorCore &core);
|
||||
~AvatarIterator();
|
||||
|
||||
AvatarIterator & operator=(const AvatarIterator &rhs);
|
||||
|
||||
// Bi-directional container navigation
|
||||
void operator++();
|
||||
void operator++(int dummyForPostfix);
|
||||
void operator--();
|
||||
void operator--(int dummyForPostfix);
|
||||
|
||||
// Dereference to ChatAvatar* value
|
||||
ChatAvatar * operator*();
|
||||
|
||||
// Test movement past beginning or end of container
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
AvatarIteratorCore *m_core;
|
||||
};
|
||||
|
||||
// class ModeratorIterator
|
||||
//
|
||||
// Description:
|
||||
// This class implements an iterator for the ChatRoom moderator container.
|
||||
//
|
||||
// Usage:
|
||||
// A ModeratorIterator will originate from getFirstModerator() or findModerator().
|
||||
// Same as AvatarIterator usage.
|
||||
//
|
||||
class ModeratorIterator
|
||||
{
|
||||
public:
|
||||
ModeratorIterator();
|
||||
ModeratorIterator(const ModeratorIteratorCore &core);
|
||||
~ModeratorIterator();
|
||||
|
||||
ModeratorIterator & operator=(const ModeratorIterator &rhs);
|
||||
|
||||
// Bi-directional container navigation
|
||||
void operator++();
|
||||
void operator++(int dummyForPostfix);
|
||||
void operator--();
|
||||
void operator--(int dummyForPostfix);
|
||||
|
||||
// Dereference to ChatAvatar* value
|
||||
ChatAvatar * operator*();
|
||||
|
||||
// Test movement past beginning or end of container
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
ModeratorIteratorCore *m_core;
|
||||
};
|
||||
|
||||
// class TemporaryModeratorIterator
|
||||
//
|
||||
// Description:
|
||||
// This class implements an iterator for the ChatRoom temporary moderator container.
|
||||
//
|
||||
// Usage:
|
||||
// A TemporaryModeratorIterator will originate from getFirstModerator() or findModerator().
|
||||
// Same as AvatarIterator usage.
|
||||
//
|
||||
class TemporaryModeratorIterator
|
||||
{
|
||||
public:
|
||||
TemporaryModeratorIterator();
|
||||
TemporaryModeratorIterator(const TemporaryModeratorIteratorCore &core);
|
||||
~TemporaryModeratorIterator();
|
||||
|
||||
TemporaryModeratorIterator & operator=(const TemporaryModeratorIterator &rhs);
|
||||
|
||||
// Bi-directional container navigation
|
||||
void operator++();
|
||||
void operator++(int dummyForPostfix);
|
||||
void operator--();
|
||||
void operator--(int dummyForPostfix);
|
||||
|
||||
// Dereference to ChatAvatar* value
|
||||
ChatAvatar * operator*();
|
||||
|
||||
// Test movement past beginning or end of container
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
TemporaryModeratorIteratorCore *m_core;
|
||||
};
|
||||
|
||||
// class VoiceIterator
|
||||
//
|
||||
// Description:
|
||||
// This class implements an iterator for the ChatRoom Voice container.
|
||||
//
|
||||
// Usage:
|
||||
// An VoiceIterator will originate from getFirstVoice() or findVoice().
|
||||
// Same as AvatarIterator usage.
|
||||
//
|
||||
class VoiceIterator
|
||||
{
|
||||
public:
|
||||
VoiceIterator();
|
||||
VoiceIterator(const VoiceIteratorCore &core);
|
||||
~VoiceIterator();
|
||||
|
||||
VoiceIterator & operator=(const VoiceIterator &rhs);
|
||||
|
||||
// Bi-directional container navigation
|
||||
void operator++();
|
||||
void operator++(int dummyForPostfix);
|
||||
void operator--();
|
||||
void operator--(int dummyForPostfix);
|
||||
|
||||
// Dereference to ChatAvatar* value
|
||||
ChatAvatar * operator*();
|
||||
|
||||
// Test movement past beginning or end of container
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
VoiceIteratorCore *m_core;
|
||||
};
|
||||
|
||||
// class InviteIterator
|
||||
//
|
||||
// Description:
|
||||
// This class implements an iterator for the ChatRoom invite container.
|
||||
//
|
||||
// Usage:
|
||||
// An InviteIterator will originate from getFirstInvite() or findInvite().
|
||||
// Same as AvatarIterator usage.
|
||||
//
|
||||
class InviteIterator
|
||||
{
|
||||
public:
|
||||
InviteIterator();
|
||||
InviteIterator(const InviteIteratorCore &core);
|
||||
~InviteIterator();
|
||||
|
||||
InviteIterator & operator=(const InviteIterator &rhs);
|
||||
|
||||
// Bi-directional container navigation
|
||||
void operator++();
|
||||
void operator++(int dummyForPostfix);
|
||||
void operator--();
|
||||
void operator--(int dummyForPostfix);
|
||||
|
||||
// Dereference to ChatAvatar* value
|
||||
ChatAvatar * operator*();
|
||||
|
||||
// Test movement past beginning or end of container
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
InviteIteratorCore *m_core;
|
||||
};
|
||||
|
||||
// class BanIterator
|
||||
//
|
||||
// Description:
|
||||
// This class implements an iterator for the ChatRoom ban container.
|
||||
//
|
||||
// Usage:
|
||||
// A BanIterator will originate from getFirstBan() or findBan().
|
||||
// Same as AvatarIterator usage.
|
||||
//
|
||||
class BanIterator
|
||||
{
|
||||
public:
|
||||
BanIterator();
|
||||
BanIterator(const BanIteratorCore &core);
|
||||
~BanIterator();
|
||||
|
||||
BanIterator & operator=(const BanIterator &rhs);
|
||||
|
||||
// Bi-directional container navigation
|
||||
void operator++();
|
||||
void operator++(int dummyForPostfix);
|
||||
void operator--();
|
||||
void operator--(int dummyForPostfix);
|
||||
|
||||
// Dereference to ChatAvatar* value
|
||||
ChatAvatar * operator*();
|
||||
|
||||
// Test movement past beginning or end of container
|
||||
bool outOfBounds();
|
||||
|
||||
private:
|
||||
BanIteratorCore *m_core;
|
||||
};
|
||||
|
||||
// class ChatRoom
|
||||
//
|
||||
// Description:
|
||||
// This class stores the information about a room in the ChatSystem that
|
||||
// is relevant to the API.
|
||||
//
|
||||
// Usage:
|
||||
// A ChatRoom will originate from an API callback method.
|
||||
// The ChatRoom object cannot be copied however all of its member data can
|
||||
// be retrived either by get__ methods or iterator methods (see comments
|
||||
// for AvatarIterator class).
|
||||
//
|
||||
class ChatRoom
|
||||
{
|
||||
public:
|
||||
ChatRoom();
|
||||
ChatRoom(ChatRoomCore *core);
|
||||
~ChatRoom();
|
||||
|
||||
const ChatUnicodeString &getCreatorName() const;
|
||||
const ChatUnicodeString &getCreatorAddress() const;
|
||||
unsigned getCreatorID() const;
|
||||
|
||||
unsigned getRoomID() const;
|
||||
const ChatUnicodeString &getRoomName() const;
|
||||
const ChatUnicodeString &getRoomTopic() const;
|
||||
const ChatUnicodeString &getRoomPassword() const;
|
||||
unsigned getRoomAttributes() const;
|
||||
unsigned getMaxRoomSize() const;
|
||||
const ChatUnicodeString &getAddress() const;
|
||||
|
||||
unsigned getAvatarCount() const;
|
||||
unsigned getBanCount() const;
|
||||
unsigned getInviteCount() const;
|
||||
unsigned getModeratorCount() const;
|
||||
unsigned getTemporaryModeratorCount() const;
|
||||
unsigned getVoiceCount() const;
|
||||
|
||||
AvatarIterator getFirstAvatar() const;
|
||||
AvatarIterator findAvatar(unsigned avatarID) const;
|
||||
AvatarIterator findAvatar(const ChatUnicodeString &name, const ChatUnicodeString &address) const;
|
||||
|
||||
ModeratorIterator getFirstModerator() const;
|
||||
ModeratorIterator findModerator(const ChatUnicodeString &name, const ChatUnicodeString &address) const;
|
||||
|
||||
TemporaryModeratorIterator getFirstTemporaryModerator() const;
|
||||
TemporaryModeratorIterator findTemporaryModerator(const ChatUnicodeString &name, const ChatUnicodeString &address) const;
|
||||
|
||||
BanIterator getFirstBanned() const;
|
||||
BanIterator findBanned(const ChatUnicodeString &name, const ChatUnicodeString &address) const;
|
||||
|
||||
InviteIterator getFirstInvited() const;
|
||||
InviteIterator findInvited(const ChatUnicodeString &name, const ChatUnicodeString &address) const;
|
||||
|
||||
VoiceIterator getFirstVoice() const;
|
||||
VoiceIterator findVoice(const ChatUnicodeString &name, const ChatUnicodeString &address) const;
|
||||
|
||||
void setRoomMessageID(unsigned roomMessageID);
|
||||
|
||||
private:
|
||||
ChatRoomCore *m_core;
|
||||
mutable ChatUnicodeString m_cCreatorAddress;
|
||||
mutable ChatUnicodeString m_cCreatorName;
|
||||
mutable ChatUnicodeString m_cRoomName;
|
||||
mutable ChatUnicodeString m_cRoomTopic;
|
||||
mutable ChatUnicodeString m_cRoomPassword;
|
||||
mutable ChatUnicodeString m_cRoomAddress;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,159 @@
|
||||
#if !defined (CHATROOMCORE_H_)
|
||||
#define CHATROOMCORE_H_
|
||||
|
||||
#pragma warning (disable : 4786)
|
||||
|
||||
#include <set>
|
||||
#include <map>
|
||||
|
||||
#include <Base/Archive.h>
|
||||
#include <Unicode/Unicode.h>
|
||||
#include <Unicode/UnicodeUtils.h>
|
||||
|
||||
#include "ChatRoom.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
class ChatAvatar;
|
||||
class ChatAvatarCore;
|
||||
class AvatarIteratorCore;
|
||||
class ModeratorIteratorCore;
|
||||
class TemporaryModeratorIteratorCore;
|
||||
class VoiceIteratorCore;
|
||||
class InviteIteratorCore;
|
||||
class BanIteratorCore;
|
||||
class RoomParams;
|
||||
|
||||
|
||||
class ChatRoomCore
|
||||
{
|
||||
public:
|
||||
ChatRoomCore();
|
||||
ChatRoomCore(Base::ByteStream::ReadIterator &iter);
|
||||
ChatRoomCore(const Plat_Unicode::String &name, const Plat_Unicode::String &address, const Plat_Unicode::String &topic, const unsigned attributes, const unsigned maxSize);
|
||||
|
||||
~ChatRoomCore();
|
||||
|
||||
const Plat_Unicode::String &getCreatorName() const { return m_creatorName; }
|
||||
const Plat_Unicode::String &getCreatorAddress() const { return m_creatorAddress; }
|
||||
unsigned getCreatorID() const { return m_creatorID; }
|
||||
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomTopic() const { return m_roomTopic; }
|
||||
const Plat_Unicode::String &getRoomPassword() const { return m_roomPassword; }
|
||||
unsigned getRoomAttributes() const { return m_roomAttributes; }
|
||||
unsigned getMaxRoomSize() const { return m_maxRoomSize; }
|
||||
const Plat_Unicode::String &getAddress() const { return m_roomAddress; }
|
||||
unsigned getNodeLevel() const { return m_nodeLevel; }
|
||||
|
||||
unsigned getAvatarCount() const;
|
||||
unsigned getBanCount() const;
|
||||
unsigned getInviteCount() const;
|
||||
unsigned getModeratorCount() const;
|
||||
unsigned getTemporaryModeratorCount() const;
|
||||
unsigned getVoiceCount() const;
|
||||
|
||||
|
||||
void setName(const Plat_Unicode::String &name) { m_roomName = name; }
|
||||
void setTopic(const Plat_Unicode::String &topic) { m_roomTopic = topic; }
|
||||
void setPassword(const Plat_Unicode::String &password) { m_roomPassword = password; }
|
||||
void setAttributes(unsigned attributes) { m_roomAttributes = attributes; }
|
||||
void setMaxRoomSize(unsigned size) { m_maxRoomSize = size; }
|
||||
void setID(unsigned id) { m_roomID = id; }
|
||||
void setCreator(unsigned creatorID, const Plat_Unicode::String &creatorName, const Plat_Unicode::String &creatorAddress);
|
||||
|
||||
void setRoomMessageID(unsigned roomMessageID) { m_roomMessageID = roomMessageID; }
|
||||
|
||||
ChatAvatarCore *getAvatarCore(unsigned avatarID);
|
||||
ChatAvatar *getAvatar(unsigned avatarID);
|
||||
ChatAvatarCore *getModeratorCore(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatar *getModerator(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatarCore *getTemporaryModeratorCore(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatar *getTemporaryModerator(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatarCore *getBannedCore(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatar *getBanned(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatarCore *getInvitedCore(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatar *getInvited(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatarCore *getVoiceCore(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
ChatAvatar *getVoice(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
ChatAvatarCore *addAvatar(ChatAvatarCore *newAvatar, bool local);
|
||||
void addLocalAvatar(unsigned avatarID);
|
||||
ChatAvatarCore *removeAvatar(unsigned avatarID);
|
||||
|
||||
ChatAvatarCore *addAdministrator(ChatAvatarCore *newAvatar);
|
||||
ChatAvatarCore *removeAdministrator(unsigned avatarID);
|
||||
|
||||
ChatAvatarCore *addModerator(ChatAvatarCore *newAvatar);
|
||||
ChatAvatarCore *removeModerator(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
ChatAvatarCore *addTempModerator(ChatAvatarCore *newAvatar);
|
||||
ChatAvatarCore *removeTempModerator(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
ChatAvatarCore *addBan(ChatAvatarCore *newAvatar);
|
||||
ChatAvatarCore *removeBan(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
ChatAvatarCore *addInvite(ChatAvatarCore *newAvatar);
|
||||
ChatAvatarCore *removeInvite(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
ChatAvatarCore *addVoice(ChatAvatarCore *newAvatar);
|
||||
ChatAvatarCore *removeVoice(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
AvatarIteratorCore getFirstAvatar();
|
||||
AvatarIteratorCore findAvatar(unsigned avatarID);
|
||||
AvatarIteratorCore findAvatar(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
ModeratorIteratorCore getFirstModerator();
|
||||
ModeratorIteratorCore findModerator(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
TemporaryModeratorIteratorCore getFirstTemporaryModerator();
|
||||
TemporaryModeratorIteratorCore findTemporaryModerator(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
BanIteratorCore getFirstBanned();
|
||||
BanIteratorCore findBanned(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
InviteIteratorCore getFirstInvited();
|
||||
InviteIteratorCore findInvited(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
VoiceIteratorCore getFirstVoice();
|
||||
VoiceIteratorCore findVoice(const Plat_Unicode::String &name, const Plat_Unicode::String &address);
|
||||
|
||||
void serializeWithLocalAvatarsOnly(Base::ByteStream &msg);
|
||||
|
||||
private:
|
||||
Plat_Unicode::String m_creatorName;
|
||||
Plat_Unicode::String m_creatorAddress;
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomTopic;
|
||||
Plat_Unicode::String m_roomPassword;
|
||||
Plat_Unicode::String m_roomPrefix;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
|
||||
unsigned m_creatorID;
|
||||
unsigned m_roomAttributes;
|
||||
unsigned m_maxRoomSize;
|
||||
unsigned m_roomID;
|
||||
unsigned m_createTime;
|
||||
unsigned m_nodeLevel;
|
||||
unsigned m_roomMessageID;
|
||||
|
||||
std::map<unsigned, ChatAvatarCore *> m_inroomAvatarsCore;
|
||||
std::map<unsigned, ChatAvatar *> m_inroomAvatars;
|
||||
std::set<unsigned> m_inroomAvatarsLocal;
|
||||
std::map<unsigned, ChatAvatarCore *> m_adminAvatarsCore;
|
||||
std::map<unsigned, ChatAvatar *> m_adminAvatars;
|
||||
std::set<ChatAvatarCore *> m_moderatorAvatarsCore;
|
||||
std::set<ChatAvatarCore *> m_tempModeratorAvatarsCore;
|
||||
std::set<ChatAvatar *> m_moderatorAvatars;
|
||||
std::set<ChatAvatar *> m_tempModeratorAvatars;
|
||||
std::set<ChatAvatarCore *> m_banAvatarsCore;
|
||||
std::set<ChatAvatar *> m_banAvatars;
|
||||
std::set<ChatAvatarCore *> m_inviteAvatarsCore;
|
||||
std::set<ChatAvatar *> m_inviteAvatars;
|
||||
std::set<ChatAvatarCore *> m_voiceAvatarsCore;
|
||||
std::set<ChatAvatar *> m_voiceAvatars;
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,515 @@
|
||||
#include "Message.h"
|
||||
#include "PersistentMessage.h"
|
||||
#include "PersistentMessageCore.h"
|
||||
|
||||
|
||||
unsigned numRead;
|
||||
namespace ChatSystem
|
||||
{
|
||||
using namespace std;
|
||||
using namespace Base;
|
||||
using namespace Plat_Unicode;
|
||||
|
||||
MInstantMessage::MInstantMessage(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_INSTANTMESSAGE),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
get(iter, m_destAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_msg));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_oob));
|
||||
}
|
||||
|
||||
MRoomMessage::MRoomMessage(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ROOMMESSAGE),
|
||||
m_destList(NULL),
|
||||
m_srcAvatar(iter),
|
||||
m_messageID(0)
|
||||
{
|
||||
get(iter, m_roomID);
|
||||
get(iter, m_listLength);
|
||||
|
||||
m_destList = new unsigned[m_listLength];
|
||||
for(unsigned i = 0; i < m_listLength; i++)
|
||||
{
|
||||
get(iter, m_destList[i]);
|
||||
}
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_msg));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_oob));
|
||||
|
||||
if (iter.getSize() >= sizeof(unsigned))
|
||||
{
|
||||
get(iter, m_messageID);
|
||||
}
|
||||
}
|
||||
|
||||
MRoomMessage::~MRoomMessage()
|
||||
{
|
||||
delete[] m_destList;
|
||||
m_destList = NULL;
|
||||
}
|
||||
|
||||
MBroadcastMessage::MBroadcastMessage(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_BROADCASTMESSAGE),
|
||||
m_srcAvatar(iter),
|
||||
m_destList(NULL)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_srcAddress));
|
||||
get(iter, m_listLength);
|
||||
|
||||
m_destList = new unsigned[m_listLength];
|
||||
for(unsigned i = 0; i < m_listLength; i++)
|
||||
{
|
||||
get(iter, m_destList[i]);
|
||||
}
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_msg));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_oob));
|
||||
}
|
||||
|
||||
MBroadcastMessage::~MBroadcastMessage()
|
||||
{
|
||||
delete[] m_destList;
|
||||
m_destList = NULL;
|
||||
}
|
||||
|
||||
MFilterMessage::MFilterMessage(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FILTERMESSAGE)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_inmsg));
|
||||
}
|
||||
|
||||
MFriendLogin::MFriendLogin(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FRIENDLOGIN),
|
||||
m_friendAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_friendAddress));
|
||||
get(iter, m_destAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_friendStatus));
|
||||
}
|
||||
|
||||
MFriendLogout::MFriendLogout(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FRIENDLOGOUT),
|
||||
m_friendAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_friendAddress));
|
||||
get(iter, m_destAvatarID);
|
||||
}
|
||||
|
||||
MFriendStatus::MFriendStatus(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FRIENDSTATUS),
|
||||
m_friendAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_friendAddress));
|
||||
get(iter, m_destAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_friendStatus));
|
||||
}
|
||||
|
||||
MKickRoom::MKickRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_KICKROOM),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MKickAvatar::MKickAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_KICKAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MAddModeratorRoom::MAddModeratorRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDMODERATORROOM)
|
||||
{
|
||||
get(iter, m_srcAvatarID);
|
||||
m_destAvatar = new ChatAvatarCore(iter);
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MAddModeratorAvatar::MAddModeratorAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDMODERATORAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MRemoveModeratorRoom::MRemoveModeratorRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEMODERATORROOM)
|
||||
{
|
||||
get(iter, m_srcAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarAddress));
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MRemoveModeratorAvatar::MRemoveModeratorAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEMODERATORAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MAddTemporaryModeratorRoom::MAddTemporaryModeratorRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDMODERATORROOM)
|
||||
{
|
||||
get(iter, m_srcAvatarID);
|
||||
m_destAvatar = new ChatAvatarCore(iter);
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MAddTemporaryModeratorAvatar::MAddTemporaryModeratorAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDMODERATORAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MRemoveTemporaryModeratorRoom::MRemoveTemporaryModeratorRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEMODERATORROOM)
|
||||
{
|
||||
get(iter, m_srcAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarAddress));
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MRemoveTemporaryModeratorAvatar::MRemoveTemporaryModeratorAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEMODERATORAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MAddBanRoom::MAddBanRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDBANROOM),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
m_destAvatar = new ChatAvatarCore(iter);
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MAddBanAvatar::MAddBanAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDBANAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MRemoveBanRoom::MRemoveBanRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEBANROOM)
|
||||
{
|
||||
get(iter, m_srcAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarAddress));
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MRemoveBanAvatar::MRemoveBanAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEBANAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MAddInviteRoom::MAddInviteRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDINVITEROOM),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
m_destAvatar = new ChatAvatarCore(iter);
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MAddInviteAvatar::MAddInviteAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDINVITEAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MRemoveInviteRoom::MRemoveInviteRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEINVITEROOM)
|
||||
{
|
||||
get(iter, m_srcAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarAddress));
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MRemoveInviteAvatar::MRemoveInviteAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEINVITEAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MGrantVoiceRoom::MGrantVoiceRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDINVITEROOM),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
m_destAvatar = new ChatAvatarCore(iter);
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MGrantVoiceAvatar::MGrantVoiceAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDINVITEAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MRevokeVoiceRoom::MRevokeVoiceRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEINVITEROOM)
|
||||
{
|
||||
get(iter, m_srcAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAvatarAddress));
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MRevokeVoiceAvatar::MRevokeVoiceAvatar(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEINVITEAVATAR),
|
||||
m_srcAvatar(iter),
|
||||
m_destAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomAddress));
|
||||
}
|
||||
|
||||
MEnterRoom::MEnterRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ENTERROOM),
|
||||
m_srcAvatar(new ChatAvatarCore(iter))
|
||||
{
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MLeaveRoom::MLeaveRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_LEAVEROOM)
|
||||
{
|
||||
get(iter, m_avatarID);
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MDestroyRoom::MDestroyRoom(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_DESTROYROOM),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MSetRoomParams::MSetRoomParams(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_SETROOMPARAMS),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomTopic));
|
||||
get(iter, m_roomAttributes);
|
||||
get(iter, m_maxRoomSize);
|
||||
get(iter, m_roomID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_roomPassword));
|
||||
}
|
||||
|
||||
MPersistentMessage::MPersistentMessage(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_PERSISTENTMESSAGE)
|
||||
{
|
||||
m_core = new PersistentHeaderCore();
|
||||
m_header = new PersistentHeader();
|
||||
get(iter, m_destAvatarID);
|
||||
|
||||
// unpack messageID,
|
||||
// destAvatarID,
|
||||
// fromName,
|
||||
// fromAddress,
|
||||
// subject,
|
||||
// sentTime, and
|
||||
// status into PersistentHeaderCore object
|
||||
m_core->load(iter, m_header);
|
||||
|
||||
if (iter.getSize() > 0)
|
||||
{
|
||||
m_core->setCategory(iter);
|
||||
}
|
||||
}
|
||||
|
||||
MPersistentMessage::~MPersistentMessage()
|
||||
{
|
||||
delete m_core;
|
||||
delete m_header;
|
||||
}
|
||||
|
||||
MForcedLogout::MForcedLogout(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FORCEDLOGOUT)
|
||||
{
|
||||
get(iter, m_avatarID);
|
||||
}
|
||||
|
||||
MUnregisterRoomReady::MUnregisterRoomReady(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_UNREGISTERROOMREADY)
|
||||
{
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MAddAdmin::MAddAdmin(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_ADDADMIN),
|
||||
m_avatar(new ChatAvatarCore(iter))
|
||||
{
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MRemoveAdmin::MRemoveAdmin(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REMOVEADMIN)
|
||||
{
|
||||
get(iter, m_avatarID);
|
||||
get(iter, m_roomID);
|
||||
}
|
||||
|
||||
MFriendConfirmRequest::MFriendConfirmRequest(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FRIENDCONFIRMREQUEST),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
get(iter, m_destAvatarID);
|
||||
}
|
||||
|
||||
MFriendConfirmResponse::MFriendConfirmResponse(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FRIENDCONFIRMRESPONSE),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
get(iter, m_destAvatarID);
|
||||
get(iter, m_confirm);
|
||||
}
|
||||
|
||||
MFriendConfirmReciprocateRequest::MFriendConfirmReciprocateRequest(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FRIENDCONFIRMRECIPROCATE_REQUEST),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
get(iter, m_destAvatarID);
|
||||
}
|
||||
|
||||
MFriendConfirmReciprocateResponse::MFriendConfirmReciprocateResponse(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FRIENDCONFIRMRECIPROCATE_RESPONSE),
|
||||
m_srcAvatar(iter)
|
||||
{
|
||||
get(iter, m_destAvatarID);
|
||||
get(iter, m_confirm);
|
||||
}
|
||||
|
||||
MChangeRoomOwner::MChangeRoomOwner(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_CHANGEROOMOWNER)
|
||||
{
|
||||
get(iter, m_destRoomID);
|
||||
get(iter, m_newRoomOwnerID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_newRoomOwnerName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_newRoomOwnerAddress));
|
||||
}
|
||||
|
||||
MRoomEntryRequest::MRoomEntryRequest(Base::ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_REQUESTROOMENTRY),
|
||||
m_requestorAvatar(iter)
|
||||
{
|
||||
get(iter, m_roomOwnerID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_requestedRoomAddress));
|
||||
}
|
||||
|
||||
MDelayedRoomEntry::MDelayedRoomEntry(Base::ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_DELAYEDROOMENTRY)
|
||||
{
|
||||
int numExtraRooms = 0;
|
||||
|
||||
get(iter, m_avatarID);
|
||||
get(iter, m_roomID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_enteredAddress));
|
||||
get(iter, numExtraRooms);
|
||||
|
||||
while (numExtraRooms > 0)
|
||||
{
|
||||
m_setExtraRooms.insert(new ChatRoomCore(iter));
|
||||
numExtraRooms--;
|
||||
}
|
||||
}
|
||||
|
||||
MDeniedRoomEntry::MDeniedRoomEntry(Base::ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_DENIEDROOMENTRY)
|
||||
{
|
||||
get(iter, m_requestorAvatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_requestedRoomAddress));
|
||||
}
|
||||
|
||||
MForceRoomFailover::MForceRoomFailover(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_FORCEROOMFAILOVER)
|
||||
{
|
||||
unsigned numAIDs(0);
|
||||
get(iter, numAIDs);
|
||||
|
||||
String aid;
|
||||
for (unsigned i = 0; i < numAIDs; i++)
|
||||
{
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, aid));
|
||||
m_aidList.push_back(aid);
|
||||
}
|
||||
}
|
||||
|
||||
MSnoop::MSnoop(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_SNOOP)
|
||||
{
|
||||
get(iter, m_snoopType);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_snooperName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_snooperAddr));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_srcName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_srcAddr));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAddr));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_message));
|
||||
}
|
||||
|
||||
MUIDList::MUIDList(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_UIDLIST)
|
||||
{
|
||||
unsigned numUIDs;
|
||||
get(iter, numUIDs);
|
||||
for (unsigned i = 0; i < numUIDs; i++)
|
||||
{
|
||||
Plat_Unicode::String uid;
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, uid));
|
||||
m_uidList.insert(toUpper(uid));
|
||||
}
|
||||
}
|
||||
|
||||
MNotifyFriendIsRemoved::MNotifyFriendIsRemoved(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_NOTIFY_FRIEND_IS_REMOVED)
|
||||
{
|
||||
get(iter, m_avatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_destAddress));
|
||||
|
||||
}
|
||||
|
||||
MNotifyFriendsListChange::MNotifyFriendsListChange(ByteStream::ReadIterator &iter)
|
||||
: GenericMessage(MESSAGE_NOTIFY_FRIENDS_LIST_CHANGE)
|
||||
{
|
||||
get(iter, m_avatarID);
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_originalName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_originalAddress));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_newName));
|
||||
ASSERT_VALID_STRING_LENGTH(get(iter, m_newAddress));
|
||||
}
|
||||
|
||||
};
|
||||
@@ -0,0 +1,929 @@
|
||||
#if !defined (MESSAGE_H_)
|
||||
#define MESSAGE_H_
|
||||
#pragma warning (disable : 4786)
|
||||
|
||||
#include <GenericAPI/GenericMessage.h>
|
||||
#include <Unicode/Unicode.h>
|
||||
|
||||
#include "ChatRoomCore.h"
|
||||
#include "ChatAvatarCore.h"
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <set>
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
class PersistentHeader;
|
||||
class PersistentHeaderCore;
|
||||
|
||||
enum eMessageType
|
||||
{
|
||||
// ChatAvatar message types
|
||||
MESSAGE_INSTANTMESSAGE, // 0
|
||||
MESSAGE_ROOMMESSAGE,
|
||||
MESSAGE_BROADCASTMESSAGE,
|
||||
MESSAGE_FRIENDLOGIN,
|
||||
MESSAGE_FRIENDLOGOUT,
|
||||
MESSAGE_KICKROOM, // 5
|
||||
|
||||
// ChatRoom message types
|
||||
MESSAGE_ADDMODERATORROOM,
|
||||
MESSAGE_REMOVEMODERATORROOM,
|
||||
MESSAGE_REMOVEMODERATORAVATAR,
|
||||
MESSAGE_ADDBANROOM,
|
||||
MESSAGE_REMOVEBANROOM, // 10
|
||||
MESSAGE_REMOVEBANAVATAR,
|
||||
MESSAGE_ADDINVITEROOM,
|
||||
MESSAGE_ADDINVITEAVATAR,
|
||||
MESSAGE_REMOVEINVITEROOM,
|
||||
MESSAGE_REMOVEINVITEAVATAR, // 15
|
||||
MESSAGE_ENTERROOM,
|
||||
MESSAGE_LEAVEROOM,
|
||||
MESSAGE_DESTROYROOM,
|
||||
MESSAGE_SETROOMPARAMS,
|
||||
MESSAGE_PERSISTENTMESSAGE, // 20
|
||||
MESSAGE_FORCEDLOGOUT,
|
||||
MESSAGE_UNREGISTERROOMREADY,
|
||||
MESSAGE_KICKAVATAR,
|
||||
MESSAGE_ADDMODERATORAVATAR,
|
||||
MESSAGE_ADDBANAVATAR, // 25
|
||||
MESSAGE_ADDADMIN,
|
||||
MESSAGE_REMOVEADMIN,
|
||||
MESSAGE_FRIENDCONFIRMREQUEST,
|
||||
MESSAGE_FRIENDCONFIRMRESPONSE,
|
||||
MESSAGE_CHANGEROOMOWNER, // 30
|
||||
MESSAGE_FORCEROOMFAILOVER,
|
||||
MESSAGE_ADDTEMPORARYMODERATORROOM,
|
||||
MESSAGE_ADDTEMPORARYMODERATORAVATAR,
|
||||
MESSAGE_REMOVETEMPORARYMODERATORROOM,
|
||||
MESSAGE_REMOVETEMPORARYMODERATORAVATAR, // 35
|
||||
MESSAGE_GRANTVOICEROOM,
|
||||
MESSAGE_GRANTVOICEAVATAR,
|
||||
MESSAGE_REVOKEVOICEROOM,
|
||||
MESSAGE_REVOKEVOICEAVATAR,
|
||||
MESSAGE_SNOOP, // 40
|
||||
MESSAGE_UIDLIST,
|
||||
MESSAGE_REQUESTROOMENTRY,
|
||||
MESSAGE_DELAYEDROOMENTRY,
|
||||
MESSAGE_DENIEDROOMENTRY,
|
||||
MESSAGE_FRIENDSTATUS, // 45
|
||||
MESSAGE_FRIENDCONFIRMRECIPROCATE_REQUEST,
|
||||
MESSAGE_FRIENDCONFIRMRECIPROCATE_RESPONSE,
|
||||
MESSAGE_FILTERMESSAGE,
|
||||
MESSAGE_FAILOVER_AVATAR_LIST,
|
||||
MESSAGE_NOTIFY_FRIENDS_LIST_CHANGE, // 50
|
||||
MESSAGE_NOTIFY_FRIEND_IS_REMOVED
|
||||
|
||||
};
|
||||
|
||||
class MInstantMessage : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MInstantMessage(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MInstantMessage() {};
|
||||
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const Plat_Unicode::String &getMsg() const { return m_msg; }
|
||||
const Plat_Unicode::String &getOOB() const { return m_oob; }
|
||||
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
unsigned m_destAvatarID;
|
||||
Plat_Unicode::String m_msg;
|
||||
Plat_Unicode::String m_oob;
|
||||
};
|
||||
|
||||
class MRoomMessage : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRoomMessage(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRoomMessage();
|
||||
|
||||
unsigned getListLength() const { return m_listLength; }
|
||||
const unsigned *getDestList() const { return m_destList; }
|
||||
ChatAvatarCore *getSrcAvatar() { return &m_srcAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
const Plat_Unicode::String &getMsg() const { return m_msg; }
|
||||
const Plat_Unicode::String &getOOB() const { return m_oob; }
|
||||
unsigned getMessageID() const { return m_messageID; }
|
||||
|
||||
private:
|
||||
unsigned m_listLength;
|
||||
unsigned *m_destList;
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
unsigned m_roomID;
|
||||
Plat_Unicode::String m_msg;
|
||||
Plat_Unicode::String m_oob;
|
||||
unsigned m_messageID;
|
||||
};
|
||||
|
||||
class MBroadcastMessage : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MBroadcastMessage(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MBroadcastMessage();
|
||||
|
||||
unsigned getListLength() const { return m_listLength; }
|
||||
const unsigned *getDestList() const { return m_destList; }
|
||||
ChatAvatarCore *getSrcAvatar() { return &m_srcAvatar; }
|
||||
const Plat_Unicode::String &getSrcAddress() const { return m_srcAddress; }
|
||||
const Plat_Unicode::String &getMsg() const { return m_msg; }
|
||||
const Plat_Unicode::String &getOOB() const { return m_oob; }
|
||||
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
unsigned m_listLength;
|
||||
unsigned *m_destList;
|
||||
Plat_Unicode::String m_srcAddress;
|
||||
Plat_Unicode::String m_msg;
|
||||
Plat_Unicode::String m_oob;
|
||||
};
|
||||
|
||||
class MFilterMessage : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MFilterMessage(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MFilterMessage() {};
|
||||
|
||||
const Plat_Unicode::String &getMsg() const { return m_inmsg; }
|
||||
|
||||
private:
|
||||
Plat_Unicode::String m_inmsg;
|
||||
};
|
||||
|
||||
class MFriendLogin : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MFriendLogin(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MFriendLogin() {};
|
||||
|
||||
const ChatAvatarCore *getFriendAvatar() const { return &m_friendAvatar; }
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
const Plat_Unicode::String &getFriendAddress() const { return m_friendAddress; }
|
||||
const Plat_Unicode::String &getFriendStatusMessage() const { return m_friendStatus; }
|
||||
|
||||
private:
|
||||
ChatAvatarCore m_friendAvatar;
|
||||
unsigned m_destAvatarID;
|
||||
Plat_Unicode::String m_friendAddress;
|
||||
Plat_Unicode::String m_friendStatus;
|
||||
};
|
||||
|
||||
class MFriendLogout : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MFriendLogout(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MFriendLogout() {};
|
||||
|
||||
const ChatAvatarCore *getFriendAvatar() const { return &m_friendAvatar; }
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
const Plat_Unicode::String &getFriendAddress() const { return m_friendAddress; }
|
||||
|
||||
private:
|
||||
ChatAvatarCore m_friendAvatar;
|
||||
unsigned m_destAvatarID;
|
||||
Plat_Unicode::String m_friendAddress;
|
||||
};
|
||||
|
||||
class MFriendStatus : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MFriendStatus(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MFriendStatus() {};
|
||||
|
||||
const ChatAvatarCore *getFriendAvatar() const { return &m_friendAvatar; }
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
const Plat_Unicode::String &getFriendAddress() const { return m_friendAddress; }
|
||||
const Plat_Unicode::String &getFriendStatusMessage() const { return m_friendStatus; }
|
||||
|
||||
private:
|
||||
ChatAvatarCore m_friendAvatar;
|
||||
unsigned m_destAvatarID;
|
||||
Plat_Unicode::String m_friendAddress;
|
||||
Plat_Unicode::String m_friendStatus;
|
||||
};
|
||||
|
||||
class MKickRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MKickRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MKickRoom() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MKickAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MKickAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MKickAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MAddModeratorRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddModeratorRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddModeratorRoom() {};
|
||||
|
||||
unsigned getSrcAvatarID() const { return m_srcAvatarID; }
|
||||
ChatAvatarCore *getDestAvatar() const { return m_destAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_srcAvatarID;
|
||||
ChatAvatarCore *m_destAvatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MAddModeratorAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddModeratorAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddModeratorAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MRemoveModeratorRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveModeratorRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveModeratorRoom() {};
|
||||
|
||||
unsigned getSrcAvatarID() const { return m_srcAvatarID; }
|
||||
const Plat_Unicode::String &getDestAvatarName() const { return m_destAvatarName; }
|
||||
const Plat_Unicode::String &getDestAvatarAddress() const { return m_destAvatarAddress; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_srcAvatarID;
|
||||
Plat_Unicode::String m_destAvatarName;
|
||||
Plat_Unicode::String m_destAvatarAddress;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MRemoveModeratorAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveModeratorAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveModeratorAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MAddTemporaryModeratorRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddTemporaryModeratorRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddTemporaryModeratorRoom() {};
|
||||
|
||||
unsigned getSrcAvatarID() const { return m_srcAvatarID; }
|
||||
ChatAvatarCore *getDestAvatar() const { return m_destAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_srcAvatarID;
|
||||
ChatAvatarCore *m_destAvatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MAddTemporaryModeratorAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddTemporaryModeratorAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddTemporaryModeratorAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MRemoveTemporaryModeratorRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveTemporaryModeratorRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveTemporaryModeratorRoom() {};
|
||||
|
||||
unsigned getSrcAvatarID() const { return m_srcAvatarID; }
|
||||
const Plat_Unicode::String &getDestAvatarName() const { return m_destAvatarName; }
|
||||
const Plat_Unicode::String &getDestAvatarAddress() const { return m_destAvatarAddress; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_srcAvatarID;
|
||||
Plat_Unicode::String m_destAvatarName;
|
||||
Plat_Unicode::String m_destAvatarAddress;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MRemoveTemporaryModeratorAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveTemporaryModeratorAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveTemporaryModeratorAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MAddBanRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddBanRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddBanRoom() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
ChatAvatarCore *getDestAvatar() const { return m_destAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore *m_destAvatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MAddBanAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddBanAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddBanAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MRemoveBanRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveBanRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveBanRoom() {};
|
||||
|
||||
unsigned getSrcAvatarID() const { return m_srcAvatarID; }
|
||||
const Plat_Unicode::String &getDestAvatarName() const { return m_destAvatarName; }
|
||||
const Plat_Unicode::String &getDestAvatarAddress() const { return m_destAvatarAddress; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_srcAvatarID;
|
||||
Plat_Unicode::String m_destAvatarName;
|
||||
Plat_Unicode::String m_destAvatarAddress;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MRemoveBanAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveBanAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveBanAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MAddInviteRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddInviteRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddInviteRoom() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
ChatAvatarCore *getDestAvatar() const { return m_destAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore *m_destAvatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MAddInviteAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddInviteAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddInviteAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MRemoveInviteRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveInviteRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveInviteRoom() {};
|
||||
|
||||
unsigned getSrcAvatarID() const { return m_srcAvatarID; }
|
||||
const Plat_Unicode::String &getDestAvatarName() const { return m_destAvatarName; }
|
||||
const Plat_Unicode::String &getDestAvatarAddress() const { return m_destAvatarAddress; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_srcAvatarID;
|
||||
Plat_Unicode::String m_destAvatarName;
|
||||
Plat_Unicode::String m_destAvatarAddress;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MRemoveInviteAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveInviteAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveInviteAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MGrantVoiceRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MGrantVoiceRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MGrantVoiceRoom() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
ChatAvatarCore *getDestAvatar() const { return m_destAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore *m_destAvatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MGrantVoiceAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MGrantVoiceAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MGrantVoiceAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MRevokeVoiceRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRevokeVoiceRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRevokeVoiceRoom() {};
|
||||
|
||||
unsigned getSrcAvatarID() const { return m_srcAvatarID; }
|
||||
const Plat_Unicode::String &getDestAvatarName() const { return m_destAvatarName; }
|
||||
const Plat_Unicode::String &getDestAvatarAddress() const { return m_destAvatarAddress; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_srcAvatarID;
|
||||
Plat_Unicode::String m_destAvatarName;
|
||||
Plat_Unicode::String m_destAvatarAddress;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MRevokeVoiceAvatar : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRevokeVoiceAvatar(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRevokeVoiceAvatar() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const ChatAvatarCore *getDestAvatar() const { return &m_destAvatar; }
|
||||
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomAddress() const { return m_roomAddress; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
ChatAvatarCore m_destAvatar;
|
||||
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomAddress;
|
||||
};
|
||||
|
||||
class MEnterRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MEnterRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MEnterRoom() {};
|
||||
|
||||
ChatAvatarCore *getSrcAvatar() const { return m_srcAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
ChatAvatarCore *m_srcAvatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MLeaveRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MLeaveRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MLeaveRoom() {};
|
||||
|
||||
unsigned getAvatarID() const { return m_avatarID; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_avatarID;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MDestroyRoom : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MDestroyRoom(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MDestroyRoom() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MSetRoomParams : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MSetRoomParams(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MSetRoomParams() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
const Plat_Unicode::String &getRoomName() const { return m_roomName; }
|
||||
const Plat_Unicode::String &getRoomTopic() const { return m_roomTopic; }
|
||||
const Plat_Unicode::String &getRoomPassword() const { return m_roomPassword; }
|
||||
unsigned getRoomAttributes() const { return m_roomAttributes; }
|
||||
unsigned getRoomSize() const { return m_maxRoomSize; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
Plat_Unicode::String m_roomName;
|
||||
Plat_Unicode::String m_roomTopic;
|
||||
Plat_Unicode::String m_roomPassword;
|
||||
unsigned m_roomAttributes;
|
||||
unsigned m_maxRoomSize;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MPersistentMessage : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MPersistentMessage(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MPersistentMessage();
|
||||
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
const PersistentHeader *getHeader() const { return m_header; }
|
||||
|
||||
private:
|
||||
unsigned m_destAvatarID;
|
||||
PersistentHeaderCore *m_core;
|
||||
PersistentHeader *m_header;
|
||||
};
|
||||
|
||||
class MForcedLogout : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MForcedLogout(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MForcedLogout() {};
|
||||
|
||||
unsigned getAvatarID() const { return m_avatarID; }
|
||||
|
||||
private:
|
||||
unsigned m_avatarID;
|
||||
};
|
||||
|
||||
class MUnregisterRoomReady : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MUnregisterRoomReady(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MUnregisterRoomReady() {};
|
||||
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MAddAdmin : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MAddAdmin(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MAddAdmin() {};
|
||||
|
||||
ChatAvatarCore *getAvatar() const { return m_avatar; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
ChatAvatarCore *m_avatar;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MRemoveAdmin : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRemoveAdmin(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRemoveAdmin() {};
|
||||
|
||||
unsigned getAvatarID() const { return m_avatarID; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
private:
|
||||
unsigned m_avatarID;
|
||||
unsigned m_roomID;
|
||||
};
|
||||
|
||||
class MFriendConfirmRequest : GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MFriendConfirmRequest(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MFriendConfirmRequest() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
unsigned m_destAvatarID;
|
||||
};
|
||||
|
||||
class MFriendConfirmResponse : GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MFriendConfirmResponse(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MFriendConfirmResponse() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
bool getConfirm() const { return m_confirm != 0; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
unsigned m_destAvatarID;
|
||||
short m_confirm;
|
||||
};
|
||||
|
||||
class MFriendConfirmReciprocateRequest : GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MFriendConfirmReciprocateRequest(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MFriendConfirmReciprocateRequest() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
unsigned m_destAvatarID;
|
||||
};
|
||||
|
||||
class MFriendConfirmReciprocateResponse : GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MFriendConfirmReciprocateResponse(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MFriendConfirmReciprocateResponse() {};
|
||||
|
||||
const ChatAvatarCore *getSrcAvatar() const { return &m_srcAvatar; }
|
||||
unsigned getDestAvatarID() const { return m_destAvatarID; }
|
||||
bool getConfirm() const { return m_confirm != 0; }
|
||||
private:
|
||||
ChatAvatarCore m_srcAvatar;
|
||||
unsigned m_destAvatarID;
|
||||
short m_confirm;
|
||||
};
|
||||
|
||||
class MChangeRoomOwner: GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MChangeRoomOwner(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MChangeRoomOwner() {};
|
||||
|
||||
unsigned getDestRoomID() const { return m_destRoomID; }
|
||||
unsigned getNewRoomOwnerID() const { return m_newRoomOwnerID; }
|
||||
const Plat_Unicode::String &getNewRoomOwnerName() const { return m_newRoomOwnerName; }
|
||||
const Plat_Unicode::String &getNewRoomOwnerAddress() const { return m_newRoomOwnerAddress; }
|
||||
|
||||
private:
|
||||
unsigned m_destRoomID;
|
||||
unsigned m_newRoomOwnerID;
|
||||
Plat_Unicode::String m_newRoomOwnerName;
|
||||
Plat_Unicode::String m_newRoomOwnerAddress;
|
||||
};
|
||||
|
||||
class MRoomEntryRequest : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MRoomEntryRequest(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MRoomEntryRequest() {};
|
||||
|
||||
unsigned getRoomOwnerID() const { return m_roomOwnerID; }
|
||||
const ChatAvatarCore *getRequestorAvatar() const { return &m_requestorAvatar; }
|
||||
const Plat_Unicode::String &getRequestedRoomAddress() const { return m_requestedRoomAddress; }
|
||||
|
||||
private:
|
||||
unsigned m_roomOwnerID;
|
||||
ChatAvatarCore m_requestorAvatar;
|
||||
Plat_Unicode::String m_requestedRoomAddress;
|
||||
};
|
||||
|
||||
class MDelayedRoomEntry : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MDelayedRoomEntry(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MDelayedRoomEntry() {};
|
||||
|
||||
unsigned getAvatarID() const { return m_avatarID; }
|
||||
unsigned getRoomID() const { return m_roomID; }
|
||||
const Plat_Unicode::String &getEnteredAddress() { return m_enteredAddress; }
|
||||
ChatRoomCore *getRoom() const { return m_room; }
|
||||
const std::set<ChatRoomCore *> &getExtraRooms() { return m_setExtraRooms; }
|
||||
|
||||
private:
|
||||
unsigned m_avatarID;
|
||||
unsigned m_roomID;
|
||||
Plat_Unicode::String m_enteredAddress;
|
||||
ChatRoomCore* m_room;
|
||||
std::set<ChatRoomCore *> m_setExtraRooms;
|
||||
};
|
||||
|
||||
class MDeniedRoomEntry : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MDeniedRoomEntry(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MDeniedRoomEntry() {};
|
||||
|
||||
unsigned getRequestorID() const { return m_requestorAvatarID; }
|
||||
const Plat_Unicode::String &getRequestedRoomAddress() const { return m_requestedRoomAddress; }
|
||||
|
||||
private:
|
||||
unsigned m_requestorAvatarID;
|
||||
Plat_Unicode::String m_requestedRoomAddress;
|
||||
};
|
||||
|
||||
class MForceRoomFailover : GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MForceRoomFailover(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MForceRoomFailover() {};
|
||||
|
||||
const std::list<Plat_Unicode::String> &getAIDList() const { return m_aidList; }
|
||||
private:
|
||||
std::list <Plat_Unicode::String> m_aidList;
|
||||
};
|
||||
|
||||
class MSnoop : GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MSnoop(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MSnoop() {};
|
||||
|
||||
unsigned getSnoopType() const { return m_snoopType; }
|
||||
const Plat_Unicode::String &getSnooperName() const { return m_snooperName; }
|
||||
const Plat_Unicode::String &getSnooperAddr() const { return m_snooperAddr; }
|
||||
const Plat_Unicode::String &getSrcName() const { return m_srcName; }
|
||||
const Plat_Unicode::String &getSrcAddr() const { return m_srcAddr; }
|
||||
const Plat_Unicode::String &getDestName() const { return m_destName; }
|
||||
const Plat_Unicode::String &getDestAddr() const { return m_destAddr; }
|
||||
const Plat_Unicode::String &getMessage() const { return m_message; }
|
||||
private:
|
||||
unsigned m_snoopType;
|
||||
Plat_Unicode::String m_snooperName;
|
||||
Plat_Unicode::String m_snooperAddr;
|
||||
Plat_Unicode::String m_srcName;
|
||||
Plat_Unicode::String m_srcAddr;
|
||||
Plat_Unicode::String m_destName;
|
||||
Plat_Unicode::String m_destAddr;
|
||||
Plat_Unicode::String m_message;
|
||||
};
|
||||
|
||||
class MUIDList : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MUIDList(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MUIDList() {};
|
||||
|
||||
const std::set<Plat_Unicode::String> &getUIDList() const { return m_uidList; }
|
||||
private:
|
||||
std::set<Plat_Unicode::String> m_uidList;
|
||||
};
|
||||
|
||||
class MNotifyFriendIsRemoved : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MNotifyFriendIsRemoved(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MNotifyFriendIsRemoved() {};
|
||||
|
||||
const unsigned &getAvatarID() const { return m_avatarID; }
|
||||
const Plat_Unicode::String &getDestName() const { return m_destName; }
|
||||
const Plat_Unicode::String &getDestAddress() const { return m_destAddress; }
|
||||
private:
|
||||
unsigned m_avatarID;
|
||||
Plat_Unicode::String m_destName;
|
||||
Plat_Unicode::String m_destAddress;
|
||||
};
|
||||
|
||||
class MNotifyFriendsListChange : public GenericAPI::GenericMessage
|
||||
{
|
||||
public:
|
||||
MNotifyFriendsListChange(Base::ByteStream::ReadIterator &iter);
|
||||
virtual ~MNotifyFriendsListChange() {};
|
||||
|
||||
const unsigned &getAvatarID() const { return m_avatarID; }
|
||||
const Plat_Unicode::String &getOriginalName() const { return m_originalName; }
|
||||
const Plat_Unicode::String &getOriginalAddress() const { return m_originalAddress; }
|
||||
const Plat_Unicode::String &getNewName() const { return m_newName; }
|
||||
const Plat_Unicode::String &getNewAddress() const { return m_newAddress; }
|
||||
private:
|
||||
|
||||
unsigned m_avatarID;
|
||||
Plat_Unicode::String m_originalName;
|
||||
Plat_Unicode::String m_originalAddress;
|
||||
Plat_Unicode::String m_newName;
|
||||
Plat_Unicode::String m_newAddress;
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
+156
@@ -0,0 +1,156 @@
|
||||
#include "PersistentMessage.h"
|
||||
#include "PersistentMessageCore.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
using namespace Base;
|
||||
using namespace Plat_Unicode;
|
||||
|
||||
PersistentHeader::PersistentHeader()
|
||||
: m_core(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
PersistentHeader::~PersistentHeader()
|
||||
{
|
||||
}
|
||||
|
||||
unsigned PersistentHeader::getMessageID() const
|
||||
{
|
||||
return m_core->getMessageID();
|
||||
}
|
||||
|
||||
unsigned PersistentHeader::getAvatarID() const
|
||||
{
|
||||
return m_core->getAvatarID();
|
||||
}
|
||||
|
||||
const ChatUnicodeString &PersistentHeader::getFromName() const
|
||||
{
|
||||
return m_fromName;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &PersistentHeader::getFromAddress() const
|
||||
{
|
||||
return m_fromAddress;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &PersistentHeader::getSubject() const
|
||||
{
|
||||
return m_subject;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &PersistentHeader::getFolder() const
|
||||
{
|
||||
return m_folder;
|
||||
}
|
||||
|
||||
const ChatUnicodeString &PersistentHeader::getCategory() const
|
||||
{
|
||||
return m_category;
|
||||
}
|
||||
|
||||
unsigned PersistentHeader::getSentTime() const
|
||||
{
|
||||
return m_core->getSentTime();
|
||||
}
|
||||
|
||||
unsigned PersistentHeader::getStatus() const
|
||||
{
|
||||
return m_core->getStatus();
|
||||
}
|
||||
|
||||
PersistentHeaderCore::PersistentHeaderCore()
|
||||
: m_messageID(0),
|
||||
m_avatarID(0),
|
||||
m_sentTime(0),
|
||||
m_status(0),
|
||||
m_interface(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
PersistentHeaderCore::~PersistentHeaderCore()
|
||||
{
|
||||
}
|
||||
|
||||
void PersistentHeaderCore::load(ByteStream::ReadIterator &iter, PersistentHeader *inf)
|
||||
{
|
||||
m_interface = inf;
|
||||
inf->m_core = this;
|
||||
get(iter, m_messageID);
|
||||
get(iter, m_avatarID);
|
||||
get(iter, m_fromName);
|
||||
get(iter, m_fromAddress);
|
||||
get(iter, m_subject);
|
||||
get(iter, m_sentTime);
|
||||
get(iter, m_status);
|
||||
|
||||
m_interface->m_fromName = m_fromName;
|
||||
m_interface->m_fromAddress = m_fromAddress;
|
||||
m_interface->m_subject = m_subject;
|
||||
}
|
||||
|
||||
void PersistentHeaderCore::setFolder(Base::ByteStream::ReadIterator &iter)
|
||||
{
|
||||
get(iter, m_folder);
|
||||
|
||||
m_interface->m_folder = m_folder;
|
||||
}
|
||||
|
||||
|
||||
void PersistentHeaderCore::setCategory(Base::ByteStream::ReadIterator &iter)
|
||||
{
|
||||
get(iter, m_category);
|
||||
|
||||
m_interface->m_category = m_category;
|
||||
}
|
||||
|
||||
PersistentMessageCore::PersistentMessageCore()
|
||||
: m_messageID(0),
|
||||
m_avatarID(0),
|
||||
m_sentTime(0),
|
||||
m_status(0),
|
||||
m_fetchResult(0)
|
||||
{
|
||||
}
|
||||
|
||||
PersistentMessageCore::~PersistentMessageCore()
|
||||
{
|
||||
}
|
||||
|
||||
void PersistentMessageCore::load(Base::ByteStream::ReadIterator &iter)
|
||||
{
|
||||
Plat_Unicode::String wideString;
|
||||
|
||||
get(iter, m_messageID);
|
||||
get(iter, m_avatarID);
|
||||
|
||||
get(iter, wideString);
|
||||
m_fromName = wideString;
|
||||
|
||||
get(iter, wideString);
|
||||
m_fromAddress = wideString;
|
||||
|
||||
get(iter, wideString);
|
||||
m_subject = wideString;
|
||||
|
||||
get(iter, m_sentTime);
|
||||
get(iter, m_status);
|
||||
|
||||
get(iter, wideString);
|
||||
m_folder = wideString;
|
||||
|
||||
get(iter, wideString);
|
||||
m_category = wideString;
|
||||
|
||||
get(iter, m_fetchResult);
|
||||
|
||||
get(iter, wideString);
|
||||
m_msg = wideString;
|
||||
|
||||
get(iter, wideString);
|
||||
m_oob = wideString;
|
||||
}
|
||||
|
||||
};
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#if !defined (PERSISTENTMESSAGE_H_)
|
||||
#define PERSISTENTMESSAGE_H_
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
class PersistentHeaderCore;
|
||||
|
||||
class PersistentHeader
|
||||
{
|
||||
public:
|
||||
PersistentHeader();
|
||||
~PersistentHeader();
|
||||
|
||||
unsigned getMessageID() const;
|
||||
unsigned getAvatarID() const;
|
||||
const ChatUnicodeString &getFromName() const;
|
||||
const ChatUnicodeString &getFromAddress() const;
|
||||
const ChatUnicodeString &getSubject() const;
|
||||
const ChatUnicodeString &getFolder() const;
|
||||
const ChatUnicodeString &getCategory() const;
|
||||
|
||||
unsigned getSentTime() const;
|
||||
unsigned getStatus() const;
|
||||
|
||||
friend class PersistentHeaderCore;
|
||||
private:
|
||||
ChatUnicodeString m_fromName;
|
||||
ChatUnicodeString m_fromAddress;
|
||||
ChatUnicodeString m_subject;
|
||||
ChatUnicodeString m_folder;
|
||||
ChatUnicodeString m_category;
|
||||
|
||||
PersistentHeaderCore *m_core;
|
||||
};
|
||||
|
||||
class PersistentMessage
|
||||
{
|
||||
public:
|
||||
virtual unsigned getMessageID() const = 0;
|
||||
virtual unsigned getAvatarID() const = 0;
|
||||
virtual const ChatUnicodeString &getFromName() const = 0;
|
||||
virtual const ChatUnicodeString &getFromAddress() const = 0;
|
||||
virtual const ChatUnicodeString &getSubject() const = 0;
|
||||
virtual const ChatUnicodeString &getFolder() const = 0;
|
||||
virtual const ChatUnicodeString &getCategory() const = 0;
|
||||
|
||||
virtual unsigned getSentTime() const = 0;
|
||||
virtual unsigned getStatus() const = 0;
|
||||
|
||||
virtual const ChatUnicodeString &getMsg() const = 0;
|
||||
virtual const ChatUnicodeString &getOOB() const = 0;
|
||||
};
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#if !defined (PERSISTENTHEADERCORE_H_)
|
||||
#define PERSISTENTHEADERCORE_H_
|
||||
|
||||
#include <Base/Archive.h>
|
||||
#include <Unicode/Unicode.h>
|
||||
#include <Unicode/UnicodeUtils.h>
|
||||
|
||||
namespace ChatSystem
|
||||
{
|
||||
|
||||
class PersistentHeader;
|
||||
|
||||
class PersistentHeaderCore
|
||||
{
|
||||
public:
|
||||
PersistentHeaderCore();
|
||||
~PersistentHeaderCore();
|
||||
|
||||
unsigned getMessageID() const { return m_messageID; }
|
||||
unsigned getAvatarID() const { return m_avatarID; }
|
||||
const Plat_Unicode::String &getFromName() const { return m_fromName; }
|
||||
const Plat_Unicode::String &getFromAddress() const { return m_fromAddress; }
|
||||
const Plat_Unicode::String &getSubject() const { return m_subject; }
|
||||
const Plat_Unicode::String &getFolder() const { return m_folder; }
|
||||
|
||||
unsigned getSentTime() const { return m_sentTime; }
|
||||
unsigned getStatus() const { return m_status; }
|
||||
void load(Base::ByteStream::ReadIterator &iter, PersistentHeader *inf);
|
||||
void setFolder(Base::ByteStream::ReadIterator &iter);
|
||||
void setCategory(Base::ByteStream::ReadIterator &iter);
|
||||
private:
|
||||
unsigned m_messageID;
|
||||
unsigned m_avatarID;
|
||||
unsigned m_sentTime;
|
||||
unsigned m_status;
|
||||
Plat_Unicode::String m_fromName;
|
||||
Plat_Unicode::String m_fromAddress;
|
||||
Plat_Unicode::String m_subject;
|
||||
Plat_Unicode::String m_folder;
|
||||
Plat_Unicode::String m_category;
|
||||
|
||||
PersistentHeader *m_interface;
|
||||
};
|
||||
|
||||
class PersistentMessageCore : public PersistentMessage
|
||||
{
|
||||
public:
|
||||
PersistentMessageCore();
|
||||
virtual ~PersistentMessageCore();
|
||||
|
||||
// PersistentMessage implementations
|
||||
virtual unsigned getMessageID() const { return m_messageID; }
|
||||
virtual unsigned getAvatarID() const { return m_avatarID; }
|
||||
virtual const ChatUnicodeString &getFromName() const { return m_fromName; }
|
||||
virtual const ChatUnicodeString &getFromAddress() const { return m_fromAddress; }
|
||||
virtual const ChatUnicodeString &getSubject() const { return m_subject; }
|
||||
virtual const ChatUnicodeString &getFolder() const { return m_folder; }
|
||||
virtual const ChatUnicodeString &getCategory() const { return m_category; }
|
||||
|
||||
virtual unsigned getSentTime() const { return m_sentTime; }
|
||||
virtual unsigned getStatus() const { return m_status; }
|
||||
|
||||
virtual const ChatUnicodeString &getMsg() const { return m_msg; }
|
||||
virtual const ChatUnicodeString &getOOB() const { return m_oob; }
|
||||
|
||||
void load(Base::ByteStream::ReadIterator &iter);
|
||||
|
||||
private:
|
||||
unsigned m_messageID;
|
||||
unsigned m_avatarID;
|
||||
unsigned m_sentTime;
|
||||
unsigned m_status;
|
||||
unsigned m_fetchResult;
|
||||
ChatUnicodeString m_fromName;
|
||||
ChatUnicodeString m_fromAddress;
|
||||
ChatUnicodeString m_subject;
|
||||
ChatUnicodeString m_folder;
|
||||
ChatUnicodeString m_category;
|
||||
ChatUnicodeString m_msg;
|
||||
ChatUnicodeString m_oob;
|
||||
};
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,28 @@
|
||||
#if !defined (ROOMPARAMSCORE_H_)
|
||||
#define ROOMPARAMSCORE_H_
|
||||
|
||||
#include <Unicode/Unicode.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem {
|
||||
|
||||
|
||||
struct RoomParamsCore
|
||||
{
|
||||
Plat_Unicode::String m_name;
|
||||
ChatUnicodeString m_cName;
|
||||
Plat_Unicode::String m_topic;
|
||||
ChatUnicodeString m_cTopic;
|
||||
Plat_Unicode::String m_password;
|
||||
ChatUnicodeString m_cPassword;
|
||||
|
||||
unsigned m_attributes;
|
||||
unsigned m_size;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#if !defined (ROOMSUMMARYCORE_H_)
|
||||
#define ROOMSUMMARYCORE_H_
|
||||
|
||||
#include <Unicode/Unicode.h>
|
||||
|
||||
#include "ChatEnum.h"
|
||||
|
||||
namespace ChatSystem {
|
||||
|
||||
|
||||
struct RoomSummaryCore
|
||||
{
|
||||
Plat_Unicode::String m_address;
|
||||
Plat_Unicode::String m_topic;
|
||||
|
||||
|
||||
unsigned m_attributes;
|
||||
unsigned m_curSize;
|
||||
unsigned m_maxSize;
|
||||
};
|
||||
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
|
||||
set(SHARED_SOURCES
|
||||
../ChatAPI/AvatarIteratorCore.cpp
|
||||
../ChatAPI/AvatarIteratorCore.h
|
||||
../ChatAPI/AvatarListItem.h
|
||||
../ChatAPI/AvatarListItemCore.cpp
|
||||
../ChatAPI/AvatarListItemCore.h
|
||||
../ChatAPI/ChatAPI.cpp
|
||||
../ChatAPI/ChatAPI.h
|
||||
../ChatAPI/ChatAPICore.cpp
|
||||
../ChatAPI/ChatAPICore.h
|
||||
../ChatAPI/ChatAvatar.cpp
|
||||
../ChatAPI/ChatAvatar.h
|
||||
../ChatAPI/ChatAvatarCore.cpp
|
||||
../ChatAPI/ChatAvatarCore.h
|
||||
../ChatAPI/ChatEnum.cpp
|
||||
../ChatAPI/ChatEnum.h
|
||||
../ChatAPI/ChatFriendStatus.h
|
||||
../ChatAPI/ChatFriendStatusCore.cpp
|
||||
../ChatAPI/ChatFriendStatusCore.h
|
||||
../ChatAPI/ChatIgnoreStatus.h
|
||||
../ChatAPI/ChatIgnoreStatusCore.cpp
|
||||
../ChatAPI/ChatIgnoreStatusCore.h
|
||||
../ChatAPI/ChatRoom.cpp
|
||||
../ChatAPI/ChatRoom.h
|
||||
../ChatAPI/ChatRoomCore.cpp
|
||||
../ChatAPI/ChatRoomCore.h
|
||||
../ChatAPI/Message.cpp
|
||||
../ChatAPI/Message.h
|
||||
../ChatAPI/PersistentMessage.cpp
|
||||
../ChatAPI/PersistentMessage.h
|
||||
../ChatAPI/PersistentMessageCore.h
|
||||
../ChatAPI/Request.cpp
|
||||
../ChatAPI/Request.h
|
||||
../ChatAPI/Response.cpp
|
||||
../ChatAPI/Response.h
|
||||
../ChatAPI/RoomParamsCore.h
|
||||
../ChatAPI/RoomSummaryCore.h
|
||||
|
||||
../../utils/Base/Archive.cpp
|
||||
../../utils/Base/Archive.h
|
||||
../../utils/Base/AutoLog.cpp
|
||||
../../utils/Base/AutoLog.h
|
||||
../../utils/Base/Base.cpp
|
||||
../../utils/Base/Base.h
|
||||
../../utils/Base/Base64.cpp
|
||||
../../utils/Base/Base64.h
|
||||
../../utils/Base/BlockAllocator.h
|
||||
../../utils/Base/ccspanutil.cpp
|
||||
../../utils/Base/ccspanutil.h
|
||||
../../utils/Base/CmdLine.cpp
|
||||
../../utils/Base/CmdLine.h
|
||||
../../utils/Base/Config.cpp
|
||||
../../utils/Base/Config.h
|
||||
../../utils/Base/Event.h
|
||||
../../utils/Base/Logger.cpp
|
||||
../../utils/Base/Logger.h
|
||||
../../utils/Base/MD5.cpp
|
||||
../../utils/Base/MD5.h
|
||||
../../utils/Base/Mutex.h
|
||||
../../utils/Base/Platform.h
|
||||
../../utils/Base/ScopeLock.cpp
|
||||
../../utils/Base/ScopeLock.h
|
||||
../../utils/Base/Statistics.cpp
|
||||
../../utils/Base/Statistics.h
|
||||
../../utils/Base/TemplateBlockAllocator.h
|
||||
../../utils/Base/TemplateObjectAllocator.h
|
||||
../../utils/Base/Thread.h
|
||||
../../utils/Base/Types.h
|
||||
../../utils/Base/WideString.h
|
||||
|
||||
../../utils/UdpLibrary/UdpConnection.cpp
|
||||
../../utils/UdpLibrary/UdpConnection.h
|
||||
../../utils/UdpLibrary/UdpDriver.h
|
||||
../../utils/UdpLibrary/UdpHandler.h
|
||||
../../utils/UdpLibrary/UdpHashTable.h
|
||||
../../utils/UdpLibrary/UdpHelper.h
|
||||
../../utils/UdpLibrary/UdpLibrary.cpp
|
||||
../../utils/UdpLibrary/UdpLibrary.h
|
||||
../../utils/UdpLibrary/UdpLinkedList.h
|
||||
../../utils/UdpLibrary/UdpLogicalPacket.cpp
|
||||
../../utils/UdpLibrary/UdpLogicalPacket.h
|
||||
../../utils/UdpLibrary/UdpManager.cpp
|
||||
../../utils/UdpLibrary/UdpManager.h
|
||||
../../utils/UdpLibrary/UdpMisc.cpp
|
||||
../../utils/UdpLibrary/UdpMisc.h
|
||||
../../utils/UdpLibrary/UdpPriority.h
|
||||
../../utils/UdpLibrary/UdpReliableChannel.cpp
|
||||
../../utils/UdpLibrary/UdpReliablechannel.h
|
||||
../../utils/UdpLibrary/UdpTypes.h
|
||||
|
||||
../../utils/Unicode/FirstUnicode.cpp
|
||||
../../utils/Unicode/FirstUnicode.h
|
||||
../../utils/Unicode/Unicode.cpp
|
||||
../../utils/Unicode/Unicode.h
|
||||
../../utils/Unicode/UnicodeBlocks.cpp
|
||||
../../utils/Unicode/UnicodeBlocks.h
|
||||
../../utils/Unicode/UnicodeCharacterData.cpp
|
||||
../../utils/Unicode/UnicodeCharacterData.h
|
||||
../../utils/Unicode/UnicodeCharacterDataMap.cpp
|
||||
../../utils/Unicode/UnicodeCharacterDataMap.h
|
||||
../../utils/Unicode/UnicodeCharTraits.cpp
|
||||
../../utils/Unicode/UnicodeUtils.cpp
|
||||
../../utils/Unicode/UnicodeUtils.h
|
||||
../../utils/Unicode/utf8.cpp
|
||||
../../utils/Unicode/utf8.h
|
||||
|
||||
../../utils/GenericAPI/GenericApicore.cpp
|
||||
../../utils/GenericAPI/GenericApiCore.h
|
||||
../../utils/GenericAPI/GenericConnection.cpp
|
||||
../../utils/GenericAPI/GenericConnection.h
|
||||
../../utils/GenericAPI/GenericMessage.cpp
|
||||
../../utils/GenericAPI/GenericMessage.h
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
set(PLATFORM_SOURCES
|
||||
../../utils/Base/win32/Archive.h
|
||||
../../utils/Base/win32/BlockAllocator.cpp
|
||||
../../utils/Base/win32/Event.cpp
|
||||
../../utils/Base/win32/Event.h
|
||||
../../utils/Base/win32/Mutex.cpp
|
||||
../../utils/Base/win32/Mutex.h
|
||||
../../utils/Base/win32/Platform.cpp
|
||||
../../utils/Base/win32/Platform.h
|
||||
../../utils/Base/win32/Thread.cpp
|
||||
../../utils/Base/win32/Thread.h
|
||||
../../utils/Base/win32/Types.h
|
||||
|
||||
../../utils/UdpLibrary/UdpDriverWindows.cpp
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../utils/Base/win32)
|
||||
else()
|
||||
set(PLATFORM_SOURCES
|
||||
../../utils/Base/linux/Archive.h
|
||||
../../utils/Base/linux/BlockAllocator.cpp
|
||||
../../utils/Base/linux/Event.cpp
|
||||
../../utils/Base/linux/Event.h
|
||||
../../utils/Base/linux/Mutex.cpp
|
||||
../../utils/Base/linux/Mutex.h
|
||||
../../utils/Base/linux/Platform.cpp
|
||||
../../utils/Base/linux/Platform.h
|
||||
../../utils/Base/linux/Thread.cpp
|
||||
../../utils/Base/linux/Thread.h
|
||||
../../utils/Base/linux/Types.h
|
||||
|
||||
../../utils/UdpLibrary/UdpDriverLinux.cpp
|
||||
)
|
||||
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../utils/Base/linux)
|
||||
endif()
|
||||
|
||||
include_directories()
|
||||
|
||||
add_library(ChatMono
|
||||
${SHARED_SOURCES}
|
||||
${PLATFORM_SOURCES}
|
||||
)
|
||||
@@ -0,0 +1,299 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// The author of this code is Justin Randall
|
||||
//
|
||||
// I have made modifications to the ByteStream
|
||||
// and AutoByteStream classes in order to make them suitable
|
||||
// for use in messaging systems which require objects that
|
||||
// are copyable and assignable. It is also desirable for
|
||||
// the ByteStream object to use a flexible allocator system
|
||||
// that may support multi-threaded programming models.
|
||||
|
||||
|
||||
#include "Archive.h"
|
||||
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
CMutex ByteStreamMutex;
|
||||
#endif
|
||||
|
||||
// Default to Data object reuse
|
||||
bool ByteStream::ms_reuseData = true;
|
||||
|
||||
#if defined (PASCAL_STRING)
|
||||
#pragma message ("--- Packing pascal style strings ---")
|
||||
unsigned get(Base::ByteStream::ReadIterator& source, std::string& target)
|
||||
{
|
||||
unsigned int size = 0;
|
||||
if (source.getSize() < sizeof(size))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
Base::get (source, size);
|
||||
|
||||
const unsigned char *buf = source.getBuffer();
|
||||
|
||||
target.assign((const char *)buf, (const char *)(buf + size));
|
||||
|
||||
const unsigned int readSize = size * sizeof(char);
|
||||
source.advance(readSize);
|
||||
|
||||
return (readSize + sizeof(size));
|
||||
}
|
||||
|
||||
void put(ByteStream& target, const std::string& source)
|
||||
{
|
||||
const unsigned int size = source.size();
|
||||
put(target, size);
|
||||
target.put(source.data(), size * sizeof (char));
|
||||
}
|
||||
|
||||
#else
|
||||
#pragma message ("--- Packing c style strings ---")
|
||||
unsigned get(ByteStream::ReadIterator & source, std::string & target)
|
||||
{
|
||||
target = reinterpret_cast<const char *>(source.getBuffer());
|
||||
|
||||
if (target.length() > source.getSize())
|
||||
return 0;
|
||||
|
||||
source.advance(target.length() + 1);
|
||||
|
||||
return (target.length() + 1);
|
||||
}
|
||||
|
||||
|
||||
void put(ByteStream & target, const std::string & source)
|
||||
{
|
||||
target.put(source.c_str(), source.size()+1);
|
||||
}
|
||||
#endif
|
||||
|
||||
ByteStream::ReadIterator::ReadIterator() :
|
||||
readPtr(0),
|
||||
stream(0)
|
||||
{
|
||||
}
|
||||
|
||||
ByteStream::ReadIterator::ReadIterator(const ReadIterator & source) :
|
||||
readPtr(source.readPtr),
|
||||
stream(source.stream)
|
||||
{
|
||||
}
|
||||
|
||||
ByteStream::ReadIterator::ReadIterator(const ByteStream & source) :
|
||||
readPtr(0),
|
||||
stream(&source)
|
||||
{
|
||||
}
|
||||
|
||||
ByteStream::ReadIterator::~ReadIterator()
|
||||
{
|
||||
stream = 0;
|
||||
}
|
||||
|
||||
ByteStream::ByteStream() :
|
||||
allocatedSize(0),
|
||||
beginReadIterator(),
|
||||
data(NULL),
|
||||
size(0),
|
||||
lastPutSize(0)
|
||||
{
|
||||
data = Data::getNewData();
|
||||
beginReadIterator = ReadIterator(*this);
|
||||
}
|
||||
|
||||
ByteStream::ByteStream(const unsigned char * const newBuffer, const unsigned int bufferSize) :
|
||||
allocatedSize(bufferSize),
|
||||
data(0),
|
||||
size(bufferSize),
|
||||
lastPutSize(0)
|
||||
{
|
||||
data = Data::getNewData();
|
||||
if(data->size < size)
|
||||
{
|
||||
delete[] data->buffer;
|
||||
data->buffer = new unsigned char[size];
|
||||
data->size = size;
|
||||
}
|
||||
memcpy(data->buffer, newBuffer, size);
|
||||
beginReadIterator = ReadIterator(*this);
|
||||
}
|
||||
|
||||
ByteStream::ByteStream(const ByteStream & source):
|
||||
allocatedSize(source.getSize()), // only allocate what is really there, be opportinistic when grow()'ing
|
||||
data(source.data),
|
||||
size(source.getSize()),
|
||||
lastPutSize(source.lastPutSize)
|
||||
{
|
||||
source.data->ref();
|
||||
beginReadIterator = ReadIterator(*this);
|
||||
}
|
||||
|
||||
ByteStream::ByteStream(ReadIterator & source) :
|
||||
allocatedSize(0),
|
||||
size(0),
|
||||
lastPutSize(0)
|
||||
{
|
||||
data = Data::getNewData();
|
||||
put(source.getBuffer(), source.getSize());
|
||||
source.advance(source.getSize());
|
||||
beginReadIterator = ReadIterator(*this);
|
||||
}
|
||||
|
||||
ByteStream::~ByteStream()
|
||||
{
|
||||
data->deref();
|
||||
allocatedSize = 0;
|
||||
data = 0; //lint !e672 (data deref insures the data is deleted if no one references it)
|
||||
size = 0;
|
||||
}
|
||||
|
||||
ByteStream & ByteStream::operator=(const ByteStream & rhs)
|
||||
{
|
||||
if(this != &rhs)
|
||||
{
|
||||
data->deref(); // deref local data
|
||||
rhs.data->ref();
|
||||
allocatedSize = rhs.allocatedSize;
|
||||
size = rhs.size;
|
||||
data = rhs.data; //lint !e672 (data is ref counted)
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
void ByteStream::get(void * target, ReadIterator & readIterator, const unsigned long int targetSize) const
|
||||
{
|
||||
assert(readIterator.getReadPosition() + targetSize <= allocatedSize);
|
||||
memcpy(target, &data->buffer[readIterator.getReadPosition()], targetSize);
|
||||
}
|
||||
|
||||
void ByteStream::put(const void * const source, const unsigned int sourceSize)
|
||||
{
|
||||
if(data->getRef() > 1)
|
||||
{
|
||||
const unsigned char * const tmp = data->buffer;
|
||||
data->deref();
|
||||
data = Data::getNewData();
|
||||
if(data->size < sourceSize)
|
||||
{
|
||||
delete[] data->buffer;
|
||||
data->buffer = new unsigned char[size];
|
||||
data->size = size;
|
||||
}
|
||||
memcpy(data->buffer, tmp, size);
|
||||
allocatedSize = size;
|
||||
}
|
||||
growToAtLeast(size + sourceSize);
|
||||
memcpy(&data->buffer[size], source, sourceSize);
|
||||
size += sourceSize;
|
||||
if (sourceSize > 0)
|
||||
lastPutSize = sourceSize;
|
||||
}
|
||||
|
||||
bool ByteStream::overwriteEnd(const void * const source, const unsigned int sourceSize)
|
||||
{
|
||||
if(data->getRef() <= 1 &&
|
||||
lastPutSize == sourceSize &&
|
||||
sourceSize <= data->size)
|
||||
{
|
||||
memcpy(&data->buffer[size-sourceSize], source, sourceSize);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void ByteStream::reAllocate(const unsigned int newSize)
|
||||
{
|
||||
allocatedSize = newSize;
|
||||
if(data->size < allocatedSize)
|
||||
{
|
||||
unsigned char * tmp = new unsigned char[newSize];
|
||||
if(data->buffer != NULL)
|
||||
memcpy(tmp, data->buffer, size);
|
||||
delete[] data->buffer;
|
||||
data->buffer = tmp;
|
||||
data->size = newSize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
AutoByteStream::AutoByteStream() :
|
||||
members()
|
||||
{
|
||||
}
|
||||
|
||||
AutoByteStream::~AutoByteStream()
|
||||
{
|
||||
}
|
||||
|
||||
void AutoByteStream::addVariable(AutoVariableBase & newVariable)
|
||||
{
|
||||
members.push_back(&newVariable);
|
||||
}
|
||||
|
||||
const unsigned int AutoByteStream::getItemCount() const
|
||||
{
|
||||
return members.size();
|
||||
}
|
||||
|
||||
void AutoByteStream::pack(ByteStream & target) const
|
||||
{
|
||||
std::vector<AutoVariableBase *>::const_iterator i;
|
||||
unsigned short packedSize=static_cast<unsigned short>(members.size());
|
||||
put(target,packedSize);
|
||||
for(i = members.begin(); i != members.end(); ++i)
|
||||
{
|
||||
(*i)->pack(target);
|
||||
}
|
||||
}
|
||||
|
||||
void AutoByteStream::unpack(ByteStream::ReadIterator & source)
|
||||
{
|
||||
std::vector<AutoVariableBase *>::iterator i;
|
||||
unsigned short packedSize;
|
||||
get(source,packedSize);
|
||||
for(i = members.begin(); i != members.end(); ++i)
|
||||
{
|
||||
(*i)->unpack(source);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
AutoVariableBase::AutoVariableBase()
|
||||
{
|
||||
}
|
||||
|
||||
AutoVariableBase::~AutoVariableBase()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,756 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// The author of this code is Justin Randall
|
||||
//
|
||||
// I have made modifications to the ByteStream
|
||||
// and AutoByteStream classes in order to make them suitable
|
||||
// for use in messaging systems which require objects that
|
||||
// are copyable and assignable. It is also desirable for
|
||||
// the ByteStream object to use a flexible allocator system
|
||||
// that may support multi-threaded programming models.
|
||||
|
||||
|
||||
#ifndef BASE_ARCHIVE_H
|
||||
#define BASE_ARCHIVE_H
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "Platform.h"
|
||||
#include "Mutex.h"
|
||||
|
||||
|
||||
#if defined _MT || defined _REENTRANT
|
||||
# define USE_ARCHIVE_MUTEX
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
# include "win32/Archive.h"
|
||||
#elif linux
|
||||
# include "linux/Archive.h"
|
||||
#elif sparc
|
||||
# include "solaris/Archive.h"
|
||||
#else
|
||||
#error /Base/Archive.h: Undefine platform type
|
||||
#endif
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
const unsigned MAX_ARRAY_SIZE = 1024;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
extern CMutex ByteStreamMutex;
|
||||
#endif
|
||||
|
||||
class ByteStream
|
||||
{
|
||||
public:
|
||||
class ReadIterator
|
||||
{
|
||||
public:
|
||||
ReadIterator();
|
||||
ReadIterator(const ReadIterator & source);
|
||||
explicit ReadIterator(const ByteStream & source);
|
||||
~ReadIterator();
|
||||
|
||||
ReadIterator & operator = (const ReadIterator & source);
|
||||
void advance (const unsigned int distance);
|
||||
unsigned get (void * target, const unsigned long int readSize);
|
||||
const unsigned int getSize () const;
|
||||
const unsigned char * const getBuffer () const;
|
||||
const unsigned int getReadPosition () const;
|
||||
|
||||
private:
|
||||
unsigned int readPtr;
|
||||
const ByteStream * stream;
|
||||
};
|
||||
|
||||
private:
|
||||
class Data
|
||||
{
|
||||
friend class ByteStream;
|
||||
friend class ReadIterator;
|
||||
public:
|
||||
~Data();
|
||||
|
||||
static Data * getNewData();
|
||||
|
||||
const int getRef () const;
|
||||
void deref ();
|
||||
void ref ();
|
||||
protected:
|
||||
unsigned char * buffer;
|
||||
unsigned long size;
|
||||
private:
|
||||
struct DataFreeList
|
||||
{
|
||||
~DataFreeList()
|
||||
{
|
||||
std::vector<ByteStream::Data *>::iterator i;
|
||||
for(i = freeList.begin(); i != freeList.end(); ++i)
|
||||
{
|
||||
delete (*i);
|
||||
}
|
||||
};
|
||||
std::vector<Data *> freeList;
|
||||
};
|
||||
Data();
|
||||
//explicit Data(unsigned char * buffer);
|
||||
static std::vector<Data *> & getDataFreeList();
|
||||
static void releaseOldData(Data * oldData);
|
||||
private:
|
||||
int refCount;
|
||||
};
|
||||
|
||||
friend class ReadIterator;
|
||||
public:
|
||||
ByteStream();
|
||||
ByteStream(const unsigned char * const buffer, const unsigned int bufferSize);
|
||||
ByteStream(const ByteStream & source);
|
||||
virtual ~ByteStream();
|
||||
|
||||
public:
|
||||
ByteStream(ReadIterator & source);
|
||||
ByteStream & operator = (const ByteStream & source);
|
||||
ByteStream & operator = (ReadIterator & source);
|
||||
const ReadIterator & begin() const;
|
||||
void clear();
|
||||
const unsigned char * const getBuffer() const;
|
||||
const unsigned int getSize() const;
|
||||
void put(const void * const source, const unsigned int sourceSize);
|
||||
bool overwriteEnd(const void * const source, const unsigned int sourceSize);
|
||||
|
||||
static bool ms_reuseData;
|
||||
|
||||
private:
|
||||
void get(void * target, ReadIterator & readIterator, const unsigned long int readSize) const;
|
||||
void growToAtLeast(const unsigned int targetSize);
|
||||
void reAllocate(const unsigned int newSize);
|
||||
|
||||
private:
|
||||
unsigned int allocatedSize;
|
||||
ReadIterator beginReadIterator;
|
||||
Data * data;
|
||||
unsigned int size;
|
||||
unsigned int lastPutSize;
|
||||
|
||||
};
|
||||
|
||||
inline ByteStream::Data::Data() :
|
||||
buffer(0),
|
||||
size(0),
|
||||
refCount(1)
|
||||
{
|
||||
}
|
||||
|
||||
inline ByteStream::Data::~Data()
|
||||
{
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Lock();
|
||||
#endif
|
||||
|
||||
refCount = 0;
|
||||
delete[] buffer;
|
||||
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void ByteStream::Data::deref()
|
||||
{
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Lock();
|
||||
#endif
|
||||
|
||||
refCount--;
|
||||
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Unlock();
|
||||
#endif
|
||||
|
||||
if(refCount < 1)
|
||||
releaseOldData(this);
|
||||
}
|
||||
|
||||
inline std::vector<ByteStream::Data *> & ByteStream::Data::getDataFreeList()
|
||||
{
|
||||
static DataFreeList freeList;
|
||||
return freeList.freeList;
|
||||
}
|
||||
|
||||
inline ByteStream::Data * ByteStream::Data::getNewData()
|
||||
{
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Lock();
|
||||
#endif
|
||||
|
||||
Data * result = 0;
|
||||
if(getDataFreeList().empty())
|
||||
{
|
||||
result = new Data;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = getDataFreeList().back();
|
||||
getDataFreeList().pop_back();
|
||||
}
|
||||
result->refCount = 1;
|
||||
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Unlock();
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
inline const int ByteStream::Data::getRef() const
|
||||
{
|
||||
return refCount;
|
||||
}
|
||||
|
||||
inline void ByteStream::Data::ref()
|
||||
{
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Lock();
|
||||
#endif
|
||||
|
||||
refCount++;
|
||||
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void ByteStream::Data::releaseOldData(ByteStream::Data * oldData)
|
||||
{
|
||||
if (ByteStream::ms_reuseData)
|
||||
{
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Lock();
|
||||
#endif
|
||||
|
||||
getDataFreeList().push_back(oldData);
|
||||
oldData->refCount = 0;
|
||||
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Unlock();
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
delete oldData;
|
||||
}
|
||||
}
|
||||
|
||||
inline ByteStream::ReadIterator & ByteStream::ReadIterator::operator = (const ByteStream::ReadIterator & rhs)
|
||||
{
|
||||
if(&rhs != this)
|
||||
{
|
||||
readPtr = rhs.readPtr;
|
||||
stream = rhs.stream;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline unsigned ByteStream::ReadIterator::get(void * target, const unsigned long int readSize)
|
||||
{
|
||||
assert(stream);
|
||||
stream->get(target, *this, readSize);
|
||||
readPtr += readSize;
|
||||
return readSize;
|
||||
}
|
||||
|
||||
inline const unsigned int ByteStream::ReadIterator::getSize() const
|
||||
{
|
||||
assert(stream);
|
||||
return stream->getSize() - readPtr;
|
||||
}
|
||||
|
||||
inline const ByteStream::ReadIterator & ByteStream::begin() const
|
||||
{
|
||||
return beginReadIterator;
|
||||
}
|
||||
|
||||
inline void ByteStream::ReadIterator::advance(const unsigned int distance)
|
||||
{
|
||||
readPtr += distance;
|
||||
}
|
||||
|
||||
inline const unsigned int ByteStream::ReadIterator::getReadPosition() const
|
||||
{
|
||||
return readPtr;
|
||||
}
|
||||
|
||||
inline const unsigned char * const ByteStream::ReadIterator::getBuffer() const
|
||||
{
|
||||
if(stream)
|
||||
return &stream->data->buffer[readPtr];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void ByteStream::clear()
|
||||
{
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Lock();
|
||||
#endif
|
||||
|
||||
size = 0;
|
||||
|
||||
#if defined(USE_ARCHIVE_MUTEX)
|
||||
ByteStreamMutex.Unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline const unsigned char * const ByteStream::getBuffer() const
|
||||
{
|
||||
return data->buffer;
|
||||
}
|
||||
|
||||
inline const unsigned int ByteStream::getSize() const
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
inline void ByteStream::growToAtLeast(const unsigned int targetSize)
|
||||
{
|
||||
if(allocatedSize < targetSize)
|
||||
{
|
||||
reAllocate(allocatedSize + allocatedSize + targetSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class AutoVariableBase
|
||||
{
|
||||
public:
|
||||
AutoVariableBase();
|
||||
virtual ~AutoVariableBase();
|
||||
|
||||
virtual void pack(ByteStream & target) const = 0;
|
||||
virtual void unpack(ByteStream::ReadIterator & source) = 0;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class AutoByteStream
|
||||
{
|
||||
public:
|
||||
AutoByteStream();
|
||||
virtual ~AutoByteStream();
|
||||
void addVariable(AutoVariableBase & newVariable);
|
||||
virtual const unsigned int getItemCount() const;
|
||||
virtual void pack(ByteStream & target) const;
|
||||
virtual void unpack(ByteStream::ReadIterator & source);
|
||||
protected:
|
||||
std::vector<AutoVariableBase *> members;
|
||||
private:
|
||||
AutoByteStream(const AutoByteStream & source);
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template<class ValueType>
|
||||
class AutoVariable : public AutoVariableBase
|
||||
{
|
||||
public:
|
||||
AutoVariable();
|
||||
explicit AutoVariable(const ValueType & source);
|
||||
virtual ~AutoVariable();
|
||||
|
||||
const ValueType & get() const;
|
||||
virtual void pack(ByteStream & target) const;
|
||||
void set(const ValueType & rhs);
|
||||
virtual void unpack(ByteStream::ReadIterator & source);
|
||||
|
||||
private:
|
||||
ValueType value;
|
||||
};
|
||||
|
||||
template<class ValueType>
|
||||
AutoVariable<ValueType>::AutoVariable() :
|
||||
AutoVariableBase(),
|
||||
value()
|
||||
{
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
AutoVariable<ValueType>::AutoVariable(const ValueType & source) :
|
||||
AutoVariableBase(),
|
||||
value(source)
|
||||
{
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
AutoVariable<ValueType>::~AutoVariable()
|
||||
{
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
const ValueType & AutoVariable<ValueType>::get() const
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
void AutoVariable<ValueType>::pack(ByteStream & target) const
|
||||
{
|
||||
Base::put(target, value);
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
void AutoVariable<ValueType>::set(const ValueType & rhs)
|
||||
{
|
||||
value = rhs;
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
void AutoVariable<ValueType>::unpack(ByteStream::ReadIterator & source)
|
||||
{
|
||||
Base::get(source, value);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
template<class ValueType>
|
||||
class AutoArray : public AutoVariableBase
|
||||
{
|
||||
public:
|
||||
AutoArray();
|
||||
AutoArray(const AutoArray & source);
|
||||
~AutoArray();
|
||||
|
||||
const std::vector<ValueType> & get() const;
|
||||
void set(const std::vector<ValueType> & source);
|
||||
|
||||
virtual void pack(ByteStream & target) const;
|
||||
virtual void unpack(ByteStream::ReadIterator & source);
|
||||
|
||||
private:
|
||||
std::vector<ValueType> array;
|
||||
};
|
||||
|
||||
template<class ValueType>
|
||||
inline AutoArray<ValueType>::AutoArray()
|
||||
{
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
inline AutoArray<ValueType>::AutoArray(const AutoArray & source) :
|
||||
array(source.array)
|
||||
{
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
inline AutoArray<ValueType>::~AutoArray()
|
||||
{
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
inline const std::vector<ValueType> & AutoArray<ValueType>::get() const
|
||||
{
|
||||
return array;
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
inline void AutoArray<ValueType>::set(const std::vector<ValueType> & source)
|
||||
{
|
||||
array = source;
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
inline void AutoArray<ValueType>::pack(ByteStream & target) const
|
||||
{
|
||||
unsigned int arraySize = array.size();
|
||||
Base::put(target, arraySize);
|
||||
|
||||
typename std::vector<ValueType>::const_iterator i;
|
||||
for(i = array.begin(); i != array.end(); ++i)
|
||||
{
|
||||
ValueType v = (*i);
|
||||
Base::put(target, v);
|
||||
}
|
||||
}
|
||||
|
||||
template<class ValueType>
|
||||
inline void AutoArray<ValueType>::unpack(ByteStream::ReadIterator & source)
|
||||
{
|
||||
unsigned int arraySize;
|
||||
Base::get(source, arraySize);
|
||||
ValueType v;
|
||||
|
||||
if (arraySize > MAX_ARRAY_SIZE)
|
||||
arraySize = 0;
|
||||
|
||||
for(unsigned int i = 0; i < arraySize; ++i)
|
||||
{
|
||||
Base::get(source, v);
|
||||
array.push_back(v);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, ByteStream & target)
|
||||
{
|
||||
target.put(source.getBuffer(), source.getSize());
|
||||
source.advance(source.getSize());
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, double & target)
|
||||
{
|
||||
source.get(&target, 8);
|
||||
target = byteSwap(target);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, float & target)
|
||||
{
|
||||
source.get(&target, 4);
|
||||
target = byteSwap(target);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, uint64 & target)
|
||||
{
|
||||
source.get(&target, 8);
|
||||
target = byteSwap(target);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, int64 & target)
|
||||
{
|
||||
source.get(&target, 8);
|
||||
target = byteSwap(target);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, uint32 & target)
|
||||
{
|
||||
source.get(&target, 4);
|
||||
target = byteSwap(target);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, int32 & target)
|
||||
{
|
||||
source.get(&target, 4);
|
||||
target = byteSwap(target);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, uint16 & target)
|
||||
{
|
||||
source.get(&target, 2);
|
||||
target = byteSwap(target);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, int16 & target)
|
||||
{
|
||||
source.get(&target, 2);
|
||||
target = byteSwap(target);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, uint8 & target)
|
||||
{
|
||||
source.get(&target, 1);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, int8 & target)
|
||||
{
|
||||
source.get(&target, 1);
|
||||
}
|
||||
|
||||
inline unsigned get(ByteStream::ReadIterator & source, unsigned char * const target, const unsigned int targetSize)
|
||||
{
|
||||
return source.get(target, targetSize);
|
||||
}
|
||||
|
||||
inline void get(ByteStream::ReadIterator & source, bool & target)
|
||||
{
|
||||
source.get(&target, 1);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
inline void put(ByteStream & target, ByteStream::ReadIterator & source)
|
||||
{
|
||||
target.put(source.getBuffer(), source.getSize());
|
||||
source.advance(source.getSize());
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const double value)
|
||||
{
|
||||
double temp = byteSwap(value);
|
||||
target.put(&temp, 8);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const float value)
|
||||
{
|
||||
float temp = byteSwap(value);
|
||||
target.put(&temp, 4);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const uint64 value)
|
||||
{
|
||||
uint64 temp = byteSwap(value);
|
||||
target.put(&temp, 8);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const int64 value)
|
||||
{
|
||||
int64 temp = byteSwap(value);
|
||||
target.put(&temp, 8);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const uint32 value)
|
||||
{
|
||||
uint32 temp = byteSwap(value);
|
||||
target.put(&temp, 4);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const int32 value)
|
||||
{
|
||||
int32 temp = byteSwap(value);
|
||||
target.put(&temp, 4);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const uint16 value)
|
||||
{
|
||||
uint16 temp = byteSwap(value);
|
||||
target.put(&temp, 2);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const int16 value)
|
||||
{
|
||||
int16 temp = byteSwap(value);
|
||||
target.put(&temp, 2);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const uint8 value)
|
||||
{
|
||||
target.put(&value, 1);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const int8 value)
|
||||
{
|
||||
target.put(&value, 1);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const bool & source)
|
||||
{
|
||||
target.put(&source, 1);
|
||||
}
|
||||
|
||||
|
||||
inline void put(ByteStream & target, const unsigned char * const source, const unsigned int sourceSize)
|
||||
{
|
||||
target.put(source, sourceSize);
|
||||
}
|
||||
|
||||
inline void put(ByteStream & target, const ByteStream & source)
|
||||
{
|
||||
target.put(source.begin().getBuffer(), source.begin().getSize());
|
||||
}
|
||||
|
||||
unsigned get(ByteStream::ReadIterator & source, std::string & target);
|
||||
void put(ByteStream & target, const std::string & source);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const double value)
|
||||
{
|
||||
double temp = byteSwap(value);
|
||||
return target.overwriteEnd(&temp, 8);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const float value)
|
||||
{
|
||||
float temp = byteSwap(value);
|
||||
return target.overwriteEnd(&temp, 4);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const uint64 value)
|
||||
{
|
||||
uint64 temp = byteSwap(value);
|
||||
return target.overwriteEnd(&temp, 8);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const int64 value)
|
||||
{
|
||||
int64 temp = byteSwap(value);
|
||||
return target.overwriteEnd(&temp, 8);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const uint32 value)
|
||||
{
|
||||
uint32 temp = byteSwap(value);
|
||||
return target.overwriteEnd(&temp, 4);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const int32 value)
|
||||
{
|
||||
int32 temp = byteSwap(value);
|
||||
return target.overwriteEnd(&temp, 4);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const uint16 value)
|
||||
{
|
||||
uint16 temp = byteSwap(value);
|
||||
return target.overwriteEnd(&temp, 2);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const int16 value)
|
||||
{
|
||||
int16 temp = byteSwap(value);
|
||||
return target.overwriteEnd(&temp, 2);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const uint8 value)
|
||||
{
|
||||
return target.overwriteEnd(&value, 1);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const int8 value)
|
||||
{
|
||||
return target.overwriteEnd(&value, 1);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const bool & source)
|
||||
{
|
||||
return target.overwriteEnd(&source, 1);
|
||||
}
|
||||
|
||||
inline bool overwriteEnd(ByteStream & target, const unsigned char * const source, const unsigned int sourceSize)
|
||||
{
|
||||
return target.overwriteEnd(source, sourceSize);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,349 @@
|
||||
#include "AutoLog.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
#ifdef WIN32
|
||||
#include <direct.h> // for NT directory commands
|
||||
#define SLASHCHAR "\\"
|
||||
#define WRONGSLASH '/'
|
||||
#else
|
||||
#define SLASHCHAR "/"
|
||||
#define WRONGSLASH '\\'
|
||||
#endif
|
||||
|
||||
// set default values for global masks
|
||||
CAutoLog::eLogLevel CAutoLog::nLogMask = eLOG_NORMAL; // what is logged in log files
|
||||
CAutoLog::eLogLevel CAutoLog::nPrintMask = eLOG_ERROR; // what is printed on the screen
|
||||
CAutoLog::eLogLevel CAutoLog::nFlushMask = eLOG_ERROR; // when is file flushed on every entry?
|
||||
|
||||
// class info
|
||||
|
||||
//-------------------------------------
|
||||
bool CAutoLog::Open(const char * filename)
|
||||
//-------------------------------------
|
||||
{
|
||||
|
||||
if( NULL == filename)
|
||||
return false;
|
||||
|
||||
if (pFilename)
|
||||
return false;
|
||||
|
||||
pFilename = strdup(filename);
|
||||
|
||||
// Sanitize slashes
|
||||
char *ptr;
|
||||
while ((ptr = strchr(pFilename,WRONGSLASH)) != NULL)
|
||||
*ptr = SLASHCHAR[0];
|
||||
|
||||
char strPath[1024];
|
||||
strcpy(strPath,pFilename);
|
||||
ptr = strrchr(strPath, SLASHCHAR[0]);
|
||||
if (ptr != NULL)
|
||||
{
|
||||
*ptr = 0;
|
||||
|
||||
#ifdef WIN32
|
||||
char curdir[128];
|
||||
|
||||
// remember current directory
|
||||
if( getcwd(curdir,sizeof(curdir)) == NULL )
|
||||
{
|
||||
fprintf(stderr,"CAutoLog::Archive failed to get current directory!\n");
|
||||
free(pFilename);
|
||||
pFilename = NULL;
|
||||
return false; // error, can't proceed
|
||||
}
|
||||
|
||||
if (chdir(strPath))
|
||||
{
|
||||
// failed to find the directory, so we must create it
|
||||
if (mkdir(strPath))
|
||||
{
|
||||
fprintf(stderr,"CAutoLog::Archive failed to make directory: %s\n", strPath);
|
||||
free(pFilename);
|
||||
pFilename = NULL;
|
||||
return false; // error, can't proceed
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// found the directory, but we don't want to be there, so go back
|
||||
chdir(curdir);
|
||||
}
|
||||
#else
|
||||
struct stat SS;
|
||||
|
||||
// see if directory exists
|
||||
if (stat(strPath,&SS))
|
||||
{
|
||||
// create directory
|
||||
if (mkdir(strPath,0777))
|
||||
{
|
||||
fprintf(stderr,"CAutoLog::Archive failed to make directory: %s\n", strPath);
|
||||
free(pFilename);
|
||||
pFilename = NULL;
|
||||
return false; // error, can't proceed
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
pFile = fopen(pFilename,"a+");
|
||||
if( pFile == NULL || pFile == (FILE *)-1)
|
||||
{
|
||||
//fprintf(stderr,"CAutoLog::Open failed to open log file: %s\n",pFilename);
|
||||
Close();
|
||||
return false;
|
||||
}
|
||||
|
||||
time_t t;
|
||||
time(&t);
|
||||
struct tm *ptm = localtime(&t);
|
||||
nTodaysDayOfYear = ptm->tm_yday;
|
||||
|
||||
//printf("Open log file: %s\n",pFilename);
|
||||
return true;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void CAutoLog::Close(void)
|
||||
//-------------------------------------
|
||||
{
|
||||
if( pFile != (FILE *)-1 && pFile != NULL)
|
||||
{
|
||||
fclose(pFile);
|
||||
}
|
||||
pFile = (FILE *)-1;
|
||||
|
||||
if (pFilename)
|
||||
{
|
||||
free(pFilename);
|
||||
}
|
||||
pFilename = NULL;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void CAutoLog::LogError(char * format, ...)
|
||||
{
|
||||
char strInput[1024];
|
||||
|
||||
// parse format and input arguments
|
||||
va_list varg;
|
||||
va_start(varg, format);
|
||||
vsprintf(strInput, format, varg);
|
||||
va_end(varg);
|
||||
|
||||
Log(eLOG_ERROR, strInput);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void CAutoLog::LogAlert(char * format, ...)
|
||||
{
|
||||
char strInput[1024];
|
||||
|
||||
// parse format and input arguments
|
||||
va_list varg;
|
||||
va_start(varg, format);
|
||||
vsprintf(strInput, format, varg);
|
||||
va_end(varg);
|
||||
|
||||
Log(eLOG_ALERT, strInput);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void CAutoLog::Log(char * format, ...)
|
||||
{
|
||||
char strInput[1024];
|
||||
|
||||
// parse format and input arguments
|
||||
va_list varg;
|
||||
va_start(varg, format);
|
||||
vsprintf(strInput, format, varg);
|
||||
va_end(varg);
|
||||
|
||||
Log(eLOG_NORMAL, strInput);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void CAutoLog::LogDebug(char * format, ...)
|
||||
{
|
||||
char strInput[1024];
|
||||
|
||||
// parse format and input arguments
|
||||
va_list varg;
|
||||
va_start(varg, format);
|
||||
vsprintf(strInput, format, varg);
|
||||
va_end(varg);
|
||||
|
||||
Log(eLOG_DEBUG, strInput);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void CAutoLog::Log(eLogLevel severity, char *fmt, ...)
|
||||
//-------------------------------------
|
||||
{
|
||||
if (pFile == (FILE *)-1 || pFile == NULL)
|
||||
{
|
||||
//fprintf(stderr,"CAutoLog::Log called with no file open!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nLogMask == eLOG_NONE || nLogMask < severity)
|
||||
{
|
||||
if (nPrintMask == eLOG_NONE || nPrintMask < severity)
|
||||
{ // no point in parsing, we're doing nothing.
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
char strTime[128];
|
||||
char strInput[1024];
|
||||
char strOutput[1024+128];
|
||||
time_t t;
|
||||
|
||||
// parse format and input arguments
|
||||
va_list varg;
|
||||
va_start(varg, fmt);
|
||||
vsprintf(strInput, fmt, varg);
|
||||
va_end(varg);
|
||||
|
||||
// make timestamp
|
||||
time(&t);
|
||||
strftime(strTime, sizeof(strTime), "[%m/%d/%Y %H:%M:%S]", localtime(&t) );
|
||||
|
||||
// construct output string
|
||||
sprintf(strOutput, "%s %s\n", strTime, strInput);
|
||||
|
||||
// check to see if current file needs to be archived
|
||||
Archive();
|
||||
|
||||
// log to file
|
||||
if (!(nLogMask == eLOG_NONE || nLogMask < severity))
|
||||
{
|
||||
fwrite(strOutput,strlen(strOutput),1,pFile);
|
||||
}
|
||||
|
||||
// print as standard output
|
||||
if (!(nPrintMask == eLOG_NONE || nPrintMask < severity))
|
||||
{
|
||||
printf("%s", strOutput);
|
||||
}
|
||||
|
||||
// flush file buffer if error is high severity
|
||||
if (severity <= nFlushMask)
|
||||
fflush(pFile);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
void CAutoLog::Archive(void)
|
||||
//-------------------------------------
|
||||
{
|
||||
if( pFile == (FILE *)-1 || pFile == NULL)
|
||||
{
|
||||
//fprintf(stderr,"CAutoLog::Archive called with no file open!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// check to see if it's time to archive
|
||||
time_t t;
|
||||
time(&t);
|
||||
struct tm *ptm = localtime(&t);
|
||||
if (ptm->tm_yday == nTodaysDayOfYear)
|
||||
{
|
||||
return; // nope, not time to archive
|
||||
}
|
||||
nTodaysDayOfYear = ptm->tm_yday;
|
||||
|
||||
char strPath[1024];
|
||||
char strCurrent[1024];
|
||||
char strTime[128];
|
||||
char * pCurrent;
|
||||
|
||||
#ifdef WIN32
|
||||
char curdir[128];
|
||||
#else
|
||||
struct stat SS;
|
||||
#endif
|
||||
|
||||
strftime(strTime, sizeof(strTime), "%m%d%Y", localtime(&t) ); // numerical time e.g. 041698
|
||||
|
||||
strcpy(strCurrent,pFilename);
|
||||
pCurrent = strrchr(strCurrent, SLASHCHAR[0]);
|
||||
if (pCurrent != NULL)
|
||||
*pCurrent = 0;
|
||||
else
|
||||
sprintf(strCurrent,".");
|
||||
|
||||
sprintf(strPath,"%s"SLASHCHAR"%s", strCurrent, strTime); // logs/041698
|
||||
|
||||
#ifdef WIN32
|
||||
// remember current directory
|
||||
if( getcwd(curdir,sizeof(curdir)) == NULL )
|
||||
{
|
||||
fprintf(stderr,"CAutoLog::Archive failed to get current directory!\n");
|
||||
return; // error, can't proceed
|
||||
}
|
||||
|
||||
if (chdir(strPath))
|
||||
{
|
||||
// failed to find the directory, so we must create it
|
||||
if (mkdir(strPath))
|
||||
{
|
||||
fprintf(stderr,"CAutoLog::Archive failed to make directory: %s\n", strPath);
|
||||
return; // error, can't proceed
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// found the directory, but we don't want to be there, so go back
|
||||
chdir(curdir);
|
||||
}
|
||||
#else
|
||||
// see if directory exists
|
||||
if (stat(strPath,&SS))
|
||||
{
|
||||
// create directory
|
||||
if (mkdir(strPath,0777))
|
||||
{
|
||||
fprintf(stderr,"CAutoLog::Archive failed to make directory: %s\n", strPath);
|
||||
return; // error, can't proceed
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
pCurrent = strrchr(pFilename, SLASHCHAR[0]);
|
||||
if (pCurrent == NULL)
|
||||
pCurrent = pFilename;
|
||||
else
|
||||
pCurrent++;
|
||||
|
||||
sprintf(strCurrent,"%s"SLASHCHAR"%s",strPath,pCurrent);
|
||||
|
||||
fflush(pFile);
|
||||
fclose(pFile);
|
||||
|
||||
rename(pFilename,strCurrent);
|
||||
|
||||
pFile = fopen(pFilename,"w+");
|
||||
}
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,117 @@
|
||||
#ifndef _AUTOLOG_H
|
||||
#define _AUTOLOG_H
|
||||
|
||||
#pragma warning (disable : 4786)
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
class CAutoLog
|
||||
{
|
||||
public:
|
||||
enum eLogLevel {
|
||||
eLOG_NONE = 0, // log entries are discarded
|
||||
eLOG_ERROR = 1, // log errors only
|
||||
eLOG_ALERT = 2, // log alerts and errors only
|
||||
eLOG_NORMAL = 3, // log all normal events, no debug
|
||||
eLOG_DEBUG = 4 // log everything
|
||||
};
|
||||
|
||||
// Global setting for all AutoLog instances for this application. Can be set on the fly. Default is eLOG_NORMAL.
|
||||
void SetLogLevel(eLogLevel loglevel);
|
||||
|
||||
// Global setting for all AutoLog instances for this application. Can be set on the fly. Default is eLOG_ERROR.
|
||||
void SetPrintLevel(eLogLevel printlevel);
|
||||
|
||||
// Global setting for all AutoLog instances for this application. Can be set on the fly. Default is eLOG_ERROR.
|
||||
void SetFlushLevel(eLogLevel flushlevel);
|
||||
|
||||
// constructor, no file loaded
|
||||
CAutoLog();
|
||||
|
||||
// version of constructor that calls Open(file)
|
||||
CAutoLog(const char * file);
|
||||
|
||||
// destructor, will close file if opened
|
||||
~CAutoLog();
|
||||
|
||||
// Open log file. If a file is already open, function will fail.
|
||||
// returns true if no error
|
||||
bool Open(const char * file);
|
||||
|
||||
// Close log file if opened.
|
||||
void Close(void);
|
||||
|
||||
// Make an entry in the log. Format and variable arguments are identical to printf.
|
||||
// severity will be compared to master log level to determine if the log entry will be made
|
||||
// severity will be compared to master print level to determine if the log entry will be printed to stdout
|
||||
void Log(eLogLevel severity, char * format, ...);
|
||||
|
||||
// Equivalent to the above with the approriate severity argument
|
||||
void LogError(char * format, ...);
|
||||
void LogAlert(char * format, ...);
|
||||
void Log(char * format, ...);
|
||||
void LogDebug(char * format, ...);
|
||||
|
||||
private:
|
||||
FILE * pFile; // current log file opened
|
||||
char * pFilename; // current log file opened
|
||||
int nTodaysDayOfYear; // remember the current day to detect change of day
|
||||
void Archive(void); // archives current log
|
||||
|
||||
static eLogLevel nLogMask; // master severity level
|
||||
static eLogLevel nPrintMask; // master severity level
|
||||
static eLogLevel nFlushMask; // master severity level
|
||||
};
|
||||
|
||||
//-------------------------------------
|
||||
inline void CAutoLog::SetLogLevel(eLogLevel loglevel)
|
||||
{
|
||||
nLogMask = loglevel;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
inline void CAutoLog::SetPrintLevel(eLogLevel printlevel)
|
||||
{
|
||||
nPrintMask = printlevel;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
inline void CAutoLog::SetFlushLevel(eLogLevel flushlevel)
|
||||
{
|
||||
nFlushMask = flushlevel;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
inline CAutoLog::CAutoLog()
|
||||
{
|
||||
pFilename = NULL;
|
||||
pFile = (FILE *)-1;
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
inline CAutoLog::CAutoLog(const char * file)
|
||||
{
|
||||
pFilename = NULL;
|
||||
pFile = (FILE *)-1;
|
||||
Open(file);
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
inline CAutoLog::~CAutoLog()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1 @@
|
||||
#include "Base.h"
|
||||
@@ -0,0 +1,63 @@
|
||||
////////////////////////////////////////
|
||||
// Base.h
|
||||
//
|
||||
// Purpose:
|
||||
// 1. Provide a single header file that may be used to include all
|
||||
// Base library header files.
|
||||
//
|
||||
// Revisions:
|
||||
// 07/10/2001 Created
|
||||
//
|
||||
|
||||
#ifndef _BASEPCH_H
|
||||
#define _BASEPCH_H
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "win32/Platform.h"
|
||||
#include "win32/Types.h"
|
||||
#include "win32/Mutex.h"
|
||||
#include "win32/Event.h"
|
||||
#include "win32/Thread.h"
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include "ScopeLock.h"
|
||||
#include "Statistics.h"
|
||||
#include "TemplateObjectAllocator.h"
|
||||
#include "BlockAllocator.h"
|
||||
|
||||
#elif linux
|
||||
|
||||
#include "linux/Platform.h"
|
||||
#include "linux/Types.h"
|
||||
#include "linux/Mutex.h"
|
||||
#include "linux/Event.h"
|
||||
#include "linux/Thread.h"
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include "ScopeLock.h"
|
||||
#include "Statistics.h"
|
||||
#include "TemplateObjectAllocator.h"
|
||||
#include "BlockAllocator.h"
|
||||
|
||||
#elif sparc
|
||||
|
||||
#include "solaris/Platform.h"
|
||||
#include "solaris/Types.h"
|
||||
#include "solaris/Mutex.h"
|
||||
#include "solaris/Event.h"
|
||||
#include "solaris/Thread.h"
|
||||
#include "Logger.h"
|
||||
#include "Config.h"
|
||||
#include "ScopeLock.h"
|
||||
#include "Statistics.h"
|
||||
#include "TemplateObjectAllocator.h"
|
||||
#include "BlockAllocator.h"
|
||||
|
||||
#else
|
||||
|
||||
#error Base.h: Undefine platform type
|
||||
|
||||
#endif
|
||||
|
||||
#endif // _BASEPCH_H
|
||||
@@ -0,0 +1,387 @@
|
||||
#include "Base64.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Constants
|
||||
//----------------------------------------------------------------------------
|
||||
#define BASE64_PAD '='
|
||||
#define BASE64_PAD_INDEX 64
|
||||
#define BASE64_ERR ((unsigned char)-1)
|
||||
#define BASE64_PAD_CODE ((unsigned char)100)
|
||||
#define BASE64_OUTPUT_LINE 76
|
||||
#define BASE64_ENCODE_BUFFER ((BASE64_OUTPUT_LINE*3)/4)
|
||||
#define BASE64_DECODE_ERROR ((unsigned)-1)
|
||||
|
||||
#define HEX_ERR 16
|
||||
#define HEX_LOWER_FORMAT "%2.2x"
|
||||
#define HEX_UPPER_FORMAT "%2.2X";
|
||||
|
||||
const char Base64::ms_base64Table[] =
|
||||
{
|
||||
'A',
|
||||
'B',
|
||||
'C',
|
||||
'D',
|
||||
'E',
|
||||
'F',
|
||||
'G',
|
||||
'H',
|
||||
'I',
|
||||
'J',
|
||||
'K',
|
||||
'L',
|
||||
'M',
|
||||
'N',
|
||||
'O',
|
||||
'P',
|
||||
'Q',
|
||||
'R',
|
||||
'S',
|
||||
'T',
|
||||
'U',
|
||||
'V',
|
||||
'W',
|
||||
'X',
|
||||
'Y',
|
||||
'Z',
|
||||
'a',
|
||||
'b',
|
||||
'c',
|
||||
'd',
|
||||
'e',
|
||||
'f',
|
||||
'g',
|
||||
'h',
|
||||
'i',
|
||||
'j',
|
||||
'k',
|
||||
'l',
|
||||
'm',
|
||||
'n',
|
||||
'o',
|
||||
'p',
|
||||
'q',
|
||||
'r',
|
||||
's',
|
||||
't',
|
||||
'u',
|
||||
'v',
|
||||
'w',
|
||||
'x',
|
||||
'y',
|
||||
'z',
|
||||
'0',
|
||||
'1',
|
||||
'2',
|
||||
'3',
|
||||
'4',
|
||||
'5',
|
||||
'6',
|
||||
'7',
|
||||
'8',
|
||||
'9',
|
||||
'+',
|
||||
'/',
|
||||
BASE64_PAD
|
||||
};
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Functions
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
unsigned char Base64::GetBase64Code(char base64char)
|
||||
{
|
||||
if (base64char == BASE64_PAD)
|
||||
return BASE64_PAD_CODE;
|
||||
|
||||
if (base64char >= 'A' && base64char <= 'Z')
|
||||
return (unsigned char)(base64char - 'A');
|
||||
if (base64char >= 'a' && base64char <= 'z')
|
||||
return (unsigned char)(base64char - 'a' + 26);
|
||||
if (base64char >= '0' && base64char <= '9')
|
||||
return (unsigned char)(base64char - '0' + 2*26);
|
||||
if (base64char == '+')
|
||||
return 2*26+10;
|
||||
if (base64char == '/')
|
||||
return 2*26+11;
|
||||
|
||||
return BASE64_ERR;
|
||||
}
|
||||
|
||||
unsigned char Base64::GetHexCode(char hexChar)
|
||||
{
|
||||
if (hexChar >= '0' && hexChar <= '9')
|
||||
return (unsigned char)(hexChar - '0');
|
||||
if (hexChar >= 'A' && hexChar <= 'F')
|
||||
return (unsigned char)(hexChar - 'A' + 10);
|
||||
if (hexChar >= 'a' && hexChar <= 'f')
|
||||
return (unsigned char)(hexChar - 'a' + 10);
|
||||
|
||||
return HEX_ERR;
|
||||
}
|
||||
|
||||
unsigned Base64::UUDecodeQuadToTriple(const char *quad, unsigned char *triple)
|
||||
{
|
||||
unsigned char b;
|
||||
unsigned char quadByteCodes[4];
|
||||
unsigned bytes = 3, i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
b = GetBase64Code(quad[i]);
|
||||
|
||||
if (b == BASE64_PAD_CODE)
|
||||
{
|
||||
switch(i)
|
||||
{
|
||||
case 0: bytes=0; break;
|
||||
case 1: bytes=0; break;
|
||||
case 2: bytes=1; break;
|
||||
case 3: bytes=2; break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if (b == BASE64_ERR)
|
||||
{
|
||||
bytes = BASE64_DECODE_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
quadByteCodes[i] = b;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
triple[0] = (quadByteCodes[0] << 2) | (quadByteCodes[1] >> 4);
|
||||
triple[1] = (quadByteCodes[1] << 4) | (quadByteCodes[2] >> 2);
|
||||
triple[2] = (quadByteCodes[2] << 6) | (quadByteCodes[3] >> 0);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
bool Base64::UUDecode(const char *source, unsigned sourceLen, unsigned char *dest, unsigned *destLen)
|
||||
{
|
||||
unsigned char q[3];
|
||||
unsigned index;
|
||||
unsigned bytes;
|
||||
unsigned char *destIn = dest;
|
||||
bool noErrors = true;
|
||||
|
||||
for (index = 0; index < sourceLen; index += 4)
|
||||
{
|
||||
bytes = UUDecodeQuadToTriple(source + index, q);
|
||||
|
||||
if (bytes != BASE64_DECODE_ERROR) {
|
||||
*destLen -= bytes;
|
||||
if (*destLen >= 0) {
|
||||
memcpy(dest, (char*)&q, bytes);
|
||||
} else {
|
||||
noErrors = false;
|
||||
}
|
||||
dest += bytes;
|
||||
} else {
|
||||
noErrors = false;
|
||||
}
|
||||
}
|
||||
*destLen = (int)(dest - destIn);
|
||||
|
||||
return noErrors;
|
||||
}
|
||||
|
||||
bool Base64::UUDecode(const char *source, unsigned sourceLen, std::string &destString)
|
||||
{
|
||||
unsigned char q[3];
|
||||
unsigned index;
|
||||
unsigned bytes;
|
||||
bool noErrors = true;
|
||||
|
||||
for (index = 0; index < sourceLen; index += 4)
|
||||
{
|
||||
bytes = UUDecodeQuadToTriple(source + index, q);
|
||||
|
||||
if (bytes != BASE64_DECODE_ERROR) {
|
||||
destString.append((char*)&q, bytes);
|
||||
} else {
|
||||
noErrors = false;
|
||||
}
|
||||
}
|
||||
|
||||
return noErrors;
|
||||
}
|
||||
|
||||
unsigned Base64::UUEncodeTripleToQuad(const unsigned char *triple, char* quad, unsigned bytes)
|
||||
{
|
||||
unsigned char indices[4];
|
||||
int quadIndex;
|
||||
|
||||
memset(indices, BASE64_PAD_INDEX, sizeof(indices));
|
||||
|
||||
switch(bytes)
|
||||
{
|
||||
case 3:
|
||||
indices[3] = (triple[2] ) & 0x0000003F;
|
||||
indices[2] = (triple[2] >> 6) & 0x0000003F;
|
||||
case 2:
|
||||
indices[2] = (indices[2] | (triple[1] << 2)) & 0x0000003F;
|
||||
indices[1] = (triple[1] >> 4) & 0x0000003F;
|
||||
case 1:
|
||||
indices[1] = (indices[1] | (triple[0] << 4)) & 0x0000003F;
|
||||
indices[0] = (triple[0] >> 2) & 0x0000003F;
|
||||
case 0:
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
for (quadIndex = 0; quadIndex < 4; quadIndex++) {
|
||||
quad[quadIndex] = ms_base64Table[indices[quadIndex]];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Base64::UUEncode(const unsigned char *source, unsigned sourceLen, char *dest, unsigned destLen)
|
||||
{
|
||||
char quad[5];
|
||||
unsigned z;
|
||||
bool noErrors = true;
|
||||
|
||||
quad[4] = 0;
|
||||
|
||||
// The normal case
|
||||
for(z = 0; z < sourceLen;z += 3)
|
||||
{
|
||||
UUEncodeTripleToQuad(source + z,quad,(z + 3 < sourceLen) ? 3 : (sourceLen - z));
|
||||
destLen -= strlen(quad);
|
||||
if (destLen > 0) {
|
||||
dest += sprintf(dest,quad);
|
||||
} else {
|
||||
noErrors = false;
|
||||
}
|
||||
}
|
||||
|
||||
return noErrors;
|
||||
}
|
||||
|
||||
bool Base64::UUEncode(const unsigned char *source, unsigned sourceLen, std::string &destString)
|
||||
{
|
||||
char quad[5];
|
||||
unsigned z;
|
||||
bool noErrors = true;
|
||||
|
||||
quad[4] = 0;
|
||||
|
||||
// The normal case
|
||||
for(z = 0; z < sourceLen;z += 3)
|
||||
{
|
||||
UUEncodeTripleToQuad(source + z,quad,(z + 3 < sourceLen) ? 3 : (sourceLen - z));
|
||||
|
||||
destString.append(quad);
|
||||
}
|
||||
|
||||
return noErrors;
|
||||
}
|
||||
|
||||
bool Base64::HexEncode(const unsigned char *source, unsigned sourceLen, char *dest, unsigned destLen, bool lowercase)
|
||||
{
|
||||
const char *format = lowercase ? HEX_LOWER_FORMAT : HEX_UPPER_FORMAT;
|
||||
bool noErrors = true;
|
||||
|
||||
for (; sourceLen > 0; sourceLen--, source++)
|
||||
{
|
||||
if (destLen >= 2) {
|
||||
destLen -= sprintf(dest, format, *source);
|
||||
} else {
|
||||
noErrors = false;
|
||||
}
|
||||
}
|
||||
|
||||
return noErrors;
|
||||
}
|
||||
|
||||
bool Base64::HexEncode(const unsigned char *source, unsigned sourceLen, std::string &destString, bool lowercase)
|
||||
{
|
||||
const char *format = lowercase ? HEX_LOWER_FORMAT : HEX_UPPER_FORMAT;
|
||||
char hexBuffer[3];
|
||||
bool noErrors = true;
|
||||
|
||||
hexBuffer[2] = '\0';
|
||||
|
||||
for (; sourceLen > 0; sourceLen--, source++)
|
||||
{
|
||||
hexBuffer[0] = '\0';
|
||||
sprintf(hexBuffer, format, *source);
|
||||
destString.append(hexBuffer);
|
||||
}
|
||||
|
||||
return noErrors;
|
||||
}
|
||||
|
||||
bool Base64::HexDecode(const char *source, unsigned sourceLen, unsigned char *dest, unsigned *destLen)
|
||||
{
|
||||
unsigned char *destIn = dest;
|
||||
unsigned char digits[2];
|
||||
bool noErrors = true;
|
||||
|
||||
for (; sourceLen > 1; sourceLen -= 2, source += 2)
|
||||
{
|
||||
if (*destLen > 0) {
|
||||
digits[0] = GetHexCode(source[0]);
|
||||
digits[1] = GetHexCode(source[1]);
|
||||
if ((digits[0] != HEX_ERR) && (digits[1] != HEX_ERR)) {
|
||||
*dest = (digits[0] * 16) + digits[1];
|
||||
dest++;
|
||||
(*destLen)--;
|
||||
} else {
|
||||
noErrors = false;
|
||||
}
|
||||
} else {
|
||||
noErrors = false;
|
||||
}
|
||||
}
|
||||
*destLen = dest - destIn;
|
||||
|
||||
if (sourceLen == 1) {
|
||||
noErrors = false;
|
||||
}
|
||||
|
||||
return noErrors;
|
||||
}
|
||||
|
||||
bool Base64::HexDecode(const char *source, unsigned sourceLen, std::string &destString)
|
||||
{
|
||||
unsigned char digits[2];
|
||||
unsigned char byte;
|
||||
bool noErrors = true;
|
||||
|
||||
for (; sourceLen > 1; sourceLen -= 2, source += 2)
|
||||
{
|
||||
digits[0] = GetHexCode(source[0]);
|
||||
digits[1] = GetHexCode(source[1]);
|
||||
if ((digits[0] != HEX_ERR) && (digits[1] != HEX_ERR)) {
|
||||
byte = (digits[0] * 16) + digits[1];
|
||||
destString.append((char *)&byte, 1);
|
||||
} else {
|
||||
noErrors = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceLen == 1) {
|
||||
noErrors = false;
|
||||
}
|
||||
|
||||
return noErrors;
|
||||
}
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
#ifndef BASE64_H
|
||||
#define BASE64_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
class Base64
|
||||
{
|
||||
public:
|
||||
static bool UUEncode(const unsigned char *source, unsigned sourceLen, char *dest, unsigned destLen);
|
||||
static bool UUEncode(const unsigned char *source, unsigned sourceLen, std::string &destString);
|
||||
static bool UUDecode(const char *source, unsigned sourceLen, unsigned char *dest, unsigned *destLen);
|
||||
static bool UUDecode(const char *source, unsigned sourceLen, std::string &destString);
|
||||
|
||||
// these don't *exactly* belong here, but it's a convenient place for them
|
||||
static bool HexEncode(const unsigned char *source, unsigned sourceLen, char *dest, unsigned destLen, bool lowercase = false);
|
||||
static bool HexEncode(const unsigned char *source, unsigned sourceLen, std::string &destString, bool lowercase = false);
|
||||
static bool HexDecode(const char *source, unsigned sourceLen, unsigned char *dest, unsigned *destLen);
|
||||
static bool HexDecode(const char *source, unsigned sourceLen, std::string &destString);
|
||||
|
||||
private:
|
||||
static unsigned UUEncodeTripleToQuad(const unsigned char *triple, char *quad, unsigned bytes);
|
||||
static unsigned UUDecodeQuadToTriple(const char *quad, unsigned char *triple);
|
||||
|
||||
static void Init();
|
||||
static unsigned char GetBase64Code(char base64char);
|
||||
static unsigned char GetHexCode(char hexChar);
|
||||
|
||||
static const char ms_base64Table[];
|
||||
};
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // BASE64_H
|
||||
@@ -0,0 +1,30 @@
|
||||
#if !defined (BLOCKALLOCATOR_H_)
|
||||
#define BLOCKALLOCATOR_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
class BlockAllocator
|
||||
{
|
||||
public:
|
||||
BlockAllocator();
|
||||
~BlockAllocator();
|
||||
void *getBlock(unsigned accum);
|
||||
void returnBlock(unsigned *handle);
|
||||
|
||||
private:
|
||||
unsigned *m_blocks[31];
|
||||
};
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,291 @@
|
||||
/*------------------------------------------------------
|
||||
CCmdLine
|
||||
|
||||
A utility for parsing command lines.
|
||||
|
||||
Copyright (C) 1999 Chris Losinger, Smaller Animals Software.
|
||||
http://www.smalleranimals.com
|
||||
|
||||
This software is provided 'as-is', without any express
|
||||
or implied warranty. In no event will the authors be
|
||||
held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software
|
||||
for any purpose, including commercial applications, and
|
||||
to alter it and redistribute it freely, subject to the
|
||||
following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented;
|
||||
you must not claim that you wrote the original software.
|
||||
If you use this software in a product, an acknowledgment
|
||||
in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such,
|
||||
and must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
See SACmds.h for more info.
|
||||
------------------------------------------------------*/
|
||||
|
||||
#pragma warning (disable: 4267)
|
||||
// if you're using MFC, you'll need to un-comment this line
|
||||
// #include "stdafx.h"
|
||||
|
||||
#include "CmdLine.h"
|
||||
//#include "crtdbg.h"
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
#endif
|
||||
|
||||
namespace Base
|
||||
{
|
||||
|
||||
/*------------------------------------------------------
|
||||
int CCmdLine::SplitLine(int argc, char **argv)
|
||||
|
||||
parse the command line into switches and arguments
|
||||
|
||||
returns number of switches found
|
||||
------------------------------------------------------*/
|
||||
int CCmdLine::SplitLine(int argc, char **argv)
|
||||
{
|
||||
clear();
|
||||
|
||||
StringType curParam; // current argv[x]
|
||||
|
||||
// skip the exe name (start with i = 1)
|
||||
for (int i = 1; i < argc; i++)
|
||||
{
|
||||
// if it's a switch, start a new CCmdLine
|
||||
if (IsSwitch(argv[i]))
|
||||
{
|
||||
curParam = argv[i];
|
||||
|
||||
StringType arg;
|
||||
|
||||
// look at next input string to see if it's a switch or an argument
|
||||
if (i + 1 < argc)
|
||||
{
|
||||
if (!IsSwitch(argv[i + 1]))
|
||||
{
|
||||
// it's an argument, not a switch
|
||||
arg = argv[i + 1];
|
||||
|
||||
// skip to next
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
arg = "";
|
||||
}
|
||||
}
|
||||
|
||||
// add it
|
||||
CCmdParam cmd;
|
||||
|
||||
// only add non-empty args
|
||||
if (arg != "")
|
||||
{
|
||||
cmd.m_strings.push_back(arg);
|
||||
}
|
||||
|
||||
// add the CCmdParam to 'this'
|
||||
std::pair<CCmdLine::iterator, bool> res = insert(CCmdLine::value_type(curParam, cmd));
|
||||
if (res.second) continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
// it's not a new switch, so it must be more stuff for the last switch
|
||||
|
||||
// ...let's add it
|
||||
CCmdLine::iterator theIterator;
|
||||
|
||||
// get an iterator for the current param
|
||||
theIterator = find(curParam);
|
||||
if (theIterator!=end())
|
||||
{
|
||||
(*theIterator).second.m_strings.push_back(argv[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// ??
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return size();
|
||||
}
|
||||
|
||||
/*------------------------------------------------------
|
||||
|
||||
protected member function
|
||||
test a parameter to see if it's a switch :
|
||||
|
||||
switches are of the form : -x
|
||||
where 'x' is one or more characters.
|
||||
the first character of a switch must be non-numeric!
|
||||
|
||||
------------------------------------------------------*/
|
||||
|
||||
bool CCmdLine::IsSwitch(const char *pParam)
|
||||
{
|
||||
if (pParam==NULL)
|
||||
return false;
|
||||
|
||||
// switches must non-empty
|
||||
// must have at least one character after the '-'
|
||||
int len = strlen(pParam);
|
||||
if (len <= 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// switches always start with '-'
|
||||
if (pParam[0]=='-')
|
||||
{
|
||||
// allow negative numbers as arguments.
|
||||
// ie., don't count them as switches
|
||||
return (!isdigit(pParam[1]));
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------
|
||||
bool CCmdLine::HasSwitch(const char *pSwitch)
|
||||
|
||||
was the switch found on the command line ?
|
||||
|
||||
ex. if the command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
|
||||
|
||||
call return
|
||||
---- ------
|
||||
cmdLine.HasSwitch("-a") true
|
||||
cmdLine.HasSwitch("-z") false
|
||||
------------------------------------------------------*/
|
||||
|
||||
bool CCmdLine::HasSwitch(const char *pSwitch)
|
||||
{
|
||||
CCmdLine::iterator theIterator;
|
||||
theIterator = find(pSwitch);
|
||||
return (theIterator!=end());
|
||||
}
|
||||
|
||||
/*------------------------------------------------------
|
||||
|
||||
StringType CCmdLine::GetSafeArgument(const char *pSwitch, int iIdx, const char *pDefault)
|
||||
|
||||
fetch an argument associated with a switch . if the parameter at
|
||||
index iIdx is not found, this will return the default that you
|
||||
provide.
|
||||
|
||||
example :
|
||||
|
||||
command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
|
||||
|
||||
call return
|
||||
---- ------
|
||||
cmdLine.GetSafeArgument("-a", 0, "zz") p1
|
||||
cmdLine.GetSafeArgument("-a", 1, "zz") p2
|
||||
cmdLine.GetSafeArgument("-b", 0, "zz") p4
|
||||
cmdLine.GetSafeArgument("-b", 1, "zz") zz
|
||||
|
||||
------------------------------------------------------*/
|
||||
|
||||
StringType CCmdLine::GetSafeArgument(const char *pSwitch, int iIdx, const char *pDefault)
|
||||
{
|
||||
StringType sRet;
|
||||
|
||||
if (pDefault!=NULL)
|
||||
sRet = pDefault;
|
||||
|
||||
try
|
||||
{
|
||||
sRet = GetArgument(pSwitch, iIdx);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
return sRet;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------
|
||||
|
||||
StringType CCmdLine::GetArgument(const char *pSwitch, int iIdx)
|
||||
|
||||
fetch a argument associated with a switch. throws an exception
|
||||
of (int)0, if the parameter at index iIdx is not found.
|
||||
|
||||
example :
|
||||
|
||||
command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
|
||||
|
||||
call return
|
||||
---- ------
|
||||
cmdLine.GetArgument("-a", 0) p1
|
||||
cmdLine.GetArgument("-b", 1) throws (int)0, returns an empty string
|
||||
|
||||
------------------------------------------------------*/
|
||||
|
||||
StringType CCmdLine::GetArgument(const char *pSwitch, int iIdx)
|
||||
{
|
||||
if (HasSwitch(pSwitch))
|
||||
{
|
||||
CCmdLine::iterator theIterator;
|
||||
|
||||
theIterator = find(pSwitch);
|
||||
if (theIterator!=end())
|
||||
{
|
||||
if ((int)(*theIterator).second.m_strings.size() > iIdx)
|
||||
{
|
||||
return (*theIterator).second.m_strings[iIdx];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
throw (int)0;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/*------------------------------------------------------
|
||||
int CCmdLine::GetArgumentCount(const char *pSwitch)
|
||||
|
||||
returns the number of arguments found for a given switch.
|
||||
|
||||
returns -1 if the switch was not found
|
||||
|
||||
------------------------------------------------------*/
|
||||
|
||||
int CCmdLine::GetArgumentCount(const char *pSwitch)
|
||||
{
|
||||
int iArgumentCount = -1;
|
||||
|
||||
if (HasSwitch(pSwitch))
|
||||
{
|
||||
CCmdLine::iterator theIterator;
|
||||
|
||||
theIterator = find(pSwitch);
|
||||
if (theIterator!=end())
|
||||
{
|
||||
iArgumentCount = (*theIterator).second.m_strings.size();
|
||||
}
|
||||
}
|
||||
|
||||
return iArgumentCount;
|
||||
}
|
||||
|
||||
}; // end namespace Base
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
}; // end namespace NAMESPACE
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,251 @@
|
||||
/*------------------------------------------------------
|
||||
CCmdLine
|
||||
|
||||
A utility for parsing command lines.
|
||||
|
||||
Copyright (C) 1999 Chris Losinger, Smaller Animals Software.
|
||||
http://www.smalleranimals.com
|
||||
|
||||
This software is provided 'as-is', without any express
|
||||
or implied warranty. In no event will the authors be
|
||||
held liable for any damages arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software
|
||||
for any purpose, including commercial applications, and
|
||||
to alter it and redistribute it freely, subject to the
|
||||
following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented;
|
||||
you must not claim that you wrote the original software.
|
||||
If you use this software in a product, an acknowledgment
|
||||
in the product documentation would be appreciated but is not required.
|
||||
|
||||
2. Altered source versions must be plainly marked as such,
|
||||
and must not be misrepresented as being the original software.
|
||||
|
||||
3. This notice may not be removed or altered from any source
|
||||
distribution.
|
||||
|
||||
-------------------------
|
||||
|
||||
Example :
|
||||
|
||||
Our example application uses a command line that has two
|
||||
required switches and two optional switches. The app should abort
|
||||
if the required switches are not present and continue with default
|
||||
values if the optional switches are not present.
|
||||
|
||||
Sample command line :
|
||||
MyApp.exe -p1 text1 text2 -p2 "this is a big argument" -opt1 -55 -opt2
|
||||
|
||||
Switches -p1 and -p2 are required.
|
||||
p1 has two arguments and p2 has one.
|
||||
|
||||
Switches -opt1 and -opt2 are optional.
|
||||
opt1 requires a numeric argument.
|
||||
opt2 has no arguments.
|
||||
|
||||
Also, assume that the app displays a 'help' screen if the '-h' switch
|
||||
is present on the command line.
|
||||
|
||||
#include "CmdLine.h"
|
||||
|
||||
void main(int argc, char **argv)
|
||||
{
|
||||
// our cmd line parser object
|
||||
CCmdLine cmdLine;
|
||||
|
||||
// parse argc,argv
|
||||
if (cmdLine.SplitLine(argc, argv) < 1)
|
||||
{
|
||||
// no switches were given on the command line, abort
|
||||
ASSERT(0);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// test for the 'help' case
|
||||
if (cmdLine.HasSwitch("-h"))
|
||||
{
|
||||
show_help();
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// get the required arguments
|
||||
StringType p1_1, p1_2, p2_1;
|
||||
try
|
||||
{
|
||||
// if any of these fail, we'll end up in the catch() block
|
||||
p1_1 = cmdLine.GetArgument("-p1", 0);
|
||||
p1_2 = cmdLine.GetArgument("-p1", 1);
|
||||
p2_1 = cmdLine.GetArgument("-p2", 0);
|
||||
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// one of the required arguments was missing, abort
|
||||
ASSERT(0);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
// get the optional parameters
|
||||
|
||||
// convert to an int, default to '100'
|
||||
int iOpt1Val = atoi(cmdLine.GetSafeArgument("-opt1", 0, 100));
|
||||
|
||||
// since opt2 has no arguments, just test for the presence of
|
||||
// the '-opt2' switch
|
||||
bool bOptVal2 = cmdLine.HasSwitch("-opt2");
|
||||
|
||||
.... and so on....
|
||||
|
||||
}
|
||||
|
||||
If this class is used in an MFC application, StringType is CString, else
|
||||
it uses the STL 'string' type.
|
||||
|
||||
If this is an MFC app, you can use the __argc and __argv macros from
|
||||
you CYourWinApp::InitInstance() function in place of the standard argc
|
||||
and argv variables.
|
||||
|
||||
------------------------------------------------------*/
|
||||
#ifndef SACMDSH
|
||||
#define SACMDSH
|
||||
|
||||
|
||||
//#include <iostream> // you may need this
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
//using namespace std ;
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
#endif
|
||||
|
||||
namespace Base
|
||||
{
|
||||
|
||||
#ifdef __AFX_H__
|
||||
// if we're using MFC, use CStrings
|
||||
#define StringType CString
|
||||
#else
|
||||
// if we're not using MFC, use STL strings
|
||||
#define StringType std::string
|
||||
#endif
|
||||
|
||||
// tell the compiler to shut up
|
||||
#pragma warning(disable:4786)
|
||||
|
||||
|
||||
// handy little container for our argument vector
|
||||
struct CCmdParam
|
||||
{
|
||||
std::vector<StringType> m_strings;
|
||||
};
|
||||
|
||||
// this class is actually a map of strings to vectors
|
||||
typedef std::map<StringType, CCmdParam> _CCmdLine;
|
||||
|
||||
// the command line parser class
|
||||
class CCmdLine : public _CCmdLine
|
||||
{
|
||||
|
||||
public:
|
||||
/*------------------------------------------------------
|
||||
int CCmdLine::SplitLine(int argc, char **argv)
|
||||
|
||||
parse the command line into switches and arguments.
|
||||
|
||||
returns number of switches found
|
||||
------------------------------------------------------*/
|
||||
int SplitLine(int argc, char **argv);
|
||||
|
||||
/*------------------------------------------------------
|
||||
bool CCmdLine::HasSwitch(const char *pSwitch)
|
||||
|
||||
was the switch found on the command line ?
|
||||
|
||||
ex. if the command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
|
||||
|
||||
call return
|
||||
---- ------
|
||||
cmdLine.HasSwitch("-a") true
|
||||
cmdLine.HasSwitch("-z") false
|
||||
------------------------------------------------------*/
|
||||
bool HasSwitch(const char *pSwitch);
|
||||
|
||||
/*------------------------------------------------------
|
||||
|
||||
StringType CCmdLine::GetSafeArgument(const char *pSwitch, int iIdx, const char *pDefault)
|
||||
|
||||
fetch an argument associated with a switch . if the parameter at
|
||||
index iIdx is not found, this will return the default that you
|
||||
provide.
|
||||
|
||||
example :
|
||||
|
||||
command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
|
||||
|
||||
call return
|
||||
---- ------
|
||||
cmdLine.GetSafeArgument("-a", 0, "zz") p1
|
||||
cmdLine.GetSafeArgument("-a", 1, "zz") p2
|
||||
cmdLine.GetSafeArgument("-b", 0, "zz") p4
|
||||
cmdLine.GetSafeArgument("-b", 1, "zz") zz
|
||||
|
||||
------------------------------------------------------*/
|
||||
|
||||
StringType GetSafeArgument(const char *pSwitch, int iIdx, const char *pDefault);
|
||||
|
||||
/*------------------------------------------------------
|
||||
|
||||
StringType CCmdLine::GetArgument(const char *pSwitch, int iIdx)
|
||||
|
||||
fetch a argument associated with a switch. throws an exception
|
||||
of (int)0, if the parameter at index iIdx is not found.
|
||||
|
||||
example :
|
||||
|
||||
command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
|
||||
|
||||
call return
|
||||
---- ------
|
||||
cmdLine.GetArgument("-a", 0) p1
|
||||
cmdLine.GetArgument("-b", 1) throws (int)0, returns an empty string
|
||||
|
||||
------------------------------------------------------*/
|
||||
StringType GetArgument(const char *pSwitch, int iIdx);
|
||||
|
||||
/*------------------------------------------------------
|
||||
int CCmdLine::GetArgumentCount(const char *pSwitch)
|
||||
|
||||
returns the number of arguments found for a given switch.
|
||||
|
||||
returns -1 if the switch was not found
|
||||
|
||||
------------------------------------------------------*/
|
||||
int GetArgumentCount(const char *pSwitch);
|
||||
|
||||
protected:
|
||||
/*------------------------------------------------------
|
||||
|
||||
protected member function
|
||||
test a parameter to see if it's a switch :
|
||||
|
||||
switches are of the form : -x
|
||||
where 'x' is one or more characters.
|
||||
the first character of a switch must be non-numeric!
|
||||
|
||||
------------------------------------------------------*/
|
||||
bool IsSwitch(const char *pParam);
|
||||
};
|
||||
|
||||
}; // end namespace Base
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
}; // end namespace NAMESPACE
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
#include "Config.h"
|
||||
|
||||
//#include <stdlib.h>
|
||||
//#include <stdio.h>
|
||||
//#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "Platform.h"
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
//-----------------------------------
|
||||
/// Read the config file into memory
|
||||
/// Returns true for success
|
||||
bool CConfig::LoadFile(char * file)
|
||||
//-----------------------------------
|
||||
{
|
||||
char ch;
|
||||
FILE * fp;
|
||||
|
||||
UnloadFile();
|
||||
|
||||
// open file
|
||||
fp = fopen(file, "r");
|
||||
if (fp == NULL || fp == (FILE *)-1)
|
||||
{
|
||||
//fprintf(stderr,"Failed to open config file %s!",file);
|
||||
return false;
|
||||
}
|
||||
|
||||
// get length of file
|
||||
fseek(fp,0,SEEK_END);
|
||||
long length = ftell(fp);
|
||||
rewind(fp);
|
||||
|
||||
// allocate buffer
|
||||
pConfig = new char[length + 1];
|
||||
|
||||
if (pConfig == NULL)
|
||||
{
|
||||
fclose(fp);
|
||||
fprintf(stderr,"Failed to alloc config buffer length %d",(int32)length);
|
||||
return false;
|
||||
}
|
||||
memset(pConfig,0,length);
|
||||
|
||||
// read data, stripping comments
|
||||
int i = 0;
|
||||
while (i < length)
|
||||
{
|
||||
ch = fgetc(fp);
|
||||
if (feof(fp))
|
||||
break;
|
||||
if (ch == '#')
|
||||
{
|
||||
while (ch != 10 && !feof (fp))
|
||||
{
|
||||
ch = fgetc(fp);
|
||||
}
|
||||
}
|
||||
pConfig[i++] = ch;
|
||||
}
|
||||
pConfig[i] = 0; // mark end of file buffer
|
||||
|
||||
fclose(fp);
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------
|
||||
/// remove the config file from memory
|
||||
void CConfig::UnloadFile(void)
|
||||
//-----------------------------------
|
||||
{
|
||||
if (pConfig)
|
||||
delete[] pConfig;
|
||||
pConfig = NULL;
|
||||
}
|
||||
|
||||
//-----------------------------------
|
||||
/// finds a key of the config in memory
|
||||
// key argument is case-insensitive, but must be upper case in config file
|
||||
// Returns true for success (passing NULL is a special case returned as success)
|
||||
bool CConfig::FindKey(char *key)
|
||||
//-----------------------------------
|
||||
{
|
||||
if (pConfig == NULL)
|
||||
return false;
|
||||
|
||||
// special case...continue with existing key
|
||||
if (key == NULL)
|
||||
return true;
|
||||
|
||||
// form the search key
|
||||
strcpy(strBuffer, "[");
|
||||
strcat(strBuffer, key);
|
||||
strcat(strBuffer,"]");
|
||||
strupr(strBuffer); // keywords must be upper case
|
||||
|
||||
// find the key heading
|
||||
pCursor = strstr(pConfig,strBuffer);
|
||||
if (pCursor==NULL)
|
||||
return false;
|
||||
|
||||
// find the closing bracket of key heading
|
||||
pCursor = strchr(pCursor,']');
|
||||
if (pCursor==NULL)
|
||||
return false;
|
||||
pCursor++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------
|
||||
/// extract a number from the config string
|
||||
// pass the key to find the first number in the list, else NULL to find the next number in the list
|
||||
// returns 0 if no number is found, else returns the number
|
||||
long CConfig::GetLong(char *key)
|
||||
//-----------------------------------
|
||||
{
|
||||
if (!FindKey(key))
|
||||
return 0;
|
||||
|
||||
|
||||
// look for start of number or end of key
|
||||
while (*pCursor && !isdigit(*pCursor) && *pCursor != '[' && *pCursor != '-')
|
||||
pCursor++;
|
||||
|
||||
int c = 0;
|
||||
while (*pCursor && (isdigit(*pCursor) || *pCursor == '-') && c < (int)sizeof(strBuffer))
|
||||
strBuffer[c++] = *(pCursor++);
|
||||
strBuffer[c] = '\0';
|
||||
|
||||
return atol(strBuffer);
|
||||
}
|
||||
|
||||
//-----------------------------------
|
||||
/// extract string (in double-quotes) from the list.
|
||||
// pass the key to find the first string in the list, else NULL to find the next string in the list
|
||||
// returns NULL if no string found, else returns a temporary copy of the string (without quotes)
|
||||
char * CConfig::GetString(char *key)
|
||||
//-----------------------------------
|
||||
{
|
||||
if (!FindKey(key))
|
||||
return NULL;
|
||||
|
||||
|
||||
// look for start of string or end of key
|
||||
while (*pCursor && *pCursor != '"' && *pCursor != '[')
|
||||
pCursor++;
|
||||
if (*(pCursor++) != '"')
|
||||
return NULL;
|
||||
|
||||
// until closing quote
|
||||
int c = 0;
|
||||
while (*pCursor && c < (int)sizeof(strBuffer))
|
||||
{
|
||||
strBuffer[c++] = *pCursor; // extract string
|
||||
if (*pCursor++ == '"')
|
||||
{
|
||||
strBuffer[--c] = '\0';
|
||||
return strBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
; Example syntax of a config file.
|
||||
# This is a comment to end of line.
|
||||
; This is a comment too....both comments are to end of line
|
||||
[KEYWORD] ; all keywords must be upper case to be recognized
|
||||
|
||||
; single number, with code example
|
||||
# long number = config.GetLong("PORT");
|
||||
[PORT] 5999 ; common single-value case
|
||||
|
||||
; list of strings, with code example
|
||||
# config.FindKey("NUMBERS");
|
||||
# while (number = config.GetLong(NULL))
|
||||
# YourHandleNumber(number);
|
||||
[NUMBERS] 100
|
||||
200, 300 ; formatting is very flexible as long as numbers are delimited by non-numbers
|
||||
400 500
|
||||
600 ; This is badly formatted for example purposes only
|
||||
|
||||
; single string, with code example
|
||||
# strcpy(mystring, config.GetString("STRING"));
|
||||
[STRING] "This is a string"
|
||||
|
||||
; list of strings, with code example
|
||||
# config.FindKey("HOSTS");
|
||||
# while (string = config.GetString(NULL))
|
||||
# YourHandleString(string);
|
||||
[HOSTS]
|
||||
"206.19.151.173:5999"
|
||||
"206.19.151.173:5998"
|
||||
"206.19.151.173:2000"
|
||||
|
||||
*/
|
||||
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
class CConfig
|
||||
{
|
||||
public:
|
||||
// constructor, no file loaded
|
||||
CConfig();
|
||||
|
||||
// version of constructor that calls LoadFile(file)
|
||||
CConfig(char * file);
|
||||
|
||||
// destructor, will delete all buffers
|
||||
~CConfig();
|
||||
|
||||
// copy text config file into memory. Required to use extraction methods.
|
||||
// if called with a different filename, existing file will be discarded.
|
||||
bool LoadFile(char * file);
|
||||
|
||||
// delete memory buffer of file
|
||||
void UnloadFile();
|
||||
|
||||
// set cursor in file based on key name. Alternate way to select first key when extracting lists.
|
||||
// returns TRUE if key is found.
|
||||
bool FindKey(char *key);
|
||||
|
||||
// extract string from config. If key is NULL, extract next string in list, else extract first string.
|
||||
// if key was not found, returns NULL
|
||||
char * GetString(char *key = NULL);
|
||||
|
||||
// extract number from config. If key is NULL, extract next number in list, else extract first number.
|
||||
// if key was not found, returns 0
|
||||
long GetLong(char *key = NULL); // extract number from config.
|
||||
|
||||
// indicate if config file has been loaded
|
||||
inline bool FileLoaded() { return pConfig == NULL ? false : true; }
|
||||
|
||||
private:
|
||||
char * pConfig; // pointer to file memory
|
||||
char * pCursor; // current cursor into file memory
|
||||
char strBuffer[8196]; // buffer for GetString return pointer -- reused
|
||||
};
|
||||
|
||||
inline CConfig::CConfig()
|
||||
{
|
||||
pConfig = NULL;
|
||||
pCursor = NULL;
|
||||
}
|
||||
|
||||
inline CConfig::CConfig(char * file)
|
||||
{
|
||||
pConfig = NULL;
|
||||
pCursor = NULL;
|
||||
LoadFile(file);
|
||||
}
|
||||
|
||||
inline CConfig::~CConfig()
|
||||
{
|
||||
UnloadFile();
|
||||
}
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef BASE_EVENT_H
|
||||
#define BASE_EVENT_H
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "win32/Event.h"
|
||||
|
||||
#elif linux
|
||||
|
||||
#include "linux/Event.h"
|
||||
|
||||
#elif sparc
|
||||
|
||||
#include "solaris/Event.h"
|
||||
|
||||
#else
|
||||
|
||||
#error /Base/Event.h: Undefine platform type
|
||||
|
||||
#endif
|
||||
|
||||
#endif // BASE_EVENT_H
|
||||
@@ -0,0 +1,756 @@
|
||||
#include "Logger.h"
|
||||
#include "Mutex.h"
|
||||
#include <sys/stat.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
const long kDateLenAllowance = 256;
|
||||
|
||||
#ifndef _BASE_LOGGER_MAX_BUF_SIZE_
|
||||
#define _BASE_LOGGER_MAX_BUF_SIZE_ 2048
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
const char file_sep = '\\';
|
||||
|
||||
#define LOGGER_GET_CURR_TIME(__tm_struct__, __time_t_var__) \
|
||||
memcpy(&__tm_struct__, localtime(&__time_t_var__), sizeof(__tm_struct__))
|
||||
|
||||
#define LOGGER_MAKE_DIR(__dir_name__, __mode__) mkdir(__dir_name__)
|
||||
|
||||
# ifdef _MT
|
||||
# define LOGGER_LOCK rLock.Lock();
|
||||
# define LOGGER_UNLOCK rLock.Unlock();
|
||||
# else // ifndef _MT
|
||||
# define LOGGER_LOCK
|
||||
# define LOGGER_UNLOCK
|
||||
# endif // _MT
|
||||
|
||||
|
||||
|
||||
|
||||
#define vsnprintf _vsnprintf
|
||||
|
||||
#else // ifndef WIN32
|
||||
const char file_sep = '/';
|
||||
|
||||
const char *syslogLevels[] = {
|
||||
"EMERG", "ALERT", "CRIT", "ERR", "WARNING", "NOTICE", "INFO", "DEBUG" };
|
||||
|
||||
const int numSysLogLevels = sizeof(syslogLevels) / sizeof(char *);
|
||||
|
||||
#define LOGGER_GET_CURR_TIME(__tm_struct__, __time_t_var__) \
|
||||
localtime_r(&__time_t_var__, &__tm_struct__)
|
||||
|
||||
#define LOGGER_MAKE_DIR(__dir_name__, __mode__) mkdir(__dir_name__, __mode__)
|
||||
|
||||
# ifdef _REENTRANT
|
||||
# define LOGGER_LOCK rLock.Lock();
|
||||
# define LOGGER_UNLOCK rLock.Unlock();
|
||||
# else // ifndef _REENTRANT
|
||||
# define LOGGER_LOCK
|
||||
# define LOGGER_UNLOCK
|
||||
# endif // _REENTRANT
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
Logger::Logger(const char *prefix,
|
||||
int level,
|
||||
unsigned size,
|
||||
bool rollDate)
|
||||
: m_defaultLevel(level),
|
||||
m_defaultSize(size),
|
||||
m_dirPrefix(prefix),
|
||||
m_rollDate(rollDate),
|
||||
m_opennedSyslog(false)
|
||||
{
|
||||
ELogType logType = eUseLocalFile;
|
||||
|
||||
m_logLevelToTypeMap[LOG_DEBUG] = logType;
|
||||
m_logLevelToTypeMap[LOG_INFO] = logType;
|
||||
m_logLevelToTypeMap[LOG_NOTICE] = logType;
|
||||
m_logLevelToTypeMap[LOG_WARNING] = logType;
|
||||
m_logLevelToTypeMap[LOG_ERR] = logType;
|
||||
m_logLevelToTypeMap[LOG_CRIT] = logType;
|
||||
m_logLevelToTypeMap[LOG_ALERT] = logType;
|
||||
m_logLevelToTypeMap[LOG_EMERG] = logType;
|
||||
m_combinedLogType = logType;
|
||||
|
||||
LoggerInit("UnNamedServer");
|
||||
}
|
||||
|
||||
Logger::Logger(const char *programName,
|
||||
const ELogType logType,
|
||||
const char *prefix,
|
||||
int level,
|
||||
unsigned size,
|
||||
bool rollDate)
|
||||
: m_defaultLevel(level),
|
||||
m_defaultSize(size),
|
||||
m_dirPrefix(prefix),
|
||||
m_rollDate(rollDate),
|
||||
m_opennedSyslog(false)
|
||||
{
|
||||
m_logLevelToTypeMap[LOG_DEBUG] = logType;
|
||||
m_logLevelToTypeMap[LOG_INFO] = logType;
|
||||
m_logLevelToTypeMap[LOG_NOTICE] = logType;
|
||||
m_logLevelToTypeMap[LOG_WARNING] = logType;
|
||||
m_logLevelToTypeMap[LOG_ERR] = logType;
|
||||
m_logLevelToTypeMap[LOG_CRIT] = logType;
|
||||
m_logLevelToTypeMap[LOG_ALERT] = logType;
|
||||
m_logLevelToTypeMap[LOG_EMERG] = logType;
|
||||
m_combinedLogType = logType;
|
||||
|
||||
LoggerInit(programName);
|
||||
}
|
||||
|
||||
|
||||
void Logger::LoggerInit(const char *programName)
|
||||
{
|
||||
char buf[1024];
|
||||
FILE *logDir = NULL;
|
||||
|
||||
if (0 != (m_combinedLogType & eUseLocalFile))
|
||||
{
|
||||
logDir = fopen(m_dirPrefix.c_str(), "r+");
|
||||
if(errno == ENOENT)
|
||||
{
|
||||
cmkdir(m_dirPrefix.c_str(), 0755);
|
||||
}
|
||||
else if(logDir != NULL)
|
||||
{
|
||||
fclose(logDir);
|
||||
}
|
||||
|
||||
tm now;
|
||||
time_t t = time(NULL);
|
||||
|
||||
LOGGER_GET_CURR_TIME(now, t);
|
||||
|
||||
memcpy(&m_lastDateTime, &now, sizeof(tm));
|
||||
if(m_rollDate)
|
||||
{
|
||||
sprintf(buf, "%s%c%2.2d-%2.2d-%2.2d", m_dirPrefix.c_str(), file_sep, (now.tm_mon + 1), now.tm_mday, (now.tm_year % 100));
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(buf, "%s", m_dirPrefix.c_str());
|
||||
}
|
||||
logDir = fopen(buf, "r+");
|
||||
if(errno == ENOENT)
|
||||
{
|
||||
cmkdir(buf, 0755);
|
||||
}
|
||||
else if(logDir != NULL)
|
||||
{
|
||||
fclose(logDir);
|
||||
}
|
||||
m_logPrefix = buf;
|
||||
m_logRolloverSize = 0x80000000; // Default: 2 GB upper limit on file size
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
// Open connection to syslog
|
||||
if (0 != (m_combinedLogType & eUseSysLog)) {
|
||||
openlog(programName, LOG_NDELAY | LOG_PID, LOG_LOCAL5);
|
||||
m_opennedSyslog = true;
|
||||
}
|
||||
#endif // !WIN32
|
||||
|
||||
}
|
||||
|
||||
Logger::~Logger()
|
||||
{
|
||||
map<unsigned, LogInfo *>::iterator iter;
|
||||
for(iter = m_logTable.begin(); iter != m_logTable.end(); iter++)
|
||||
{
|
||||
logWithSys((*iter).first, LOG_INFO, LOG_FILEONLY, "---=== Log Stopped ===---");
|
||||
fflush((*iter).second->file);
|
||||
fclose((*iter).second->file);
|
||||
delete((*iter).second);
|
||||
|
||||
}
|
||||
m_logTable.clear();
|
||||
|
||||
#ifndef WIN32
|
||||
// close connection to syslog
|
||||
if (m_opennedSyslog)
|
||||
closelog();
|
||||
#endif // !WIN32
|
||||
}
|
||||
|
||||
ELogType Logger::getLoggingType(unsigned logLevel) const
|
||||
{
|
||||
std::map<unsigned, ELogType>::const_iterator levelIter = m_logLevelToTypeMap.find(logLevel);
|
||||
ELogType logType = eUseNone;
|
||||
|
||||
if (levelIter != m_logLevelToTypeMap.end())
|
||||
{
|
||||
logType = levelIter->second;
|
||||
}
|
||||
|
||||
return logType;
|
||||
}
|
||||
|
||||
void Logger::setLoggingType(unsigned logLevel, ELogType logType)
|
||||
{
|
||||
std::map<unsigned, ELogType>::iterator levelIter = m_logLevelToTypeMap.find(logLevel);
|
||||
|
||||
if (levelIter != m_logLevelToTypeMap.end())
|
||||
{
|
||||
levelIter->second = logType;
|
||||
|
||||
if (logType > m_combinedLogType) {
|
||||
m_combinedLogType = (ELogType)(m_combinedLogType | logType);
|
||||
} else {
|
||||
m_combinedLogType = eUseNone;
|
||||
|
||||
for (levelIter = m_logLevelToTypeMap.begin();
|
||||
levelIter != m_logLevelToTypeMap.end();
|
||||
levelIter++)
|
||||
{
|
||||
m_combinedLogType = (ELogType)(m_combinedLogType | logType);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::flush(unsigned logenum)
|
||||
{
|
||||
map<unsigned, LogInfo *>::iterator iter = m_logTable.find(logenum);
|
||||
|
||||
if(iter != m_logTable.end())
|
||||
{
|
||||
LogInfo *info = (*iter).second;
|
||||
fflush(info->file);
|
||||
info->used = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::flushAll()
|
||||
{
|
||||
if (0 != (m_combinedLogType & eUseLocalFile))
|
||||
{
|
||||
map<unsigned, LogInfo *>::iterator iter;
|
||||
|
||||
for(iter = m_logTable.begin(); iter != m_logTable.end(); iter++)
|
||||
{
|
||||
LogInfo *info = (*iter).second;
|
||||
fflush(info->file);
|
||||
info->used = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::addLog(const char *id, unsigned logenum, int level, unsigned size)
|
||||
{
|
||||
if (0 != (m_combinedLogType & eUseLocalFile))
|
||||
{
|
||||
LogInfo *newLog = new LogInfo;
|
||||
newLog->filename = m_logPrefix + file_sep + id + ".log";
|
||||
newLog->name = id;
|
||||
newLog->used = 0;
|
||||
newLog->max = size;
|
||||
newLog->last = 0;
|
||||
newLog->level = level;
|
||||
|
||||
m_logTable.insert(pair<unsigned, LogInfo *>(logenum, newLog));
|
||||
|
||||
if(strcmp("stdout", id) == 0)
|
||||
{
|
||||
newLog->file = stdout;
|
||||
}
|
||||
else if(strcmp("stderr", id) == 0)
|
||||
{
|
||||
newLog->file = stderr;
|
||||
}
|
||||
else
|
||||
{
|
||||
newLog->file = fopen(newLog->filename.c_str(), "a+");
|
||||
if(newLog->file == NULL)
|
||||
{
|
||||
printf("Open file %s failed\n", newLog->filename.c_str());
|
||||
}
|
||||
}
|
||||
logWithSys(logenum, LOG_INFO, LOG_FILEONLY, "---=== Log Started ===---");
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::addLog(const char *id, unsigned logenum)
|
||||
{
|
||||
if (0 != (m_combinedLogType & eUseLocalFile))
|
||||
{
|
||||
LogInfo *newLog = new LogInfo;
|
||||
newLog->filename = m_logPrefix + file_sep + id + ".log";
|
||||
newLog->name = id;
|
||||
newLog->used = 0;
|
||||
newLog->max = m_defaultSize;
|
||||
newLog->last = 0;
|
||||
newLog->level = m_defaultLevel;
|
||||
|
||||
m_logTable.insert(pair<unsigned, LogInfo *>(logenum, newLog));
|
||||
|
||||
if(strcmp("stdout", id) == 0)
|
||||
{
|
||||
newLog->file = stdout;
|
||||
}
|
||||
else if(strcmp("stderr", id) == 0)
|
||||
{
|
||||
newLog->file = stderr;
|
||||
}
|
||||
else
|
||||
{
|
||||
newLog->file = fopen(newLog->filename.c_str(), "a+");
|
||||
if(newLog->file == NULL)
|
||||
{
|
||||
printf("Open file %s failed\n", newLog->filename.c_str());
|
||||
}
|
||||
}
|
||||
logWithSys(logenum, LOG_INFO, LOG_FILEONLY, "---===Log Started ===---");
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::updateLog(unsigned logenum, int level, unsigned size)
|
||||
{
|
||||
if (0 != (m_combinedLogType & eUseLocalFile))
|
||||
{
|
||||
map<unsigned, LogInfo *>::iterator iter = m_logTable.find(logenum);
|
||||
|
||||
if(iter != m_logTable.end())
|
||||
{
|
||||
(*iter).second->level = level;
|
||||
(*iter).second->max = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::removeLog(unsigned logenum)
|
||||
{
|
||||
if (0 != (m_combinedLogType & eUseLocalFile))
|
||||
{
|
||||
map<unsigned, LogInfo *>::iterator iter = m_logTable.find(logenum);
|
||||
|
||||
if(iter != m_logTable.end())
|
||||
{
|
||||
#ifdef WIN32
|
||||
logWithSys((*iter).first, LOG_INFO, LOG_FILEONLY, "---=== Log Stopped ===---");
|
||||
#else // ifndef WIN32
|
||||
logWithSys((*iter).first, LOG_INFO, LOG_ALWAYS, "---=== Log Stopped ===---");
|
||||
#endif // WIN32
|
||||
fflush((*iter).second->file);
|
||||
fclose((*iter).second->file);
|
||||
delete((*iter).second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Logger::logSimple(unsigned logenum, int level, const char *message)
|
||||
{
|
||||
map<unsigned, LogInfo *>::iterator iter = m_logTable.find(logenum);
|
||||
|
||||
if(iter == m_logTable.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
time_t t = time(NULL);
|
||||
LogInfo *info = (*iter).second;
|
||||
if(level >= info->level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
#ifndef WIN32
|
||||
if(level == LOG_FILEONLY && ((info->file == stderr) || (info->file == stdout)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif // !WIN32
|
||||
if(info->last != t)
|
||||
{
|
||||
memcpy(&info->ts, localtime(&t), sizeof(tm));
|
||||
info->last = t;
|
||||
}
|
||||
|
||||
if(m_rollDate && info->ts.tm_mday != m_lastDateTime.tm_mday)
|
||||
{
|
||||
LOGGER_LOCK
|
||||
|
||||
if(info->ts.tm_mday != m_lastDateTime.tm_mday)
|
||||
{
|
||||
memcpy(&m_lastDateTime, &info->ts, sizeof(tm));
|
||||
rollDate(t);
|
||||
}
|
||||
|
||||
LOGGER_UNLOCK
|
||||
}
|
||||
if(iter != m_logTable.end())
|
||||
{
|
||||
if(info->max > 0)
|
||||
{
|
||||
info->used += fprintf(info->file, "[%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d] %s", (info->ts.tm_mon + 1), info->ts.tm_mday, (info->ts.tm_year % 100), info->ts.tm_hour, info->ts.tm_min, info->ts.tm_sec, message);
|
||||
info->used += fputc('\n', info->file);
|
||||
if(info->used > info->max)
|
||||
{
|
||||
fflush(info->file);
|
||||
info->used = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(info->file, "[%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d] %s", (info->ts.tm_mon + 1), info->ts.tm_mday, (info->ts.tm_year % 100), info->ts.tm_hour, info->ts.tm_min, info->ts.tm_sec, message);
|
||||
fputc('\n', info->file);
|
||||
fflush(info->file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void Logger::logSimpleWithSys(unsigned logenum, unsigned priority, int level, const char *message)
|
||||
{
|
||||
#ifndef WIN32
|
||||
if (0 != (m_combinedLogType & eUseSysLog))
|
||||
syslog(priority, "%s: %s", syslogLevels[priority % numSysLogLevels], message);
|
||||
#endif // !WIN32
|
||||
|
||||
if (0 != (m_combinedLogType & eUseLocalFile))
|
||||
{
|
||||
map<unsigned, LogInfo *>::iterator iter = m_logTable.find(logenum);
|
||||
|
||||
if(iter == m_logTable.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
time_t t = time(NULL);
|
||||
LogInfo *info = (*iter).second;
|
||||
|
||||
if(level >= info->level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
if(level == LOG_FILEONLY && ((info->file == stderr) || (info->file == stdout)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
#endif // !WIN32
|
||||
|
||||
if(info->last != t)
|
||||
{
|
||||
memcpy(&info->ts, localtime(&t), sizeof(tm));
|
||||
info->last = t;
|
||||
}
|
||||
|
||||
if(m_rollDate && info->ts.tm_mday != m_lastDateTime.tm_mday)
|
||||
{
|
||||
LOGGER_LOCK
|
||||
|
||||
if(info->ts.tm_mday != m_lastDateTime.tm_mday)
|
||||
{
|
||||
memcpy(&m_lastDateTime, &info->ts, sizeof(tm));
|
||||
rollDate(t);
|
||||
}
|
||||
|
||||
LOGGER_UNLOCK
|
||||
}
|
||||
if(iter != m_logTable.end())
|
||||
{
|
||||
if (m_logRolloverSize> 0)
|
||||
checkLogRoll(info, ::strlen(message) + kDateLenAllowance);
|
||||
|
||||
if(info->max > 0)
|
||||
{
|
||||
info->used += fprintf(info->file, "[%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d] %s", (info->ts.tm_mon + 1), info->ts.tm_mday, (info->ts.tm_year % 100), info->ts.tm_hour, info->ts.tm_min, info->ts.tm_sec, message);
|
||||
info->used += fputc('\n', info->file);
|
||||
if(info->used > info->max)
|
||||
{
|
||||
fflush(info->file);
|
||||
info->used = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(info->file, "[%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d] %s", (info->ts.tm_mon + 1), info->ts.tm_mday, (info->ts.tm_year % 100), info->ts.tm_hour, info->ts.tm_min, info->ts.tm_sec, message);
|
||||
fputc('\n', info->file);
|
||||
fflush(info->file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::log(unsigned logenum, int level, const char *message, ...)
|
||||
{
|
||||
char buf[_BASE_LOGGER_MAX_BUF_SIZE_];
|
||||
va_list varg;
|
||||
va_start(varg, message);
|
||||
vsnprintf(buf, _BASE_LOGGER_MAX_BUF_SIZE_, message, varg);
|
||||
buf[_BASE_LOGGER_MAX_BUF_SIZE_ - 1] = 0;
|
||||
va_end(varg);
|
||||
|
||||
// ensure that the buf does not contain any '%' characters.
|
||||
// prevent crash problem
|
||||
char *rv;
|
||||
while((rv = strchr(buf, '%')) != NULL)
|
||||
{
|
||||
*rv = ' '; // replace with space
|
||||
}
|
||||
|
||||
|
||||
logWithSys(logenum, LOG_NOTICE, level, buf);
|
||||
}
|
||||
|
||||
|
||||
void Logger::logWithSys(unsigned logenum, unsigned priority, int level, const char *message, ...)
|
||||
{
|
||||
ELogType logType = getLoggingType(priority);
|
||||
char buf[_BASE_LOGGER_MAX_BUF_SIZE_];
|
||||
va_list varg;
|
||||
va_start(varg, message);
|
||||
vsnprintf(buf, _BASE_LOGGER_MAX_BUF_SIZE_, message, varg);
|
||||
buf[_BASE_LOGGER_MAX_BUF_SIZE_ - 1] = 0;
|
||||
va_end(varg);
|
||||
|
||||
#ifndef WIN32
|
||||
if (0 != (logType & eUseSysLog))
|
||||
syslog(priority, "%s: %s", syslogLevels[priority % numSysLogLevels], buf);
|
||||
#endif // !WIN32
|
||||
|
||||
if (0 != (logType & eUseLocalFile))
|
||||
{
|
||||
map<unsigned, LogInfo *>::iterator iter = m_logTable.find(logenum);
|
||||
if(iter == m_logTable.end())
|
||||
{
|
||||
return;
|
||||
}
|
||||
time_t t = time(NULL);
|
||||
LogInfo *info = (*iter).second;
|
||||
|
||||
if(level >= info->level)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(level == LOG_FILEONLY && ((info->file == stderr) || (info->file == stdout)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(info->last != t)
|
||||
{
|
||||
LOGGER_GET_CURR_TIME(info->ts, t);
|
||||
|
||||
info->last = t;
|
||||
}
|
||||
if(m_rollDate && info->ts.tm_mday != m_lastDateTime.tm_mday)
|
||||
{
|
||||
LOGGER_LOCK
|
||||
|
||||
if(info->ts.tm_mday != m_lastDateTime.tm_mday)
|
||||
{
|
||||
memcpy(&m_lastDateTime, &info->ts, sizeof(tm));
|
||||
rollDate(t);
|
||||
}
|
||||
|
||||
LOGGER_UNLOCK
|
||||
}
|
||||
|
||||
if(iter != m_logTable.end())
|
||||
{
|
||||
if (m_logRolloverSize> 0)
|
||||
checkLogRoll(info, ::strlen(buf) + kDateLenAllowance);
|
||||
|
||||
if(info->max > 0)
|
||||
{
|
||||
info->used += fprintf(info->file, "[%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d] %s", (info->ts.tm_mon + 1), info->ts.tm_mday, (info->ts.tm_year % 100), info->ts.tm_hour, info->ts.tm_min, info->ts.tm_sec, buf);
|
||||
info->used += fputc('\n', info->file);
|
||||
if(info->used > info->max)
|
||||
{
|
||||
fflush(info->file);
|
||||
info->used = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(info->file, "[%2.2d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d] %s", (info->ts.tm_mon + 1), info->ts.tm_mday, (info->ts.tm_year % 100), info->ts.tm_hour, info->ts.tm_min, info->ts.tm_sec, buf);
|
||||
fputc('\n', info->file);
|
||||
fflush(info->file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::rollDate(time_t t)
|
||||
{
|
||||
char buf[80];
|
||||
FILE *logDir = NULL;
|
||||
|
||||
logDir = fopen(m_dirPrefix.c_str(), "r+");
|
||||
if(errno == ENOENT)
|
||||
{
|
||||
cmkdir(m_dirPrefix.c_str(), 0755);
|
||||
}
|
||||
else if(logDir != NULL)
|
||||
{
|
||||
fclose(logDir);
|
||||
}
|
||||
|
||||
tm now;
|
||||
|
||||
LOGGER_GET_CURR_TIME(now, t);
|
||||
|
||||
sprintf(buf, "%s%c%2.2d-%2.2d-%2.2d", m_dirPrefix.c_str(), file_sep, (now.tm_mon + 1), now.tm_mday, (now.tm_year % 100));
|
||||
logDir = fopen(buf, "r+");
|
||||
|
||||
if(errno == ENOENT)
|
||||
{
|
||||
cmkdir(buf, 0755);
|
||||
}
|
||||
else if(logDir != NULL)
|
||||
{
|
||||
fclose(logDir);
|
||||
}
|
||||
m_logPrefix = buf;
|
||||
|
||||
map<unsigned, LogInfo *>::iterator iter;
|
||||
for(iter = m_logTable.begin(); iter != m_logTable.end(); iter++)
|
||||
{
|
||||
(*iter).second->filename = m_logPrefix + file_sep + (*iter).second->name.c_str() + ".log";
|
||||
fflush((*iter).second->file);
|
||||
fclose((*iter).second->file);
|
||||
(*iter).second->file = fopen((*iter).second->filename.c_str(), "a+");
|
||||
if ((*iter).second->file == 0)
|
||||
abort();
|
||||
memcpy(&((*iter).second->ts), &now, sizeof(tm));
|
||||
}
|
||||
}
|
||||
|
||||
// mkdir function that creates intermediate directories
|
||||
void Logger::cmkdir(const char *dir, int mode)
|
||||
{
|
||||
char dirbuf[128];
|
||||
strncpy(dirbuf, dir, 127);
|
||||
dirbuf[127] = 0;
|
||||
char *j = dirbuf, *i = dirbuf;
|
||||
int handle;
|
||||
|
||||
while(*i)
|
||||
{
|
||||
if(*i == file_sep)
|
||||
{
|
||||
(*i) = 0;
|
||||
#ifdef WIN32
|
||||
handle = open(j, O_EXCL);
|
||||
|
||||
if((handle > 0) || (errno != EISDIR && errno != ENOENT && errno != EACCES))
|
||||
{
|
||||
perror("Logger::cmkdir():");
|
||||
abort();
|
||||
}
|
||||
#else // ifndef WIN32
|
||||
// handle = open(j, O_EXCL); // Ben's original code
|
||||
// if((handle > 0) || (errno != EISDIR && errno != ENOENT))
|
||||
// {
|
||||
// perror("Logger::cmkdir():");
|
||||
// abort();
|
||||
// }
|
||||
|
||||
// This doesnt work under Linux, it returns a valid handle
|
||||
// Instead: see if file exists. If it doesnt, create directory ok
|
||||
// If it exists, do stat to see if it is a dir.
|
||||
// If it is a dir, then ok, create the directory.
|
||||
// If it is a file, error
|
||||
// ging 9-16-2002
|
||||
|
||||
handle = open(j, O_RDONLY);
|
||||
if (handle > 0)
|
||||
{
|
||||
struct stat stat_buffer;
|
||||
int ret = fstat(handle,&stat_buffer);
|
||||
if ((ret == -1) || ((stat_buffer.st_mode | S_IFDIR) == 0))
|
||||
{
|
||||
perror("Logger::cmkdir():");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
#endif // WIN32
|
||||
LOGGER_MAKE_DIR(j, mode);
|
||||
close(handle);
|
||||
(*i) = file_sep;
|
||||
}
|
||||
else if(*(i + 1) == 0)
|
||||
{
|
||||
LOGGER_MAKE_DIR(j, mode);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
void Logger::rollLog(LogInfo *logInfo)
|
||||
{
|
||||
std::string newLogName;
|
||||
char timeStampBuffer[256];
|
||||
time_t t = time(NULL);
|
||||
tm now;
|
||||
int r;
|
||||
int nTries = 10;
|
||||
|
||||
fflush(logInfo->file);
|
||||
fclose(logInfo->file);
|
||||
|
||||
do
|
||||
{
|
||||
LOGGER_GET_CURR_TIME(now, t);
|
||||
sprintf(timeStampBuffer, "-%4.4d-%2.2d-%2.2d-%2.2d-%2.2d-%2.2d.log",
|
||||
(now.tm_year + 1900), (now.tm_mon + 1), now.tm_mday, now.tm_hour, now.tm_min, now.tm_sec);
|
||||
newLogName = logInfo->filename.substr(0, logInfo->filename.length() - 4) + timeStampBuffer;
|
||||
r = rename(logInfo->filename.c_str(), newLogName.c_str());
|
||||
nTries--;
|
||||
t++;
|
||||
}
|
||||
while ((r != 0) && (nTries > 0));
|
||||
|
||||
logInfo->file = fopen(logInfo->filename.c_str(), "a+");
|
||||
memcpy(&(logInfo->ts), &now, sizeof(tm));
|
||||
}
|
||||
|
||||
void Logger::checkLogRoll(LogInfo *logInfo, unsigned long lenToAdd)
|
||||
{
|
||||
unsigned long logSize = ftell(logInfo->file);
|
||||
|
||||
if ((logSize + lenToAdd) > m_logRolloverSize)
|
||||
{
|
||||
LOGGER_LOCK
|
||||
|
||||
rollLog(logInfo);
|
||||
|
||||
LOGGER_UNLOCK
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,165 @@
|
||||
#ifndef __LOGGER_H__
|
||||
#define __LOGGER_H__
|
||||
|
||||
// make the compiler shut up
|
||||
#pragma warning (disable : 4786)
|
||||
|
||||
#include "Platform.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include "Mutex.h"
|
||||
#ifndef WIN32
|
||||
#include <syslog.h>
|
||||
#endif
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
#define LOG_ALWAYS -1
|
||||
#define LOG_FILEONLY -2
|
||||
|
||||
struct LogInfo
|
||||
{
|
||||
FILE *file;
|
||||
unsigned used;
|
||||
tm ts;
|
||||
time_t last;
|
||||
unsigned max;
|
||||
int level;
|
||||
std::string filename;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
/* Use these flags defined in syslog.h for the priority level
|
||||
LOG_EMERG,
|
||||
LOG_ALERT,
|
||||
LOG_CRIT,
|
||||
LOG_ERR,
|
||||
LOG_WARNING,
|
||||
LOG_NOTICE,
|
||||
LOG_INFO,
|
||||
LOG_DEBUG
|
||||
*/
|
||||
|
||||
//-----------------------------------------------
|
||||
// Windows doesn't have syslog (?) so we define the
|
||||
// syslog warning levels here to satisfy the compiler
|
||||
// but then ignore them in log() and logSimple()
|
||||
//-----------------------------------------------
|
||||
|
||||
// PLEASE USE THE FOLLOWING ENUMERATIONS FOR LOGGING INSTEAD OF THE SYSLOG ONES.
|
||||
enum LogLevel
|
||||
{
|
||||
#ifndef WIN32
|
||||
BASE_LOG_EMERG = LOG_EMERG,
|
||||
BASE_LOG_ALERT = LOG_ALERT,
|
||||
BASE_LOG_CRIT = LOG_CRIT,
|
||||
BASE_LOG_ERR = LOG_ERR,
|
||||
BASE_LOG_WARNING = LOG_WARNING,
|
||||
BASE_LOG_NOTICE = LOG_NOTICE,
|
||||
BASE_LOG_INFO = LOG_INFO,
|
||||
BASE_LOG_DEBUG = LOG_DEBUG
|
||||
#else
|
||||
BASE_LOG_EMERG = 0,
|
||||
BASE_LOG_ALERT,
|
||||
BASE_LOG_CRIT,
|
||||
BASE_LOG_ERR,
|
||||
BASE_LOG_WARNING,
|
||||
BASE_LOG_NOTICE,
|
||||
BASE_LOG_INFO,
|
||||
BASE_LOG_DEBUG
|
||||
#endif
|
||||
};
|
||||
|
||||
// The _WIN32_LOG_LEVELS_ remain for backwards compatability.
|
||||
#ifdef WIN32
|
||||
enum _WIN32_LOG_LEVELS_
|
||||
{
|
||||
LOG_EMERG = 0,
|
||||
LOG_ALERT,
|
||||
LOG_CRIT,
|
||||
LOG_ERR,
|
||||
LOG_WARNING,
|
||||
LOG_NOTICE,
|
||||
LOG_INFO,
|
||||
LOG_DEBUG
|
||||
};
|
||||
#endif
|
||||
|
||||
enum ELogType
|
||||
{
|
||||
eUseNone = 0,
|
||||
eUseLocalFile = 1,
|
||||
eUseSysLog = 2,
|
||||
eUseBoth = 3
|
||||
};
|
||||
|
||||
class Logger
|
||||
{
|
||||
public:
|
||||
Logger(const char *programName,
|
||||
const ELogType logType = eUseLocalFile,
|
||||
const char *prefix = "logs",
|
||||
int level = 10,
|
||||
unsigned size = 0,
|
||||
bool rollDate = true);
|
||||
|
||||
Logger(const char *prefix,
|
||||
int level,
|
||||
unsigned size,
|
||||
bool rollDate = true); // Backwards compatibility
|
||||
void LoggerInit(const char *programName);
|
||||
|
||||
~Logger();
|
||||
void addLog(const char *id, unsigned logenum, int level, unsigned size);
|
||||
void addLog(const char *id, unsigned logenum);
|
||||
void removeLog(unsigned logenum);
|
||||
void updateLog(unsigned logenum, int level, unsigned size);
|
||||
void logSimple(unsigned logenum, int level, const char *message);
|
||||
void logSimpleWithSys(unsigned logenum, unsigned priority, int level, const char *message);
|
||||
void logWithSys(unsigned logenum, unsigned priority, int level, const char *message, ...);
|
||||
void log(unsigned logenum, int level, const char *message, ...);
|
||||
|
||||
void flushAll();
|
||||
void flush(unsigned logenum);
|
||||
unsigned long getLogRolloverSize() { return m_logRolloverSize; }
|
||||
void setLogRolloverSize(unsigned long maxLogSize) { m_logRolloverSize = maxLogSize; }
|
||||
ELogType getLoggingType(unsigned logLevel) const;
|
||||
void setLoggingType(unsigned logLevel, ELogType logType);
|
||||
|
||||
private:
|
||||
void rollDate(time_t now);
|
||||
void cmkdir(const char *dir, int mode);
|
||||
void rollLog(LogInfo *logInfo);
|
||||
void checkLogRoll(LogInfo *logInfo, unsigned long lenToAdd);
|
||||
|
||||
unsigned m_defaultLevel;
|
||||
unsigned m_defaultSize;
|
||||
std::string m_lastDateText;
|
||||
tm m_lastDateTime;
|
||||
std::map<unsigned, LogInfo *> m_logTable;
|
||||
std::string m_logPrefix;
|
||||
std::string m_dirPrefix;
|
||||
#if defined (_REENTRANT) || defined (_MT)
|
||||
Base::CMutex rLock;
|
||||
#endif
|
||||
bool m_rollDate;
|
||||
unsigned long m_logRolloverSize;
|
||||
std::map<unsigned, ELogType> m_logLevelToTypeMap;
|
||||
ELogType m_combinedLogType;
|
||||
bool m_opennedSyslog;
|
||||
};
|
||||
|
||||
extern const char file_sep;
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,325 @@
|
||||
// MD5.cpp: implementation of the MD5 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "MD5.h"
|
||||
#include "Types.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
|
||||
MD5::State::State() :
|
||||
state(4,0),
|
||||
count(2,0),
|
||||
buffer(64,0)
|
||||
{
|
||||
state[0] = 0x67452301;
|
||||
state[1] = 0xefcdab89;
|
||||
state[2] = 0x98badcfe;
|
||||
state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
static char const init[64] =
|
||||
{
|
||||
-128, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
vector<char> MD5::padding(init,init+sizeof(init)/sizeof(init[0]));
|
||||
|
||||
MD5::MD5()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
MD5::MD5(const string & input)
|
||||
{
|
||||
Init();
|
||||
Update(input);
|
||||
}
|
||||
|
||||
vector<int> MD5::Decode(vector<char> achar0, int i, int j)
|
||||
{
|
||||
vector<int> ai(16,0);
|
||||
int l;
|
||||
int k = l = 0;
|
||||
for(; l < i; l += 4)
|
||||
{
|
||||
ai[k] = achar0[l + j] & 0xff | (achar0[l + 1 + j] & 0xff) << 8 | (achar0[l + 2 + j] & 0xff) << 16 | (achar0[l + 3 + j] & 0xff) << 24;
|
||||
k++;
|
||||
}
|
||||
|
||||
return ai;
|
||||
}
|
||||
|
||||
vector<char> MD5::Encode(vector<int> ai, int i)
|
||||
{
|
||||
vector<char> achar0(i,0);
|
||||
int k;
|
||||
int j = k = 0;
|
||||
for(; k < i; k += 4){
|
||||
achar0[k] = (char)(ai[j] & 0xff);
|
||||
achar0[k + 1] = (char)(ai[j] >> 8 & 0xff);
|
||||
achar0[k + 2] = (char)(ai[j] >> 16 & 0xff);
|
||||
achar0[k + 3] = (char)(ai[j] >> 24 & 0xff);
|
||||
j++;
|
||||
}
|
||||
|
||||
return achar0;
|
||||
}
|
||||
|
||||
int MD5::FF(int i, int j, int k, int l, int i1, int j1, int k1)
|
||||
{
|
||||
i = uadd(i, j & k | ~j & l, i1, k1);
|
||||
return uadd(rotate_left(i, j1), j);
|
||||
}
|
||||
|
||||
vector<char> MD5::Final()
|
||||
{
|
||||
if (finalsNull)
|
||||
{
|
||||
State &state1 = state;
|
||||
vector<char> achar0 = Encode(state1.count, 8);
|
||||
int i = state1.count[0] >> 3 & 0x3f;
|
||||
int j = i >= 56 ? 120 - i : 56 - i;
|
||||
Update(state1, padding, 0, j);
|
||||
Update(state1, achar0, 0, 8);
|
||||
finals = state1;
|
||||
finalsNull = false;
|
||||
}
|
||||
return Encode(finals.state, 16);
|
||||
}
|
||||
|
||||
int MD5::GG(int i, int j, int k, int l, int i1, int j1, int k1)
|
||||
{
|
||||
i = uadd(i, j & l | k & ~l, i1, k1);
|
||||
return uadd(rotate_left(i, j1), j);
|
||||
}
|
||||
|
||||
int MD5::HH(int i, int j, int k, int l, int i1, int j1, int k1)
|
||||
{
|
||||
i = uadd(i, j ^ k ^ l, i1, k1);
|
||||
return uadd(rotate_left(i, j1), j);
|
||||
}
|
||||
|
||||
int MD5::II(int i, int j, int k, int l, int i1, int j1, int k1)
|
||||
{
|
||||
i = uadd(i, k ^ (j | ~l), i1, k1);
|
||||
return uadd(rotate_left(i, j1), j);
|
||||
}
|
||||
|
||||
void MD5::Init()
|
||||
{
|
||||
if (padding.size() == 0)
|
||||
{
|
||||
padding.resize(64,0);
|
||||
padding[0] = -128;
|
||||
}
|
||||
finalsNull = true;
|
||||
}
|
||||
|
||||
void MD5::Transform(State & state1, vector<char> achar0, int i)
|
||||
{
|
||||
int j = state1.state[0];
|
||||
int k = state1.state[1];
|
||||
int l = state1.state[2];
|
||||
int i1 = state1.state[3];
|
||||
vector<int> ai = Decode(achar0, 64, i);
|
||||
j = FF(j, k, l, i1, ai[0], 7, 0xd76aa478);
|
||||
i1 = FF(i1, j, k, l, ai[1], 12, 0xe8c7b756);
|
||||
l = FF(l, i1, j, k, ai[2], 17, 0x242070db);
|
||||
k = FF(k, l, i1, j, ai[3], 22, 0xc1bdceee);
|
||||
j = FF(j, k, l, i1, ai[4], 7, 0xf57c0faf);
|
||||
i1 = FF(i1, j, k, l, ai[5], 12, 0x4787c62a);
|
||||
l = FF(l, i1, j, k, ai[6], 17, 0xa8304613);
|
||||
k = FF(k, l, i1, j, ai[7], 22, 0xfd469501);
|
||||
j = FF(j, k, l, i1, ai[8], 7, 0x698098d8);
|
||||
i1 = FF(i1, j, k, l, ai[9], 12, 0x8b44f7af);
|
||||
l = FF(l, i1, j, k, ai[10], 17, -42063);
|
||||
k = FF(k, l, i1, j, ai[11], 22, 0x895cd7be);
|
||||
j = FF(j, k, l, i1, ai[12], 7, 0x6b901122);
|
||||
i1 = FF(i1, j, k, l, ai[13], 12, 0xfd987193);
|
||||
l = FF(l, i1, j, k, ai[14], 17, 0xa679438e);
|
||||
k = FF(k, l, i1, j, ai[15], 22, 0x49b40821);
|
||||
j = GG(j, k, l, i1, ai[1], 5, 0xf61e2562);
|
||||
i1 = GG(i1, j, k, l, ai[6], 9, 0xc040b340);
|
||||
l = GG(l, i1, j, k, ai[11], 14, 0x265e5a51);
|
||||
k = GG(k, l, i1, j, ai[0], 20, 0xe9b6c7aa);
|
||||
j = GG(j, k, l, i1, ai[5], 5, 0xd62f105d);
|
||||
i1 = GG(i1, j, k, l, ai[10], 9, 0x2441453);
|
||||
l = GG(l, i1, j, k, ai[15], 14, 0xd8a1e681);
|
||||
k = GG(k, l, i1, j, ai[4], 20, 0xe7d3fbc8);
|
||||
j = GG(j, k, l, i1, ai[9], 5, 0x21e1cde6);
|
||||
i1 = GG(i1, j, k, l, ai[14], 9, 0xc33707d6);
|
||||
l = GG(l, i1, j, k, ai[3], 14, 0xf4d50d87);
|
||||
k = GG(k, l, i1, j, ai[8], 20, 0x455a14ed);
|
||||
j = GG(j, k, l, i1, ai[13], 5, 0xa9e3e905);
|
||||
i1 = GG(i1, j, k, l, ai[2], 9, 0xfcefa3f8);
|
||||
l = GG(l, i1, j, k, ai[7], 14, 0x676f02d9);
|
||||
k = GG(k, l, i1, j, ai[12], 20, 0x8d2a4c8a);
|
||||
j = HH(j, k, l, i1, ai[5], 4, 0xfffa3942);
|
||||
i1 = HH(i1, j, k, l, ai[8], 11, 0x8771f681);
|
||||
l = HH(l, i1, j, k, ai[11], 16, 0x6d9d6122);
|
||||
k = HH(k, l, i1, j, ai[14], 23, 0xfde5380c);
|
||||
j = HH(j, k, l, i1, ai[1], 4, 0xa4beea44);
|
||||
i1 = HH(i1, j, k, l, ai[4], 11, 0x4bdecfa9);
|
||||
l = HH(l, i1, j, k, ai[7], 16, 0xf6bb4b60);
|
||||
k = HH(k, l, i1, j, ai[10], 23, 0xbebfbc70);
|
||||
j = HH(j, k, l, i1, ai[13], 4, 0x289b7ec6);
|
||||
i1 = HH(i1, j, k, l, ai[0], 11, 0xeaa127fa);
|
||||
l = HH(l, i1, j, k, ai[3], 16, 0xd4ef3085);
|
||||
k = HH(k, l, i1, j, ai[6], 23, 0x4881d05);
|
||||
j = HH(j, k, l, i1, ai[9], 4, 0xd9d4d039);
|
||||
i1 = HH(i1, j, k, l, ai[12], 11, 0xe6db99e5);
|
||||
l = HH(l, i1, j, k, ai[15], 16, 0x1fa27cf8);
|
||||
k = HH(k, l, i1, j, ai[2], 23, 0xc4ac5665);
|
||||
j = II(j, k, l, i1, ai[0], 6, 0xf4292244);
|
||||
i1 = II(i1, j, k, l, ai[7], 10, 0x432aff97);
|
||||
l = II(l, i1, j, k, ai[14], 15, 0xab9423a7);
|
||||
k = II(k, l, i1, j, ai[5], 21, 0xfc93a039);
|
||||
j = II(j, k, l, i1, ai[12], 6, 0x655b59c3);
|
||||
i1 = II(i1, j, k, l, ai[3], 10, 0x8f0ccc92);
|
||||
l = II(l, i1, j, k, ai[10], 15, 0xffeff47d);
|
||||
k = II(k, l, i1, j, ai[1], 21, 0x85845dd1);
|
||||
j = II(j, k, l, i1, ai[8], 6, 0x6fa87e4f);
|
||||
i1 = II(i1, j, k, l, ai[15], 10, 0xfe2ce6e0);
|
||||
l = II(l, i1, j, k, ai[6], 15, 0xa3014314);
|
||||
k = II(k, l, i1, j, ai[13], 21, 0x4e0811a1);
|
||||
j = II(j, k, l, i1, ai[4], 6, 0xf7537e82);
|
||||
i1 = II(i1, j, k, l, ai[11], 10, 0xbd3af235);
|
||||
l = II(l, i1, j, k, ai[2], 15, 0x2ad7d2bb);
|
||||
k = II(k, l, i1, j, ai[9], 21, 0xeb86d391);
|
||||
state1.state[0] += j;
|
||||
state1.state[1] += k;
|
||||
state1.state[2] += l;
|
||||
state1.state[3] += i1;
|
||||
}
|
||||
|
||||
void MD5::Update(char char0)
|
||||
{
|
||||
vector<char> achar0(1,0);
|
||||
achar0[0] = char0;
|
||||
Update(achar0, 1);
|
||||
}
|
||||
|
||||
void MD5::Update(State & state1, vector<char> achar0, int i, int j)
|
||||
{
|
||||
finalsNull = true;
|
||||
if (j - i > (int)achar0.size())
|
||||
j = achar0.size() - i;
|
||||
int k = state1.count[0] >> 3 & 0x3f;
|
||||
if ((state1.count[0] += j << 3) < j << 3)
|
||||
state1.count[1]++;
|
||||
state1.count[1] += j >> 29;
|
||||
int l = 64 - k;
|
||||
int j1;
|
||||
if(j >= l)
|
||||
{
|
||||
for(int i1 = 0; i1 < l; i1++)
|
||||
state1.buffer[i1 + k] = achar0[i1 + i];
|
||||
|
||||
Transform(state1, state1.buffer, 0);
|
||||
for(j1 = l; j1 + 63 < j; j1 += 64)
|
||||
Transform(state1, achar0, j1);
|
||||
|
||||
k = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
j1 = 0;
|
||||
}
|
||||
if (j1 < j)
|
||||
{
|
||||
int k1 = j1;
|
||||
for(; j1 < j; j1++)
|
||||
state1.buffer[(k + j1) - k1] = achar0[j1 + i];
|
||||
}
|
||||
}
|
||||
|
||||
void MD5::Update(string s)
|
||||
{
|
||||
vector<char> achar(s.size(),0);
|
||||
for (int i=0; i<(int)s.size(); i++)
|
||||
achar[i] = s[i];
|
||||
Update( achar, achar.size() );
|
||||
}
|
||||
|
||||
void MD5::Update(vector<char> achar0)
|
||||
{
|
||||
Update(achar0, 0, achar0.size());
|
||||
}
|
||||
|
||||
void MD5::Update(vector<char> achar0, int i)
|
||||
{
|
||||
Update(state, achar0, 0, i);
|
||||
}
|
||||
|
||||
void MD5::Update(vector<char> achar0, int i, int j)
|
||||
{
|
||||
Update(state, achar0, i, j);
|
||||
}
|
||||
|
||||
string MD5::asHex()
|
||||
{
|
||||
return asHex(Final());
|
||||
}
|
||||
|
||||
string MD5::asHex(vector<char> achar0)
|
||||
{
|
||||
const string hex = "0123456789abcdef";
|
||||
|
||||
string stringbuffer;
|
||||
for (int i = 0; i < (int)achar0.size(); i++)
|
||||
{
|
||||
stringbuffer += hex.substr((achar0[i] >> 4) & 0x0f,1);
|
||||
stringbuffer += hex.substr(achar0[i] & 0x0f,1);
|
||||
}
|
||||
|
||||
return stringbuffer;
|
||||
}
|
||||
|
||||
int MD5::rotate_left(int i, int j)
|
||||
{
|
||||
unsigned i1 = i;
|
||||
unsigned j1 = j;
|
||||
return i1 << j1 | i1 >> (32 - j1);
|
||||
}
|
||||
|
||||
int MD5::uadd(int i, int j)
|
||||
{
|
||||
int64 l = (int64)i & 0x0ffffffffL;
|
||||
int64 l1 = (int64)j & 0x0ffffffffL;
|
||||
l += l1;
|
||||
return (int)(l & 0x0ffffffffL);
|
||||
}
|
||||
|
||||
int MD5::uadd(int i, int j, int k)
|
||||
{
|
||||
return uadd(uadd(i, j), k);
|
||||
}
|
||||
|
||||
int MD5::uadd(int i, int j, int k, int l)
|
||||
{
|
||||
return uadd(uadd(i, j, k), l);
|
||||
}
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
// MD5.h: interface for the MD5 class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef MD5_H
|
||||
#define MD5_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
|
||||
class MD5
|
||||
{
|
||||
struct State
|
||||
{
|
||||
State();
|
||||
|
||||
std::vector<int> state;
|
||||
std::vector<int> count;
|
||||
std::vector<char> buffer;
|
||||
};
|
||||
|
||||
public:
|
||||
MD5::MD5();
|
||||
MD5(const std::string &input);
|
||||
|
||||
void Init();
|
||||
std::vector<char> Final();
|
||||
void Update(char char0);
|
||||
void Update(State & state1, std::vector<char> achar0, int i, int j);
|
||||
void Update(std::string s);
|
||||
void Update(std::vector<char> achar0);
|
||||
void Update(std::vector<char> achar0, int i);
|
||||
void Update(std::vector<char> achar0, int i, int j);
|
||||
std::string asHex();
|
||||
static std::string asHex(std::vector<char> achar0);
|
||||
|
||||
private:
|
||||
std::vector<int> Decode(std::vector<char> achar0, int i, int j);
|
||||
std::vector<char> Encode(std::vector<int> ai, int i);
|
||||
int FF(int i, int j, int k, int l, int i1, int j1, int k1);
|
||||
int GG(int i, int j, int k, int l, int i1, int j1, int k1);
|
||||
int HH(int i, int j, int k, int l, int i1, int j1, int k1);
|
||||
int II(int i, int j, int k, int l, int i1, int j1, int k1);
|
||||
void Transform(State & state1, std::vector<char> achar0, int i);
|
||||
int rotate_left(int i, int j);
|
||||
int uadd(int i, int j);
|
||||
int uadd(int i, int j, int k);
|
||||
int uadd(int i, int j, int k, int l);
|
||||
|
||||
private:
|
||||
State state;
|
||||
State finals;
|
||||
bool finalsNull;
|
||||
static std::vector<char> padding;
|
||||
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#endif // MD5_H
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef BASE_MUTEX_H
|
||||
#define BASE_MUTEX_H
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "win32/Mutex.h"
|
||||
|
||||
#elif linux
|
||||
|
||||
#include "linux/Mutex.h"
|
||||
|
||||
#elif sparc
|
||||
|
||||
#include "solaris/Mutex.h"
|
||||
|
||||
#else
|
||||
|
||||
#error /Base/Mutex.h: Undefine platform type
|
||||
|
||||
#endif
|
||||
|
||||
#endif // BASE_MUTEX_H
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
#ifndef BASE_PLATFORM_H
|
||||
#define BASE_PLATFORM_H
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
#include "win32/Platform.h"
|
||||
#elif linux
|
||||
#include "linux/Platform.h"
|
||||
#elif sparc
|
||||
#include "solaris/Platform.h"
|
||||
#else
|
||||
#error /Base/Platform.h: Undefine platform type
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
|
||||
template <class T> inline T rotlFixed(T x, unsigned int y)
|
||||
{
|
||||
assert(y < sizeof(T)*8);
|
||||
return (T)((x<<y) | (x>>(sizeof(T)*8-y)));
|
||||
}
|
||||
|
||||
template <class T> inline T rotrFixed(T x, unsigned int y)
|
||||
{
|
||||
assert(y < sizeof(T)*8);
|
||||
return (x>>y) | (x<<(sizeof(T)*8-y));
|
||||
}
|
||||
|
||||
template <class T> inline T rotlMod(T x, unsigned int y)
|
||||
{
|
||||
y %= sizeof(T)*8;
|
||||
return (x<<y) | (x>>(sizeof(T)*8-y));
|
||||
}
|
||||
|
||||
template <class T> inline T rotrMod(T x, unsigned int y)
|
||||
{
|
||||
y %= sizeof(T)*8;
|
||||
return (x>>y) | (x<<(sizeof(T)*8-y));
|
||||
}
|
||||
|
||||
inline uint16 byteReverse16(void * data)
|
||||
{
|
||||
uint16 value = *static_cast<uint16 *>(data);
|
||||
return *static_cast<uint16 *>(data) = rotlFixed(value, 8U);
|
||||
// return rotlFixed(value, 8U);
|
||||
}
|
||||
|
||||
inline uint32 byteReverse32(void * data)
|
||||
{
|
||||
uint32 value = *static_cast<uint32 *>(data);
|
||||
return *static_cast<uint32 *>(data) = (rotrFixed(value, 8U) & 0xff00ff00) | (rotlFixed(value, 8U) & 0x00ff00ff);
|
||||
// return (rotrFixed(value, 8U) & 0xff00ff00) | (rotlFixed(value, 8U) & 0x00ff00ff);
|
||||
}
|
||||
inline uint64 byteReverse64(void * data)
|
||||
{
|
||||
uint64 value = *static_cast<uint64 *>(data);
|
||||
return *static_cast<uint64 *>(data) = (
|
||||
uint64((rotrFixed(uint32(value), 8U) & 0xff00ff00) | (rotlFixed(uint32(value), 8U) & 0x00ff00ff)) << 32) |
|
||||
(rotrFixed(uint32(value>>32), 8U) & 0xff00ff00) | (rotlFixed(uint32(value>>32), 8U) & 0x00ff00ff);
|
||||
// return (uint64(byteReverse(uint32(value))) << 32) | byteReverse(uint32(value>>32));
|
||||
}
|
||||
|
||||
inline uint32 strlen(const unsigned short * string)
|
||||
{
|
||||
if (string == 0)
|
||||
return 0;
|
||||
|
||||
uint32 length=0;
|
||||
while (*(string+length++) != 0);
|
||||
|
||||
return length-1;
|
||||
}
|
||||
|
||||
inline double getTimerLatency(Base::uint64 startTime, Base::uint64 finishTime=0)
|
||||
{
|
||||
Base::int64 requestAge;
|
||||
Base::int64 freq = Base::getTimerFrequency();
|
||||
Base::uint64 finish = (finishTime ? finishTime : Base::getTimer());
|
||||
if (finish < startTime)
|
||||
requestAge = (0 - 1) - startTime - finish;
|
||||
else
|
||||
requestAge = finish - startTime;
|
||||
return (double)requestAge/freq;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#endif // BASE_PLATFORM_H
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "ScopeLock.h"
|
||||
|
||||
#ifdef INCLUDE_SCOPELOCK
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
CScopeLock::CScopeLock(CMutex& mutex) :
|
||||
mMutex(&mutex)
|
||||
{
|
||||
mMutex->Lock();
|
||||
}
|
||||
|
||||
CScopeLock::CScopeLock(CScopeLock& lock) :
|
||||
mMutex(lock.mMutex)
|
||||
{
|
||||
mMutex->Lock();
|
||||
}
|
||||
|
||||
CScopeLock::~CScopeLock()
|
||||
{
|
||||
mMutex->Unlock();
|
||||
}
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // INCLUDE_SCOPELOCK
|
||||
@@ -0,0 +1,40 @@
|
||||
// ScopeLock.h: interface for the CScopeLock class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SCOPELOCK_H
|
||||
#define SCOPELOCK_H
|
||||
|
||||
#if defined _MT || defined _REENTRANT
|
||||
# define INCLUDE_SCOPELOCK
|
||||
#endif
|
||||
|
||||
#ifdef INCLUDE_SCOPELOCK
|
||||
|
||||
#include "Mutex.h"
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
class CScopeLock
|
||||
{
|
||||
public:
|
||||
CScopeLock(CMutex& mutex);
|
||||
CScopeLock(CScopeLock& lock);
|
||||
virtual ~CScopeLock();
|
||||
|
||||
private:
|
||||
CMutex *mMutex;
|
||||
};
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // INCLUDE_SCOPELOCK
|
||||
|
||||
#endif // SCOPELOCK_H
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "Statistics.h"
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
|
||||
CStatisticTimer::CStatisticTimer(bool running) :
|
||||
mTotal(0),
|
||||
mStart(getTimer()),
|
||||
mRunning(running)
|
||||
{
|
||||
}
|
||||
|
||||
double CStatisticTimer::GetTime()
|
||||
{
|
||||
uint64 total = mTotal;
|
||||
|
||||
if (mRunning)
|
||||
total += getTimer()-mStart;
|
||||
|
||||
return (double)((int64)(total/getTimerFrequency()));
|
||||
}
|
||||
|
||||
uint64 CStatisticTimer::GetFraction(uint32 fraction)
|
||||
{
|
||||
uint64 total = mTotal;
|
||||
|
||||
if (mRunning)
|
||||
total += getTimer()-mStart;
|
||||
|
||||
if (fraction == 0)
|
||||
return total;
|
||||
else
|
||||
return total/(getTimerFrequency()/fraction);
|
||||
}
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
#ifndef STATISTICS_H
|
||||
#define STATISTICS_H
|
||||
|
||||
#include <time.h>
|
||||
#include "Platform.h"
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
template <class TYPE, uint32 COUNT>
|
||||
class CStatistic
|
||||
{
|
||||
public:
|
||||
CStatistic(uint32 freq=0) :
|
||||
mSampleFrequency(freq),
|
||||
mLastSampleTime(0),
|
||||
mSample(0),
|
||||
mSampleTotal(0),
|
||||
mAggregateTotal(0),
|
||||
mAggregateMaximum(0),
|
||||
mAggregateMinimum(0),
|
||||
mAverageTotal(0),
|
||||
mAverageIndex(0),
|
||||
mAverageCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
bool Sample(TYPE value)
|
||||
{
|
||||
bool commit = false;
|
||||
|
||||
if (!mLastSampleTime)
|
||||
mLastSampleTime = time(NULL);
|
||||
|
||||
if (!mSampleFrequency || mLastSampleTime + mSampleFrequency < (unsigned)time(NULL))
|
||||
{
|
||||
mSampleTotal++;
|
||||
mAggregateTotal += value;
|
||||
if (value > mAggregateMaximum)
|
||||
mAggregateMaximum = value;
|
||||
if (value < mAggregateMinimum)
|
||||
mAggregateMinimum = value;
|
||||
|
||||
if (mAverageIndex == COUNT)
|
||||
mAverageIndex = 0;
|
||||
if (mAverageCount > COUNT)
|
||||
mAverageTotal -= mAverageData[mAverageIndex];
|
||||
|
||||
mAverageData[mAverageIndex++] = value;
|
||||
mAverageTotal += value;
|
||||
|
||||
if (mAverageCount < COUNT)
|
||||
mAverageCount++;
|
||||
|
||||
commit = true;
|
||||
mSample = 0;
|
||||
}
|
||||
|
||||
mSample += value;
|
||||
|
||||
return commit;
|
||||
}
|
||||
|
||||
TYPE GetSample(uint32 age = 0)
|
||||
{
|
||||
if (age > mAverageCount)
|
||||
return 0;
|
||||
|
||||
uint32 index = mAverageIndex;
|
||||
if (age > index)
|
||||
index = COUNT - (age - index);
|
||||
else
|
||||
index -= age;
|
||||
|
||||
return mAverageData[index];
|
||||
}
|
||||
|
||||
double GetAverage()
|
||||
{
|
||||
return (double)mAverageTotal/mAverageCount;
|
||||
}
|
||||
|
||||
double GetAggregateAverage()
|
||||
{
|
||||
return (double)mAggregateTotal/mSampleTotal;
|
||||
}
|
||||
|
||||
TYPE GetMaximum()
|
||||
{
|
||||
return mAggregateMaximum;
|
||||
}
|
||||
|
||||
TYPE GetMinimum()
|
||||
{
|
||||
return mAggregateMinimum;
|
||||
}
|
||||
|
||||
private:
|
||||
uint32 mSampleFrequency;
|
||||
time_t mLastSampleTime;
|
||||
TYPE mSample;
|
||||
uint32 mSampleTotal;
|
||||
TYPE mAggregateTotal;
|
||||
TYPE mAggregateMaximum;
|
||||
TYPE mAggregateMinimum;
|
||||
|
||||
TYPE mAverageData[COUNT];
|
||||
TYPE mAverageTotal;
|
||||
uint32 mAverageIndex;
|
||||
uint32 mAverageCount;
|
||||
};
|
||||
|
||||
class CStatisticTimer
|
||||
{
|
||||
public:
|
||||
CStatisticTimer(bool running = true);
|
||||
|
||||
void Start() { if (mRunning) return; mStart = getTimer(); mRunning = true; }
|
||||
void Stop() { if (!mRunning) return; mTotal += getTimer()-mStart; mRunning = false; }
|
||||
void Reset() { mTotal = 0; mStart = getTimer(); }
|
||||
|
||||
double GetTime();
|
||||
uint64 GetFraction(uint32 fraction=1000);
|
||||
|
||||
private:
|
||||
uint64 mTotal;
|
||||
uint64 mStart;
|
||||
bool mRunning;
|
||||
};
|
||||
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // STATISTICS_H
|
||||
+238
@@ -0,0 +1,238 @@
|
||||
#ifndef BLOCK_ALLOCATOR_H
|
||||
#define BLOCK_ALLOCATOR_H
|
||||
|
||||
#if defined _MT || defined _REENTRANT
|
||||
# define USE_ALLOCATOR_MUTEX
|
||||
#endif
|
||||
|
||||
|
||||
#include <new>
|
||||
#include "Mutex.h"
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
template<int BLOCK_SIZE>
|
||||
class CBlockAllocator
|
||||
{
|
||||
|
||||
private:
|
||||
class Node
|
||||
{
|
||||
public:
|
||||
Node * mNext;
|
||||
unsigned mBuffer[(BLOCK_SIZE-1)/sizeof(unsigned)+1];
|
||||
};
|
||||
|
||||
public:
|
||||
CBlockAllocator() :
|
||||
mMemoryBlockCount(0),
|
||||
mNodesAllocated(0),
|
||||
mNodesUsed(0),
|
||||
mUnusedList(0)
|
||||
{
|
||||
for (int block=0; block<MAX_BLOCK_COUNT; block++)
|
||||
mMemoryBlock[block] = 0;
|
||||
Allocate();
|
||||
}
|
||||
|
||||
~CBlockAllocator()
|
||||
{
|
||||
for (int block=0; block<MAX_BLOCK_COUNT; block++)
|
||||
delete[] mMemoryBlock[block];
|
||||
}
|
||||
|
||||
void * Allocate()
|
||||
{
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Lock();
|
||||
#endif
|
||||
void * data;
|
||||
|
||||
Node * node = mUnusedList;
|
||||
mUnusedList = node->mNext;
|
||||
node->mNext = (Node *)1;
|
||||
|
||||
data = node->mBuffer;
|
||||
|
||||
mNodesUsed++;
|
||||
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Unlock();
|
||||
#endif
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
void Deallocate(void * data)
|
||||
{
|
||||
if (!data)
|
||||
return;
|
||||
|
||||
char * memoryPtr = reinterpret_cast<char *>(data) - sizeof(Node *);
|
||||
Node * node = reinterpret_cast<Node *>(memoryPtr);
|
||||
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Lock();
|
||||
#endif
|
||||
|
||||
node->mNext = mUnusedList;
|
||||
mUnusedList = node;
|
||||
mNodesUsed--;
|
||||
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T> T * Construct(const T & object)
|
||||
{
|
||||
T * objectPtr;
|
||||
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Lock();
|
||||
#endif
|
||||
if (sizeof(T) > BLOCK_SIZE || (!mUnusedList && !Allocate()))
|
||||
{
|
||||
char * memoryPtr = reinterpret_cast<char *>(new unsigned[(sizeof(Node *)+sizeof(T)-1)/sizeof(unsigned)+1]);
|
||||
objectPtr = reinterpret_cast<T *>(memoryPtr+sizeof(Node *));
|
||||
|
||||
*reinterpret_cast<unsigned *>(memoryPtr) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Node * node = mUnusedList;
|
||||
mUnusedList = node->mNext;
|
||||
node->mNext = (Node *)1;
|
||||
|
||||
objectPtr = reinterpret_cast<T *>(node->mBuffer);
|
||||
|
||||
mNodesUsed++;
|
||||
}
|
||||
|
||||
new (objectPtr) T(object);
|
||||
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Unlock();
|
||||
#endif
|
||||
return objectPtr;
|
||||
}
|
||||
|
||||
template<class T> void Destroy(T * object)
|
||||
{
|
||||
if (!object)
|
||||
return;
|
||||
|
||||
char * memoryPtr = reinterpret_cast<char *>(object) - sizeof(Node *);
|
||||
Node * node = reinterpret_cast<Node *>(memoryPtr);
|
||||
|
||||
object->~T();
|
||||
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Lock();
|
||||
#endif
|
||||
if (node->mNext == 0)
|
||||
delete []memoryPtr;
|
||||
else
|
||||
{
|
||||
node->mNext = mUnusedList;
|
||||
mUnusedList = node;
|
||||
mNodesUsed--;
|
||||
}
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
template<class T> T * FastConstruct(const T & object)
|
||||
{
|
||||
T * objectPtr;
|
||||
|
||||
if (sizeof(T) > BLOCK_SIZE || (!mUnusedList && !Allocate()))
|
||||
{
|
||||
char * memoryPtr = reinterpret_cast<char *>(new unsigned[(sizeof(Node *)+sizeof(T)-1)/sizeof(unsigned)+1]);
|
||||
objectPtr = reinterpret_cast<T *>(memoryPtr+sizeof(Node *));
|
||||
|
||||
*reinterpret_cast<unsigned *>(memoryPtr) = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
Node * node = mUnusedList;
|
||||
mUnusedList = node->mNext;
|
||||
node->mNext = (Node *)1;
|
||||
|
||||
objectPtr = reinterpret_cast<T *>(node->mBuffer);
|
||||
|
||||
mNodesUsed++;
|
||||
}
|
||||
|
||||
new (objectPtr) T(object);
|
||||
|
||||
return objectPtr;
|
||||
}
|
||||
|
||||
template<class T> void FastDestroy(T * object)
|
||||
{
|
||||
if (!object)
|
||||
return;
|
||||
|
||||
char * memoryPtr = reinterpret_cast<char *>(object) - sizeof(Node *);
|
||||
Node * node = reinterpret_cast<Node *>(memoryPtr);
|
||||
|
||||
object->~T();
|
||||
|
||||
if (node->mNext == 0)
|
||||
delete []memoryPtr;
|
||||
else
|
||||
{
|
||||
node->mNext = mUnusedList;
|
||||
mUnusedList = node;
|
||||
mNodesUsed--;
|
||||
}
|
||||
}
|
||||
|
||||
bool Allocate()
|
||||
{
|
||||
if (mMemoryBlockCount == MAX_BLOCK_COUNT)
|
||||
return false;
|
||||
|
||||
unsigned count = (mNodesAllocated ? mNodesAllocated : 32);
|
||||
|
||||
Node* newMemoryBlock = new Node[count];
|
||||
for (unsigned i=0; i<count-1; i++)
|
||||
newMemoryBlock[i].mNext = &newMemoryBlock[i+1];
|
||||
newMemoryBlock[count-1].mNext = mUnusedList;
|
||||
|
||||
mUnusedList = newMemoryBlock;
|
||||
mMemoryBlock[mMemoryBlockCount++] = newMemoryBlock;
|
||||
mNodesAllocated += count;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
private:
|
||||
enum { MAX_BLOCK_COUNT = 32 };
|
||||
|
||||
void * mMemoryBlock[MAX_BLOCK_COUNT];
|
||||
unsigned mMemoryBlockCount;
|
||||
unsigned mNodesAllocated;
|
||||
unsigned mNodesUsed;
|
||||
Node * mUnusedList;
|
||||
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
Base::CMutex mMutex;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // BLOCK_ALLOCATOR_H
|
||||
+200
@@ -0,0 +1,200 @@
|
||||
// TemplateCBlockAlloc.h: interface for the CBlockAlloc class.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _TEMPLATE_COBJECTALLOCATOR_H
|
||||
#define _TEMPLATE_COBJECTALLOCATOR_H
|
||||
|
||||
#if defined _MT || defined _REENTRANT
|
||||
# define USE_ALLOCATOR_MUTEX
|
||||
#endif
|
||||
|
||||
|
||||
#include <new>
|
||||
#include "Types.h"
|
||||
#include "Mutex.h"
|
||||
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
namespace NAMESPACE
|
||||
{
|
||||
|
||||
#endif
|
||||
namespace Base
|
||||
{
|
||||
const uint32 MAX_BLOCK_COUNT = 32;
|
||||
|
||||
template <class TYPE>
|
||||
class CObjectAllocator
|
||||
{
|
||||
public:
|
||||
CObjectAllocator(uint32 size=32)
|
||||
{
|
||||
if (size < 32)
|
||||
size = 32;
|
||||
|
||||
for (uint32 index=0; index<MAX_BLOCK_COUNT; index++)
|
||||
mMemoryBlock[index] = 0;
|
||||
|
||||
mMemoryBlockCount = 0;
|
||||
mObjectsAllocated = 0;
|
||||
mObjectCount = 0;
|
||||
mUnusedList = 0;
|
||||
|
||||
mBytesAllocated = 0;
|
||||
|
||||
Allocate(size);
|
||||
}
|
||||
|
||||
~CObjectAllocator()
|
||||
{
|
||||
for (uint32 index=0; index<MAX_BLOCK_COUNT; index++)
|
||||
delete[] mMemoryBlock[index];
|
||||
}
|
||||
|
||||
TYPE *Construct()
|
||||
{
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Lock();
|
||||
#endif
|
||||
if (!mUnusedList)
|
||||
Allocate(mObjectCount);
|
||||
|
||||
Node *node = mUnusedList;
|
||||
mUnusedList = mUnusedList->next;
|
||||
|
||||
new (node) TYPE;
|
||||
|
||||
mObjectCount++;
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Unlock();
|
||||
#endif
|
||||
return (TYPE *)node;
|
||||
}
|
||||
|
||||
TYPE *Construct(const TYPE& object)
|
||||
{
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Lock();
|
||||
#endif
|
||||
if (!mUnusedList)
|
||||
Allocate(mObjectCount);
|
||||
|
||||
Node *node = mUnusedList;
|
||||
mUnusedList = mUnusedList->next;
|
||||
|
||||
new (node) TYPE(object);
|
||||
|
||||
mObjectCount++;
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Unlock();
|
||||
#endif
|
||||
return (TYPE *)node;
|
||||
}
|
||||
|
||||
void Destroy(TYPE *object)
|
||||
{
|
||||
if (object == NULL)
|
||||
return;
|
||||
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Lock();
|
||||
#endif
|
||||
object->~TYPE();
|
||||
|
||||
Node *node = reinterpret_cast<Node *>(object);
|
||||
|
||||
node->next = mUnusedList;
|
||||
mUnusedList = node;
|
||||
|
||||
mObjectCount--;
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
mMutex.Unlock();
|
||||
#endif
|
||||
}
|
||||
|
||||
TYPE *FastConstruct()
|
||||
{
|
||||
if (!mUnusedList)
|
||||
Allocate(mObjectCount);
|
||||
|
||||
Node *node = mUnusedList;
|
||||
mUnusedList = mUnusedList->next;
|
||||
|
||||
new (node) TYPE;
|
||||
|
||||
mObjectCount++;
|
||||
return (TYPE *)node;
|
||||
}
|
||||
|
||||
TYPE *FastConstruct(const TYPE& object)
|
||||
{
|
||||
if (!mUnusedList)
|
||||
Allocate(mObjectCount);
|
||||
|
||||
Node *node = mUnusedList;
|
||||
mUnusedList = mUnusedList->next;
|
||||
|
||||
new (node) TYPE(object);
|
||||
|
||||
mObjectCount++;
|
||||
return (TYPE *)node;
|
||||
}
|
||||
|
||||
void FastDestroy(TYPE *object)
|
||||
{
|
||||
if (object == NULL)
|
||||
return;
|
||||
|
||||
object->~TYPE();
|
||||
|
||||
Node *node = reinterpret_cast<Node *>(object);
|
||||
|
||||
node->next = mUnusedList;
|
||||
mUnusedList = node;
|
||||
|
||||
mObjectCount--;
|
||||
}
|
||||
|
||||
private:
|
||||
struct Node
|
||||
{
|
||||
char buffer[sizeof(TYPE)];
|
||||
Node* next;
|
||||
};
|
||||
|
||||
bool Allocate(uint32 size)
|
||||
{
|
||||
if (mMemoryBlockCount == MAX_BLOCK_COUNT)
|
||||
return false;
|
||||
|
||||
Node* newMemoryBlock = new Node[size];
|
||||
mBytesAllocated += size * sizeof(Node);
|
||||
|
||||
for (uint32 i=0; i<size-1; i++)
|
||||
newMemoryBlock[i].next = &newMemoryBlock[i+1];
|
||||
newMemoryBlock[size-1].next = mUnusedList;
|
||||
|
||||
mUnusedList = newMemoryBlock;
|
||||
mMemoryBlock[mMemoryBlockCount++] = newMemoryBlock;
|
||||
mObjectsAllocated += size;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
Node* mMemoryBlock[MAX_BLOCK_COUNT];
|
||||
uint32 mMemoryBlockCount;
|
||||
uint32 mObjectsAllocated;
|
||||
uint32 mObjectCount;
|
||||
Node* mUnusedList;
|
||||
#ifdef USE_ALLOCATOR_MUTEX
|
||||
CMutex mMutex;
|
||||
#endif
|
||||
|
||||
uint64 mBytesAllocated;
|
||||
};
|
||||
};
|
||||
#ifdef EXTERNAL_DISTRO
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif // _TEMPLATE_CBLOCKALLOC_H
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef BASE_THREAD_H
|
||||
#define BASE_THREAD_H
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "win32/Thread.h"
|
||||
|
||||
#elif linux
|
||||
|
||||
#include "linux/Thread.h"
|
||||
|
||||
#elif sparc
|
||||
|
||||
#include "solaris/Thread.h"
|
||||
|
||||
#else
|
||||
|
||||
#error /Base/Thread.h: Undefine platform type
|
||||
|
||||
#endif
|
||||
|
||||
#endif // BASE_THREAD_H
|
||||
@@ -0,0 +1,29 @@
|
||||
#ifndef BASE_TYPES_H
|
||||
#define BASE_TYPES_H
|
||||
|
||||
#ifdef WIN32
|
||||
# define FILENAME (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
|
||||
#else
|
||||
# define FILENAME __FILE__
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
|
||||
#include "win32/Types.h"
|
||||
|
||||
#elif linux
|
||||
|
||||
#include "linux/Types.h"
|
||||
|
||||
#elif sparc
|
||||
|
||||
#include "solaris/Types.h"
|
||||
|
||||
#else
|
||||
|
||||
#error /Base/Types.h: Undefine platform type
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user