Added ChatServer and soePlatform

This commit is contained in:
Anonymous
2014-01-17 03:40:51 -07:00
parent 26b88b4533
commit 4fae2dfe0f
183 changed files with 64549 additions and 0 deletions
@@ -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;
}