From: <mua...@us...> - 2009-09-07 20:37:49
|
Revision: 33 http://polserver.svn.sourceforge.net/polserver/?rev=33&view=rev Author: muaddib_pol Date: 2009-09-07 20:37:38 +0000 (Mon, 07 Sep 2009) Log Message: ----------- + Network Code organized some. Baby steps, baby steps Modified Paths: -------------- trunk/pol-core/makefile.gcc trunk/pol-core/plib/realmfunc.cpp trunk/pol-core/pol/accounts/account.cpp trunk/pol-core/pol/accounts/acscrobj.cpp trunk/pol-core/pol/bowsalut.cpp trunk/pol-core/pol/clfunc.cpp trunk/pol-core/pol/containr.cpp trunk/pol-core/pol/core.cpp trunk/pol-core/pol/create.cpp trunk/pol-core/pol/dblclick.cpp trunk/pol-core/pol/door.cpp trunk/pol-core/pol/dropitem.cpp trunk/pol-core/pol/eqpitem.cpp trunk/pol-core/pol/getitem.cpp trunk/pol-core/pol/getmsg.cpp trunk/pol-core/pol/guardrgn.cpp trunk/pol-core/pol/help.cpp trunk/pol-core/pol/irequest.cpp trunk/pol-core/pol/item.cpp trunk/pol-core/pol/itemcr.cpp trunk/pol-core/pol/login.cpp trunk/pol-core/pol/menusel.cpp trunk/pol-core/pol/miscmsg.cpp trunk/pol-core/pol/mobile/attack.cpp trunk/pol-core/pol/mobile/charactr.cpp trunk/pol-core/pol/module/attributemod.cpp trunk/pol-core/pol/module/clmod.cpp trunk/pol-core/pol/module/npcmod.cpp trunk/pol-core/pol/module/osmod.cpp trunk/pol-core/pol/module/unimod.cpp trunk/pol-core/pol/module/uomod.cpp trunk/pol-core/pol/module/uomod2.cpp trunk/pol-core/pol/module/uomod3.cpp trunk/pol-core/pol/module/vitalmod.cpp trunk/pol-core/pol/movement.cpp trunk/pol-core/pol/multi/boat.cpp trunk/pol-core/pol/multi/customhouses.cpp trunk/pol-core/pol/multi/customhouses.h trunk/pol-core/pol/multi/house.cpp trunk/pol-core/pol/npc.cpp trunk/pol-core/pol/packetscrobj.cpp trunk/pol-core/pol/party.cpp trunk/pol-core/pol/pol-2008.vcproj trunk/pol-core/pol/pol.cpp trunk/pol-core/pol/scrsched.cpp trunk/pol-core/pol/sngclick.cpp trunk/pol-core/pol/speech.cpp trunk/pol-core/pol/spelbook.h trunk/pol-core/pol/spells.cpp trunk/pol-core/pol/statmsg.cpp trunk/pol-core/pol/target.cpp trunk/pol-core/pol/tasks.cpp trunk/pol-core/pol/textcmd.cpp trunk/pol-core/pol/tooltips.cpp trunk/pol-core/pol/tooltips.h trunk/pol-core/pol/ufunc.cpp trunk/pol-core/pol/ufunc2.cpp trunk/pol-core/pol/umap.cpp trunk/pol-core/pol/uobjhelp.cpp trunk/pol-core/pol/uolisten.cpp trunk/pol-core/pol/uoscrobj.cpp trunk/pol-core/pol/useskill.cpp trunk/pol-core/pol/uvars.cpp Added Paths: ----------- trunk/pol-core/pol/network/ trunk/pol-core/pol/network/bannedips.cpp trunk/pol-core/pol/network/bannedips.h trunk/pol-core/pol/network/cgdata.cpp trunk/pol-core/pol/network/cgdata.h trunk/pol-core/pol/network/client.cpp trunk/pol-core/pol/network/client.h trunk/pol-core/pol/network/clientio.cpp trunk/pol-core/pol/network/cliface.cpp trunk/pol-core/pol/network/cliface.h trunk/pol-core/pol/network/iostats.cpp trunk/pol-core/pol/network/iostats.h trunk/pol-core/pol/network/packethooks.cpp trunk/pol-core/pol/network/packethooks.h Removed Paths: ------------- trunk/pol-core/pol/bannedips.cpp trunk/pol-core/pol/bannedips.h trunk/pol-core/pol/cgdata.cpp trunk/pol-core/pol/cgdata.h trunk/pol-core/pol/client.cpp trunk/pol-core/pol/client.h trunk/pol-core/pol/clientio.cpp trunk/pol-core/pol/cliface.cpp trunk/pol-core/pol/cliface.h trunk/pol-core/pol/iostats.cpp trunk/pol-core/pol/iostats.h trunk/pol-core/pol/packethooks.cpp trunk/pol-core/pol/packethooks.h Modified: trunk/pol-core/makefile.gcc =================================================================== --- trunk/pol-core/makefile.gcc 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/makefile.gcc 2009-09-07 20:37:38 UTC (rev 33) @@ -51,13 +51,13 @@ pol/accounts/account.cpp pol/accounts/accounts.cpp pol/accounts/acscrobj.cpp pol/allocd.cpp \ pol/armor.cpp pol/mobile/attack.cpp \ pol/mobile/attribute.cpp pol/auxclient.cpp \ - pol/bannedips.cpp pol/binaryfilescrobj.cpp pol/multi/boat.cpp pol/multi/boatcomp.cpp \ + pol/network/bannedips.cpp pol/binaryfilescrobj.cpp pol/multi/boat.cpp pol/multi/boatcomp.cpp \ pol/module/boatmod.cpp pol/mobile/boundbox.cpp pol/bowsalut.cpp \ - pol/module/cfgmod.cpp pol/cfgrepos.cpp pol/cgdata.cpp pol/mobile/charactr.cpp \ + pol/module/cfgmod.cpp pol/cfgrepos.cpp pol/network/cgdata.cpp pol/mobile/charactr.cpp \ pol/checkpnt.cpp \ - pol/mobile/chrcast.cpp pol/mobile/chrituse.cpp pol/mobile/chrskuse.cpp pol/client.cpp \ - pol/clientio.cpp \ - pol/cliface.cpp pol/cmbtcfg.cpp pol/cmdlevel.cpp pol/containr.cpp \ + pol/mobile/chrcast.cpp pol/mobile/chrituse.cpp pol/mobile/chrskuse.cpp pol/network/client.cpp \ + pol/network/clientio.cpp \ + pol/network/cliface.cpp pol/cmbtcfg.cpp pol/cmdlevel.cpp pol/containr.cpp \ pol/console.cpp pol/core.cpp pol/mobile/corpse.cpp \ pol/create.cpp \ pol/cryptengine.cpp pol/crypt/cryptbase.cpp pol/crypt/cryptkey.cpp \ @@ -76,7 +76,7 @@ pol/module/guildmod.cpp \ pol/module/basiciomod.cpp pol/module/basicmod.cpp \ pol/help.cpp pol/multi/house.cpp \ - pol/iostats.cpp pol/irequest.cpp pol/item.cpp pol/item00.cpp \ + pol/network/iostats.cpp pol/irequest.cpp pol/item.cpp pol/item00.cpp \ pol/itemcr.cpp pol/itemdesc.cpp \ pol/landtile.cpp \ pol/listenpt.cpp pol/loadunld.cpp pol/lockable.cpp pol/logfiles.cpp \ @@ -89,7 +89,7 @@ pol/musicrgn.cpp \ pol/npc.cpp pol/npctmpl.cpp pol/npctemplates.cpp pol/module/npcmod.cpp \ pol/objecthash.cpp pol/module/osmod.cpp \ - pol/packethooks.cpp pol/packetscrobj.cpp pol/party.cpp \ + pol/network/packethooks.cpp pol/packetscrobj.cpp pol/party.cpp \ pol/pol.cpp pol/polcfg.cpp pol/polclock.cpp pol/poldbg.cpp \ pol/polfile2.cpp pol/polsem.cpp pol/polsig.cpp pol/polstats.cpp \ pol/module/polsystemmod.cpp \ Modified: trunk/pol-core/plib/realmfunc.cpp =================================================================== --- trunk/pol-core/plib/realmfunc.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/plib/realmfunc.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -14,7 +14,7 @@ */ -#include "clib/stl_inc.h" +#include "../clib/stl_inc.h" #include "realm.h" #include "realmdescriptor.h" @@ -24,20 +24,20 @@ #include "mapshape.h" #include "maptileserver.h" -#include "pol/tiles.h" +#include "../pol/tiles.h" #include "../pol/mobile/charactr.h" -#include "pol/cgdata.h" -#include "pol/multi/customhouses.h" -#include "pol/fnsearch.h" -#include "pol/ssopt.h" -#include "pol/uvars.h" -#include "pol/uworld.h" -#include "pol/item.h" -#include "pol/itemdesc.h" -#include "pol/itemdesc.h" -#include "pol/multi/multi.h" -#include "pol/multi/house.h" -#include "pol/uconst.h" +#include "../pol/network/cgdata.h" +#include "../pol/multi/customhouses.h" +#include "../pol/fnsearch.h" +#include "../pol/ssopt.h" +#include "../pol/uvars.h" +#include "../pol/uworld.h" +#include "../pol/item.h" +#include "../pol/itemdesc.h" +#include "../pol/itemdesc.h" +#include "../pol/multi/multi.h" +#include "../pol/multi/house.h" +#include "../pol/uconst.h" #define HULL_HEIGHT_BUFFER 2 Modified: trunk/pol-core/pol/accounts/account.cpp =================================================================== --- trunk/pol-core/pol/accounts/account.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/accounts/account.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -18,7 +18,7 @@ #include "account.h" #include "accounts.h" #include "../mobile/charactr.h" -#include "../client.h" +#include "../network/client.h" #include "../cmdlevel.h" #include "../polcfg.h" Modified: trunk/pol-core/pol/accounts/acscrobj.cpp =================================================================== --- trunk/pol-core/pol/accounts/acscrobj.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/accounts/acscrobj.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -35,7 +35,7 @@ #include "accounts.h" #include "acscrobj.h" #include "../mobile/charactr.h" -#include "../client.h" +#include "../network/client.h" #include "../cmdlevel.h" #include "../core.h" #include "../objecthash.h" Deleted: trunk/pol-core/pol/bannedips.cpp =================================================================== --- trunk/pol-core/pol/bannedips.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/bannedips.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -1,74 +0,0 @@ -/* -History -======= - -Notes -======= - -*/ - -#include "clib/stl_inc.h" - -#include "clib/cfgelem.h" -#include "clib/cfgfile.h" -#include "clib/fileutil.h" -#include "client.h" -#include "bannedips.h" - -bool is_banned_ip(Client* client) -{ - if (banned_ips.empty()) - return false; - - for( std::vector<IPRule>::iterator itr = banned_ips.begin(); itr != banned_ips.end(); ++itr ) - { - unsigned long addr1part, addr2part; - struct sockaddr_in* sockin = reinterpret_cast<struct sockaddr_in*>(&client->ipaddr); - addr1part = itr->ipMatch & itr->ipMask; - -#ifdef _WIN32 - addr2part = sockin->sin_addr.S_un.S_addr & itr->ipMask; -#else - addr2part = sockin->sin_addr.s_addr & itr->ipMask; -#endif - - if (addr1part == addr2part) - return true; - } - return false; -} - -void read_bannedips_config( bool initial_load) -{ - if (!initial_load) - { - banned_ips.clear(); - } - if (!FileExists( "config/bannedips.cfg" )) - return; - - ConfigFile cf( "config/bannedips.cfg" ); - ConfigElem elem; - - while (cf.read( elem )) - { - IPRule CurrentEntry; - string iptext = elem.remove_string( "IPMatch" ); - string::size_type delim = iptext.find_first_of( "/" ); - if (delim != string::npos) - { - string ipaddr_str = iptext.substr( 0, delim ); - string ipmask_str = iptext.substr( delim+1 ); - CurrentEntry.ipMatch = inet_addr( ipaddr_str.c_str() ); - CurrentEntry.ipMask = inet_addr( ipmask_str.c_str() ); - banned_ips.push_back(CurrentEntry); - } - else - { - string ipmask_str = "255.255.255.255"; - CurrentEntry.ipMatch = inet_addr( iptext.c_str() ); - CurrentEntry.ipMask = inet_addr( ipmask_str.c_str() ); - banned_ips.push_back(CurrentEntry); - } - } -} Deleted: trunk/pol-core/pol/bannedips.h =================================================================== --- trunk/pol-core/pol/bannedips.h 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/bannedips.h 2009-09-07 20:37:38 UTC (rev 33) @@ -1,23 +0,0 @@ -/* -History -======= -2009/01/24 MuadDib Creation of bannedips.h. This is for the new upcoming bannedips.cpp/h setup. - This will work by storing the ip/mask in a vectored struct so - it's not reloading EVERY client connection! Will need to set a - clearing/reset with reloadcfg for this new system when done. - -Notes -======= - -*/ - -#include <string> -#include <vector> - -struct IPRule -{ - unsigned long ipMatch; - unsigned long ipMask; -}; - -std::vector< IPRule > banned_ips; \ No newline at end of file Modified: trunk/pol-core/pol/bowsalut.cpp =================================================================== --- trunk/pol-core/pol/bowsalut.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/bowsalut.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -18,7 +18,7 @@ #include "clib/strutil.h" #include "mobile/charactr.h" -#include "client.h" +#include "network/client.h" #include "extcmd.h" #include "pktin.h" #include "uobject.h" Deleted: trunk/pol-core/pol/cgdata.cpp =================================================================== --- trunk/pol-core/pol/cgdata.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/cgdata.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -1,139 +0,0 @@ -/* -History -======= -2009/09/03 MuadDib: Relocation of multi related cpp/h - -Notes -======= - -*/ - -#include "clib/stl_inc.h" - -#include "clib/unicode.h" - -#include "module/osmod.h" -#include "module/unimod.h" -#include "module/uomod.h" -#include "uoexec.h" - -#include "cgdata.h" -#include "fnsearch.h" -#include "multi/house.h" - -ClientGameData::ClientGameData() : - vendor(NULL), - gumpmods(), - textentry_uoemod(NULL), - target_cursor_uoemod(NULL), - menu_selection_uoemod(NULL), - prompt_uoemod(NULL), - resurrect_uoemod(NULL), - selcolor_uoemod(NULL), - prompt_uniemod(NULL), - justice_region(NULL), - lightlevel(0), - // light_region(NULL), - music_region(NULL), - weather_region(NULL), - custom_house_serial(0) -{ -} - -ClientGameData::~ClientGameData() -{ - clear(); -} - -void ClientGameData::clear() -{ - while (!gumpmods.empty()) - { - UOExecutorModule* uoemod = *gumpmods.begin(); - uoemod->uoexec.os_module->revive(); - uoemod->gump_chr = NULL; - gumpmods.erase( gumpmods.begin() ); - } - - if (textentry_uoemod != NULL) - { - textentry_uoemod->uoexec.os_module->revive(); - textentry_uoemod->textentry_chr = NULL; - textentry_uoemod = NULL; - } - - if (menu_selection_uoemod != NULL) - { - menu_selection_uoemod->uoexec.os_module->revive(); - menu_selection_uoemod->menu_selection_chr = NULL; - menu_selection_uoemod = NULL; - } - - if (prompt_uoemod != NULL) - { - prompt_uoemod->uoexec.os_module->revive(); - prompt_uoemod->prompt_chr = NULL; - prompt_uoemod = NULL; - } - - if (resurrect_uoemod != NULL) - { - resurrect_uoemod->uoexec.os_module->revive(); - resurrect_uoemod->resurrect_chr = NULL; - resurrect_uoemod = NULL; - } - - if (selcolor_uoemod != NULL) - { - selcolor_uoemod->uoexec.os_module->revive(); - selcolor_uoemod->selcolor_chr = NULL; - selcolor_uoemod = NULL; - } - - if (target_cursor_uoemod != NULL) - { - target_cursor_uoemod->uoexec.os_module->revive(); - target_cursor_uoemod->target_cursor_chr = NULL; - target_cursor_uoemod = NULL; - } - - if (prompt_uniemod != NULL) - { - prompt_uniemod->os_module->revive(); - prompt_uniemod->prompt_chr = NULL; - prompt_uniemod = NULL; - } - if (custom_house_serial != 0) - { - UMulti* multi = system_find_multi(custom_house_serial); - if(multi != NULL) - { - UHouse* house = multi->as_house(); - if(house != NULL) - house->editing = false; - } - custom_house_serial = 0; - } - -} - -void ClientGameData::add_gumpmod( UOExecutorModule* uoemod ) -{ - gumpmods.insert( uoemod ); -} - -UOExecutorModule* ClientGameData::find_gumpmod( u32 pid ) -{ - for( GumpMods::iterator itr = gumpmods.begin(); itr != gumpmods.end(); ++itr ) - { - UOExecutorModule* uoemod = (*itr); - if (uoemod->uoexec.os_module->pid() == pid) - return uoemod; - } - return NULL; -} - -void ClientGameData::remove_gumpmod( UOExecutorModule* uoemod ) -{ - gumpmods.erase( uoemod ); -} Deleted: trunk/pol-core/pol/cgdata.h =================================================================== --- trunk/pol-core/pol/cgdata.h 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/cgdata.h 2009-09-07 20:37:38 UTC (rev 33) @@ -1,71 +0,0 @@ -/* -History -======= - - -Notes -======= - -*/ - -#ifndef CGDATA_H -#define CGDATA_H - -#include "clib/refptr.h" - -#include "containr.h" -#include "npc.h" -#include "reftypes.h" - -class JusticeRegion; -class LightRegion; -class MusicRegion; -class WeatherRegion; - -class UnicodeExecutorModule; - -class ClientGameData -{ -public: - ClientGameData(); - ~ClientGameData(); - void clear(); - - - ref_ptr<UContainer> vendor_bought; - ref_ptr<UContainer> vendor_for_sale; - NPCRef vendor; - - typedef std::set<UOExecutorModule*> GumpMods; - GumpMods gumpmods; - - void add_gumpmod( UOExecutorModule* ); - UOExecutorModule* find_gumpmod( u32 pid ); - void remove_gumpmod( UOExecutorModule* ); - - UOExecutorModule* textentry_uoemod; - - - /* - * If a script is requesting a target cursor from this - * character, target_cursor_ex is that script. - * Same for menu selection. - */ - UOExecutorModule* target_cursor_uoemod; - UOExecutorModule* menu_selection_uoemod; - UOExecutorModule* prompt_uoemod; - UOExecutorModule* resurrect_uoemod; - UOExecutorModule* selcolor_uoemod; - - UnicodeExecutorModule* prompt_uniemod; // UNIemod, not UOemod!!! - - JusticeRegion* justice_region; - - int lightlevel; - // LightRegion* light_region; - MusicRegion* music_region; - WeatherRegion* weather_region; - u32 custom_house_serial; -}; - -#endif Modified: trunk/pol-core/pol/clfunc.cpp =================================================================== --- trunk/pol-core/pol/clfunc.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/clfunc.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -19,7 +19,7 @@ #include "clib/passert.h" #include "mobile/charactr.h" -#include "client.h" +#include "network/client.h" #include "pktoutid.h" #include "sockio.h" #include "clfunc.h" Deleted: trunk/pol-core/pol/client.cpp =================================================================== --- trunk/pol-core/pol/client.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/client.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -1,571 +0,0 @@ -/* -History -======= -2005/01/24 Shinigami: added getspyonclient2 to support packet 0xd9 (Spy on Client 2) -2005/08/29 Shinigami: character.spyonclient2 renamed to character.clientinfo - getspyonclient2 renamed to getclientinfo -2007/07/09 Shinigami: added isUOKR [bool] - UO:KR client used? -2009/07/20 MuadDib: Added statement to bypass cryptseed at login. Handled by changing default client recv_state using ssopt flag. -2009/07/23 MuadDib: updates for new Enum::Packet Out ID -2009/08/25 Shinigami: STLport-5.2.1 fix: init order changed of aosresist - STLport-5.2.1 fix: params in call of Log2() - -Notes -======= - -*/ - -#include "clib/stl_inc.h" - -#include "clib/fdump.h" -#include "clib/logfile.h" -#include "clib/stlutil.h" -#include "clib/strutil.h" //CNXBUG -#include "clib/unicode.h" - -#include "bscript/berror.h" - -#include "accounts/account.h" -#include "cgdata.h" -#include "mobile/charactr.h" -#include "client.h" -#include "cliface.h" -#include "crypt/cryptengine.h" -#include "msgfiltr.h" -#include "pktin.h" -#include "polcfg.h" -#include "polsig.h" -#include "polstats.h" -#include "sockio.h" -#include "ssopt.h" -#include "module/unimod.h" -#include "uoclient.h" -#include "uvars.h" -#include "uworld.h" -#include "xbuffer.h" - -// only in here temporarily, until logout-on-disconnect stuff is removed -#include "ufunc.h" - -unsigned long Client::instance_counter_; - -Client::Client( ClientInterface& aInterface, const string& encryption ) : - acct(NULL), - chr(NULL), - Interface(aInterface), - ready(false), - csocket(-1), - listen_port(0), - aosresist(false), - disconnect(0), - recv_state( RECV_STATE_CRYPTSEED_WAIT ), - encrypted_data(), - bufcheck1_AA(0xAA), - buffer(), - bufcheck2_55(0x55), - bytes_received(0), - message_length(0), - cryptengine( create_crypt_engine( encryption ) ), - encrypt_server_stream(0), - msgtype_filter(&login_filter), - fpLog(NULL), - pause_count(0), - first_xmit_buffer(NULL), - last_xmit_buffer(NULL), - n_queued(0), - queued_bytes_counter(0), - gd(new ClientGameData), - instance_( ++instance_counter_ ), - checkpoint(-1), //CNXBUG - last_msgtype(255), - thread_pid(-1), - UOExpansionFlag(0), - isUOKR(false), - is_greq_6017(false), - is_greq_60142(false), - paused_(false) -{ - // For bypassing cryptseed packet - if ( ssopt.use_edit_server ) - { - recv_state = RECV_STATE_MSGTYPE_WAIT; - } - - Interface.register_client( this ); - memset( buffer, 0, sizeof buffer ); - memset( &counters, 0, sizeof counters ); - memset( &clientinfo_, 0, sizeof(clientinfo_) ); - memset( &versiondetail_, 0, sizeof(versiondetail_) ); -} - -void cancel_trade( Character* chr1 ); - -void Client::Delete( Client* client ) -{ - client->PreDelete(); - delete client; -} - -Client::~Client() -{ -} - -void Client::Disconnect() -{ - Interface.deregister_client( this ); - if (csocket != INVALID_SOCKET)//>= 0) - { -#ifdef _WIN32 - shutdown( csocket,2 ); //2 is both sides, defined in winsock2.h ... - closesocket( csocket ); -#else - shutdown( csocket,SHUT_RDWR ); - close( csocket ); -#endif - } - csocket = INVALID_SOCKET; -} - -void Client::PreDelete() -{ - Disconnect(); - // FIXME: TEMPORARY FIX: disassociate the character from the account, so - // you can log on with another character - if ((acct != NULL) && - (acct->active_character != NULL) && - (acct->active_character->client == this)) - { - if (acct->active_character->logged_in) - { - Character* tchr = acct->active_character; - ClrCharacterWorldPosition( tchr, "Client Exit" ); - send_remove_character_to_nearby( tchr ); - tchr->logged_in = false; - - tchr->set_opponent( NULL ); - tchr->removal_cleanup(); - if (tchr->get_opponent() != NULL) - { - tchr->set_opponent(NULL, true); - } - } - else - { - cerr << "Uhh... active character not logged in!??" << endl; - } - acct->active_character = NULL; - } - - // detach the account and character from this client, if they - // are still associated with it. - - acct = NULL; - - if (chr) - { - if (chr->client == this) - chr->client = NULL; - chr = NULL; - } - - if (fpLog != NULL) - { - time_t now = time(NULL); - fprintf( fpLog, "Log closed at %s\n", asctime( localtime( &now ) ) ); - - fclose( fpLog ); - fpLog = NULL; - } - - delete gd; - gd = NULL; - - while (first_xmit_buffer != NULL) - { - XmitBuffer* xbuffer = first_xmit_buffer; - first_xmit_buffer = first_xmit_buffer->next; - free(xbuffer); - --n_queued; - } - last_xmit_buffer = NULL; -} - -// ClientInfo - delivers a lot of usefull infomation about client PC -BStruct* Client::getclientinfo() const -{ - BStruct* ret = new BStruct; - - ret->addMember( "unknown1", new BLong( clientinfo_.unknown1 ) ); // Unknown - allways 0x02 - ret->addMember( "instance", new BLong( clientinfo_.instance ) ); // Unique Instance ID of UO - ret->addMember( "os_major", new BLong( clientinfo_.os_major ) ); // OS Major - ret->addMember( "os_minor", new BLong( clientinfo_.os_minor ) ); // OS Minor - ret->addMember( "os_revision", new BLong( clientinfo_.os_revision ) ); // OS Revision - ret->addMember( "cpu_manufacturer", new BLong( clientinfo_.cpu_manufacturer ) ); // CPU Manufacturer - ret->addMember( "cpu_family", new BLong( clientinfo_.cpu_family ) ); // CPU Family - ret->addMember( "cpu_model", new BLong( clientinfo_.cpu_model ) ); // CPU Model - ret->addMember( "cpu_clockspeed", new BLong( clientinfo_.cpu_clockspeed ) ); // CPU Clock Speed [Mhz] - ret->addMember( "cpu_quantity", new BLong( clientinfo_.cpu_quantity ) ); // CPU Quantity - ret->addMember( "memory", new BLong( clientinfo_.memory ) ); // Memory [MB] - ret->addMember( "screen_width", new BLong( clientinfo_.screen_width ) ); // Screen Width - ret->addMember( "screen_height", new BLong( clientinfo_.screen_height ) ); // Screen Height - ret->addMember( "screen_depth", new BLong( clientinfo_.screen_depth ) ); // Screen Depth [Bit] - ret->addMember( "directx_major", new BLong( clientinfo_.directx_major ) ); // DirectX Major - ret->addMember( "directx_minor", new BLong( clientinfo_.directx_minor ) ); // DirectX Minor - - ObjArray* arr_vd; - unsigned maxlen_vd = sizeof(clientinfo_.video_description) / sizeof(clientinfo_.video_description[0]); - unsigned wlen_vd = 0; - while ( (clientinfo_.video_description[wlen_vd] != L'\0') && (wlen_vd < maxlen_vd) ) - ++wlen_vd; - if ( !convertUCtoArray(clientinfo_.video_description, arr_vd, wlen_vd, true) ) - ret->addMember( "video_description", new BError("Invalid Unicode speech received.") ); - else { - ret->addMember( "video_description", arr_vd ); // Video Card Description [wide-character] - } - - ret->addMember( "video_vendor", new BLong( clientinfo_.video_vendor ) ); // Video Card Vendor ID - ret->addMember( "video_device", new BLong( clientinfo_.video_device ) ); // Video Card Device ID - ret->addMember( "video_memory", new BLong( clientinfo_.video_memory ) ); // Video Card Memory [MB] - ret->addMember( "distribution", new BLong( clientinfo_.distribution ) ); // Distribution - ret->addMember( "clients_running", new BLong( clientinfo_.clients_running ) ); // Clients Running - ret->addMember( "clients_installed", new BLong( clientinfo_.clients_installed ) ); // Clients Installed - ret->addMember( "partial_installed", new BLong( clientinfo_.partial_installed ) ); // Partial Insstalled - - ObjArray* arr_lc; - unsigned maxlen_lc = sizeof(clientinfo_.langcode) / sizeof(clientinfo_.langcode[0]); - unsigned wlen_lc = 0; - while ( (clientinfo_.langcode[wlen_lc] != L'\0') && (wlen_lc < maxlen_lc) ) - ++wlen_lc; - if ( !convertUCtoArray(clientinfo_.langcode, arr_lc, wlen_lc, true) ) - ret->addMember( "langcode", new BError("Invalid Unicode speech received.") ); - else { - ret->addMember( "langcode", arr_lc ); // Language Code [wide-character] - } - - ObjArray* arr_u2 = new ObjArray; - for ( unsigned i = 0; i < sizeof(clientinfo_.unknown2); ++i ) - arr_u2->addElement( new BLong( clientinfo_.unknown2[i] ) ); - ret->addMember( "unknown2", arr_u2 ); // Unknown - - return ret; -} - -void Client::itemizeclientversion(const std::string& ver, VersionDetailStruct& detail) -{ - try - { - int dot1 = ver.find_first_of('.',0); - int dot2 = ver.find_first_of('.',dot1 + 1); - int dot3 = ver.find_first_of('.',dot2 + 1); - if (dot3 == -1) // since 5.0.7 patch is digit - { - dot3 = dot2 + 1; - while ( (dot3 < (int)ver.length()) && (isdigit(ver[dot3])) ) - { - dot3++; - } - } - - detail.major = atoi(ver.substr(0,dot1).c_str()); - detail.minor = atoi(ver.substr(dot1+1,dot2 - dot1 - 1).c_str()); - detail.rev = atoi(ver.substr(dot2+1,dot3 - dot2 - 1).c_str()); - detail.patch = 0; - if (dot3<(int)ver.length()) - { - if ( (detail.major<=5) && (detail.minor<=0) && (detail.rev<=6)) - { - if (ver[dot3]!=' ') - detail.patch = (ver[dot3] - 'a') + 1; // char to int - } - else - detail.patch = atoi(ver.substr(dot3+1,ver.length() - dot3 - 1).c_str()); - } - } - catch(...) - { - detail.major = 0; - detail.minor = 0; - detail.rev = 0; - detail.patch = 0; - Log2("Malformed clientversion string: %s\n",ver.c_str()); - } -} - -bool Client::compareVersion( const std::string& ver ) -{ - VersionDetailStruct ver2; - itemizeclientversion(ver, ver2); - return Client::compareVersion(ver2); -} - -bool Client::compareVersion(const VersionDetailStruct& ver2) -{ - VersionDetailStruct ver1 = getversiondetail(); - - if ( ver1.major > ver2.major ) - return true; - else if ( ver1.major < ver2.major ) - return false; - else if ( ver1.minor > ver2.minor ) - return true; - else if ( ver1.minor < ver2.minor ) - return false; - else if ( ver1.rev > ver2.rev ) - return true; - else if ( ver1.rev < ver2.rev ) - return false; - else if ( ver1.patch > ver2.patch ) - return true; - else if ( ver1.patch < ver2.patch ) - return false; - else - return true; -} - -std::string Client::status() const -{ - std::string st; - if (acct != NULL) - st += "AC:" + std::string(acct->name()) + " "; - if (chr != NULL) - st += "CH:" + chr->name() + " "; - if (have_queued_data()) - st += "TXBUF "; - if (disconnect) - st += "DISC "; - if (paused_) - st += "PAUSE "; - if (ready) - st += "RDY "; - st += ipaddrAsString() + " "; - st += "CHK: " + decint(checkpoint) + " "; - st += "PID: " + decint(thread_pid) + " "; - st += "LAST: " + hexint(last_msgtype); - return st; -} - -void Client::setcryptseed( unsigned char i_cryptseed[4] ) -{ - memcpy( cryptseed, i_cryptseed, sizeof cryptseed ); -} - -void Client::queue_data( const void *data, unsigned short datalen ) -{ - THREAD_CHECKPOINT( active_client, 300 ); - XmitBuffer *xbuffer = (XmitBuffer *) malloc( sizeof(XmitBuffer)-1+datalen ); - THREAD_CHECKPOINT( active_client, 301 ); - if (xbuffer) - { - THREAD_CHECKPOINT( active_client, 302 ); - xbuffer->next = NULL; - xbuffer->nsent = 0; - xbuffer->lenleft = datalen; - memcpy( xbuffer->data, data, datalen ); - THREAD_CHECKPOINT( active_client, 303 ); - if (first_xmit_buffer == NULL) - { // in this case, last_xmit_buffer is also NULL, so can't set its ->next. - THREAD_CHECKPOINT( active_client, 304 ); - first_xmit_buffer = xbuffer; - } - else - { - THREAD_CHECKPOINT( active_client, 305 ); - last_xmit_buffer->next = xbuffer; - } - THREAD_CHECKPOINT( active_client, 306 ); - last_xmit_buffer = xbuffer; - ++n_queued; - queued_bytes_counter += datalen; - } - else - { - THREAD_CHECKPOINT( active_client, 307 ); - Log( "Client#%lu: Unable to allocate %d bytes for queued data. Disconnecting.\n", - instance_, sizeof(XmitBuffer)-1+datalen ); - disconnect = true; - } - THREAD_CHECKPOINT( active_client, 309 ); - -} - - -void Client::xmit( const void *data, unsigned short datalen ) -{ - THREAD_CHECKPOINT( active_client, 200 ); - if (last_xmit_buffer) // this client already backlogged, schedule for later - { - THREAD_CHECKPOINT( active_client, 201 ); - queue_data( data, datalen ); - THREAD_CHECKPOINT( active_client, 202 ); - return; - } - THREAD_CHECKPOINT( active_client, 203 ); - - /* client not backlogged - try to send. */ - const unsigned char *cdata = (const unsigned char *) data; - int nsent; - - if (-1 == (nsent = send( csocket, (const char *)cdata, datalen, 0 ))) - { - THREAD_CHECKPOINT( active_client, 204 ); - int sckerr = socket_errno; - - if (sckerr == SOCKET_ERRNO(EWOULDBLOCK)) - { - THREAD_CHECKPOINT( active_client, 205 ); - Log( "Client#%lu: Switching to queued data mode (1, %u bytes)\n", instance_, (unsigned) datalen ); - cerr << "Switching to queued data mode (1, " << datalen << " bytes)" << endl; - THREAD_CHECKPOINT( active_client, 206 ); - queue_data( data, datalen ); - THREAD_CHECKPOINT( active_client, 207 ); - return; - } - else - { - THREAD_CHECKPOINT( active_client, 208 ); - if (!disconnect) - Log( "Client#%lu: Disconnecting client due to send() error (1): %d\n" , instance_, sckerr); - disconnect = 1; - THREAD_CHECKPOINT( active_client, 209 ); - return; - } - } - else // no error - { - THREAD_CHECKPOINT( active_client, 210 ); - datalen -= static_cast<unsigned short>(nsent); - counters.bytes_transmitted += nsent; - polstats.bytes_sent += nsent; - if (datalen) // anything left? if so, queue for later. - { - THREAD_CHECKPOINT( active_client, 211 ); - Log( "Client#%lu: Switching to queued data mode (2)\n", instance_ ); - cerr << "Switching to queued data mode (2)" << endl; - THREAD_CHECKPOINT( active_client, 212 ); - queue_data( cdata+nsent, datalen ); - THREAD_CHECKPOINT( active_client, 213 ); - - } - } - THREAD_CHECKPOINT( active_client, 214 ); -} - -void Client::send_queued_data() -{ - XmitBuffer *xbuffer; - // hand off data to the sockets layer until it won't take any more. - // note if a buffer is sent in full, we try to send the next one, ad infinitum - while (NULL != (xbuffer = first_xmit_buffer)) - { - int nsent; - nsent = send( csocket, - (char *) &xbuffer->data[xbuffer->nsent], - xbuffer->lenleft, - 0 ); - if (nsent == -1) - { -#ifdef _WIN32 - int sckerr = WSAGetLastError(); -#else - int sckerr = errno; -#endif - if (sckerr == SOCKET_ERRNO(EWOULDBLOCK)) - { - // do nothing. it'll be re-queued later, when it won't block. - return; - } - else - { - if (!disconnect) - Log( "Client#%lu: Disconnecting client due to send() error (2): %d\n", instance_, sckerr ); - disconnect = 1; - return; - } - } - else - { - xbuffer->nsent += static_cast<unsigned short>(nsent); - xbuffer->lenleft -= static_cast<unsigned short>(nsent); - counters.bytes_transmitted += nsent; - polstats.bytes_sent += nsent; - if (xbuffer->lenleft == 0) - { - first_xmit_buffer = first_xmit_buffer->next; - if (first_xmit_buffer == NULL) - { - last_xmit_buffer = NULL; - Log( "Client#%lu: Leaving queued mode (%ld bytes xmitted)\n", instance_, queued_bytes_counter ); - queued_bytes_counter = 0; - } - free( xbuffer ); - --n_queued; - } - } - } -} - -#define PRE_ENCRYPT - -#ifndef PRE_ENCRYPT -#include "sockio.h" -#endif - -// 33 01 "encrypted": 4F FA -static const unsigned char pause_pre_encrypted[2] = { 0x4F, 0xFA }; -// 33 00 "encrypted": 4C D0 -static const unsigned char restart_pre_encrypted[2] = { 0x4C, 0xD0 }; - -void Client::send_pause(bool bForce /*=false*/) -{ - if ((bForce || uoclient_protocol.EnableFlowControlPackets) && !paused_) - { -#ifndef PRE_ENCRYPT - PKTOUT_33 msg; - msg.msgtype = PKTOUT_33_ID; - msg.flow = MSGOPT_33_FLOW_PAUSE; - transmit( this, &msg, sizeof msg ); -#else - xmit( pause_pre_encrypted, sizeof pause_pre_encrypted ); -#endif - paused_ = true; - // cout << "Client#" << instance_ << " paused" << endl; - } -} - -void Client::pause() -{ - if (!pause_count) - { - send_pause(); - pause_count = 1; - } - // ++pause_count; -} - -void Client::send_restart(bool bForce /*=false*/) -{ - if (paused_) - { -#ifndef PRE_ENCRYPT - PKTOUT_33 msg; - msg.msgtype = PKTOUT_33_ID; - msg.flow = MSGOPT_33_FLOW_RESTART; - transmit( this, &msg, sizeof msg ); -#else - xmit( restart_pre_encrypted, sizeof restart_pre_encrypted ); -#endif - // cout << "Client#" << instance_ << " restarted" << endl; - paused_ = false; - } -} - -// FIXME: Why is this empty?? -void Client::restart() -{ -} - -void Client::restart2() -{ - send_restart(); - pause_count = 0; -} Deleted: trunk/pol-core/pol/client.h =================================================================== --- trunk/pol-core/pol/client.h 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/client.h 2009-09-07 20:37:38 UTC (rev 33) @@ -1,203 +0,0 @@ -/* -History -======= -2005/01/24 Shinigami: added get-/setspyonclient2 to support packet 0xd9 (Spy on Client 2) -2005/04/03 Shinigami: added UOExpansionFlag for Samurai Empire -2005/08/29 Shinigami: character.spyonclient2 renamed to character.clientinfo - get-/setspyonclient2 renamed to get-/setclientinfo -2006/05/16 Shinigami: added UOExpansionFlag for Mondain's Legacy - added GENDER/RACE flag (e.g. used inside ClientCreateChar()) -2007/07/09 Shinigami: added isUOKR [bool] - UO:KR client used? -2009/08/10 MuadDib: Added CLIENT_VER_50000 for v5.0.0x clients. -2009/08/19 Turley: Added u32 UOExpansionFlagClient - -Notes -======= - -*/ - -#ifndef __CLIENT_H -#define __CLIENT_H - -#include <stdio.h> // for that FILE fpLog down there :( -#include <memory> -#include <string> - -#include "clib/rawtypes.h" -#include "pktin.h" -#include "sockets.h" -#include "ucfg.h" -#include "ucrypto.h" -#include "crypt/cryptengine.h" -#include "bscript/bstruct.h" - -class MessageTypeFilter; -class Account; -class Character; -class UContainer; -struct XmitBuffer; -class ClientGameData; -class ClientInterface; -class UOClientInterface; - -extern UOClientInterface uo_client_interface; - -const u16 T2A = 0x01; -const u16 LBR = 0x02; -const u16 AOS = 0x04; -const u16 SE = 0x08; // set AOS-Flag in send_feature_enable() too for needed checks -const u16 ML = 0x10; // set SE- and AOS-Flag in send_feature_enable() too for needed checks -const u16 KR = 0x20; // set KR- and SE- and AOS-Flag in send_feature_enable() too for needed checks - -const u8 FLAG_GENDER = 0x01; -const u8 FLAG_RACE = 0x02; - - -struct VersionDetailStruct -{ - int major; - int minor; - int rev; - int patch; -}; - -const struct VersionDetailStruct CLIENT_VER_50000={5,0,0,0}; -const struct VersionDetailStruct CLIENT_VER_60171={6,0,1,7}; -const struct VersionDetailStruct CLIENT_VER_60142={6,0,14,2}; - -class Client -{ -public: - Client( ClientInterface& aInterface, const string& encryption ); - static void Delete( Client* client ); - friend class GCCHelper; - -private: - void PreDelete(); - virtual ~Client(); - -public: - void Disconnect(); - void transmit( const void *data, int len ); // for entire message or header only - void transmitmore( const void *data, int len ); // for stuff after a header - - void recv_remaining( int total_expected ); - void recv_remaining_nocrypt( int total_expected ); - - void setversion( const std::string& ver ) { version_ = ver; } - const std::string& getversion() const { return version_; } - VersionDetailStruct getversiondetail() const { return versiondetail_; } - void setversiondetail( VersionDetailStruct& detail ) { versiondetail_ = detail; } - void itemizeclientversion( const std::string& ver, VersionDetailStruct& detail ); - bool compareVersion( const std::string& ver ); - bool compareVersion(const VersionDetailStruct& ver2); - - void setclientinfo( const PKTIN_D9 *msg ) { memcpy( &clientinfo_, msg, sizeof(clientinfo_) ); } - BStruct* getclientinfo() const; - - Account* acct; - Character* chr; - ClientInterface& Interface; - - bool ready; // all initialization stuff has been sent, ready for general use. - - -// - bool have_queued_data() const; - void send_queued_data(); - - SOCKET csocket; // socket to client ACK - requires header inclusion. - unsigned short listen_port; - bool aosresist; // UOClient.Cfg Entry - - bool disconnect; // if 1, disconnect this client - - enum e_recv_states { - RECV_STATE_CRYPTSEED_WAIT, - RECV_STATE_MSGTYPE_WAIT, - RECV_STATE_MSGLEN_WAIT, - RECV_STATE_MSGDATA_WAIT - } recv_state; - - unsigned char encrypted_data[ MAXBUFFER ]; - unsigned char bufcheck1_AA; - unsigned char buffer[ MAXBUFFER ]; - unsigned char bufcheck2_55; - unsigned int bytes_received; // how many bytes have been received into the buffer. - unsigned int message_length; // how many bytes are expected for this message - - struct sockaddr ipaddr; - - ClientEncryptionEngine clicrypt; - - std::auto_ptr<CryptEngine> cryptengine; - - //CCrypt newcrypt; - unsigned char cryptseed[4]; - - void setcryptseed( unsigned char cryptseed[4] ); - - bool encrypt_server_stream; // encrypt the server stream (data sent to client)? - - const MessageTypeFilter *msgtype_filter; - - FILE* fpLog; - - std::string status() const; - - void send_pause(bool bForce = false); - void send_restart(bool bForce = false); - - void pause(); - void restart(); - void restart2(); - int pause_count; - - std::string ipaddrAsString() const; - -protected: - - XmitBuffer *first_xmit_buffer; - XmitBuffer *last_xmit_buffer; - long n_queued; - long queued_bytes_counter; // only used for monitoring - - // we may want to track how many bytes total are outstanding, - // and boot clients that are too far behind. - void queue_data( const void *data, unsigned short datalen ); - void transmit_encrypted( const void *data, int len ); - void xmit( const void *data, unsigned short datalen ); - -public: - ClientGameData* gd; - unsigned long instance_; - static unsigned long instance_counter_; - int checkpoint;//CNXBUG - unsigned char last_msgtype; - int thread_pid; - u16 UOExpansionFlag; - u32 UOExpansionFlagClient; - bool isUOKR; - bool is_greq_6017; - bool is_greq_60142; - -private: - struct { - unsigned long bytes_transmitted; - unsigned long bytes_received; - } counters; - std::string version_; - PKTIN_D9 clientinfo_; - bool paused_; - VersionDetailStruct versiondetail_; - // hidden: - Client( const Client& x ); - Client& operator=( const Client& x ); -}; - -inline bool Client::have_queued_data() const -{ - return (first_xmit_buffer != NULL); -} - -#endif Deleted: trunk/pol-core/pol/clientio.cpp =================================================================== --- trunk/pol-core/pol/clientio.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/clientio.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -1,310 +0,0 @@ -/* -History -======= - -Notes -======= - -*/ - -#include "clib/stl_inc.h" - -#include "ctable.h" -#include "uvars.h" -#include "ucrypto.h" -#include "sockio.h" - -#define OPT_LOG_CLIENT_DATA 0 - -#include "config.h" - -#include "clib/logfile.h" -#include "clib/fdump.h" -#include "clib/passert.h" - -#include "client.h" -#include "iostats.h" -#include "packethooks.h" -#include "polsig.h" -#include "polstats.h" -#include "ucfg.h" - -string Client::ipaddrAsString() const -{ - return AddressToString( const_cast<struct sockaddr*>(&ipaddr) ); -} - -void Client::recv_remaining( int total_expected) -{ - int count; - int max_expected = total_expected - bytes_received; - - count=recv(csocket, - (char *) encrypted_data, // &client->buffer[ client->bytes_received ] - max_expected, 0); - - if (count > 0) - { - passert( count <= max_expected ); - -#if OPT_LOG_CLIENT_DATA - if (logfile) - { - fprintf( logfile, "Client ciphertext: \n" ); - fdump( logfile, encrypted_data, count ); - } -#endif - - cryptengine->Decrypt( encrypted_data, &buffer[ bytes_received ], count ); - -#if OPT_LOG_CLIENT_DATA - if (logfile) - { - fprintf( logfile, "Client plaintext: \n" ); - fdump( logfile, &buffer[ bytes_received ], count ); - } -#endif - - bytes_received += count; - counters.bytes_received += count; - polstats.bytes_received += count; - } - else if (count == 0) // graceful close - { - disconnect = true; - } - else - { - int errn = socket_errno; - if (errn != SOCKET_ERRNO( EWOULDBLOCK )) - disconnect = true; - } -} - -void Client::recv_remaining_nocrypt( int total_expected) -{ - int count; - - count=recv(csocket, - (char *) &buffer[ bytes_received ], - total_expected - bytes_received, 0); - - if (count > 0) - { - bytes_received += count; - counters.bytes_received += count; - polstats.bytes_received += count; - } - else if (count == 0) // graceful close - { - disconnect = true; - } - else - { - int errn = socket_errno; - if (errn != SOCKET_ERRNO( EWOULDBLOCK )) - disconnect = true; - } -} - -void svr_decrypt( unsigned char *dst, int *lenout, - const unsigned char *src, int lenin ) -{ - unsigned short cmpval; - unsigned char inmask; - int bitcount; - - bitcount = 0; - *lenout = 0; - cmpval = 0; - while (lenin) - { - inmask = 0x80; - while (inmask) - { - cmpval <<= 1; - - if (*src & inmask) - cmpval |= 1; - - inmask >>= 1; - - bitcount += 1; - - for( unsigned char i = 0; i <= 256; i++ ) - { - if (bitcount == keydesc[ i ].nbits) - { - if (keydesc[i].bits == cmpval) - { - if (i == 0x0100) return; - *dst = i; - dst++; - *lenout = *lenout + 1; - bitcount = 0; - cmpval = 0; - break; // FIXME - } - } - } - } - src++; - lenin--; - } -} - -unsigned char xoutbuffer[ 64000 ]; - - - -/* NOTE: If this changes, code in client.cpp must change - pause() and restart() use - pre-encrypted values of 33 00 and 33 01. -*/ -void Client::transmit_encrypted( const void *data, int len ) -{ - THREAD_CHECKPOINT( active_client, 100 ); - const unsigned char *cdata = (const unsigned char *) data; - unsigned char *pch; - int i; - int bidx; // Offset in output byte - - pch = xoutbuffer; - bidx=0; - THREAD_CHECKPOINT( active_client, 101 ); - for (i=0; i < len; i++) - { - THREAD_CHECKPOINT( active_client, 102 ); - unsigned char ch = cdata[i]; - int nbits = keydesc[ ch ].nbits; - unsigned short inval = keydesc[ ch ].bits_reversed; - - THREAD_CHECKPOINT( active_client, 103 ); - - while (nbits--) - { - THREAD_CHECKPOINT( active_client, 104 ); - *pch <<= 1; - if (inval & 1) *pch |= 1; - bidx++; - if (bidx == 8) - { - THREAD_CHECKPOINT( active_client, 105 ); - pch++; - bidx = 0; - } - THREAD_CHECKPOINT( active_client, 106 ); - - inval >>= 1; - } - THREAD_CHECKPOINT( active_client, 107 ); - - } - THREAD_CHECKPOINT( active_client, 108 ); - do { - int nbits = keydesc[ 0x100 ].nbits; - unsigned short inval = keydesc[ 0x100 ].bits_reversed; - - THREAD_CHECKPOINT( active_client, 109 ); - - while (nbits--) - { - THREAD_CHECKPOINT( active_client, 110 ); - *pch <<= 1; - if (inval & 1) *pch |= 1; - bidx++; - THREAD_CHECKPOINT( active_client, 111 ); - if (bidx == 8) - { - pch++; - bidx = 0; - } - THREAD_CHECKPOINT( active_client, 112 ); - - inval >>= 1; - } - } while (0); - THREAD_CHECKPOINT( active_client, 113 ); - - if (bidx==0) - { - pch--; - } - else - { - *pch <<= (8-bidx); - } - THREAD_CHECKPOINT( active_client, 114 ); - - passert( pch-xoutbuffer+1 <= int(sizeof xoutbuffer) ); - THREAD_CHECKPOINT( active_client, 115 ); - xmit( xoutbuffer, pch-xoutbuffer+1 ); - THREAD_CHECKPOINT( active_client, 116 ); -} -#include "packetscrobj.h" -void Client::transmit( const void *data, int len ) -{ - ref_ptr<BPacket> p; - bool handled = false; - //see if the outgoing packet has a SendFunction installed. If so call it. It may or may not - //want us to continue sending the packet. If it does, handled will be false, and data, len, and p - //will be altered. data has the new packet data to send, len the new length, and p, a ref counted - //pointer to the packet object. - // - //If there is no outgoing packet script, handled will be false, and the passed params will be unchanged. - CallOutgoingPacketExportedFunction(this, data, len, p, handled); - if(handled) - return; - - unsigned char msgtype = * (const char*) data; - - if (fpLog != NULL) - { - fprintf( fpLog, "Server -> Client: 0x%X, %d bytes\n", msgtype, len ); - fdump( fpLog, data, len ); - fprintf( fpLog, "\n" ); - } - - if (last_xmit_buffer) - { - queuedmode_iostats.sent[ msgtype ].count++; - queuedmode_iostats.sent[ msgtype ].bytes += len; - } - iostats.sent[ msgtype ].count++; - iostats.sent[ msgtype ].bytes += len; - - if (encrypt_server_stream) - { - pause(); - transmit_encrypted( data, len ); - } - else - { - xmit( data, len ); - // _xmit( client->csocket, data, len ); - } -} - -void Client::transmitmore( const void *data, int len ) -{ - if (fpLog != NULL) - { - fprintf( fpLog, "Server -> Client (%d bytes)\n", len ); - fdump( fpLog, data, len ); - } - - if (encrypt_server_stream) - { - pause(); - transmit_encrypted( data, len ); - } - else - { - xmit( data, len ); - // _xmit( client->csocket, data, len ); - } -} - -void transmit( Client* client, const void *data, int len ) -{ - client->transmit( data, len ); -} Deleted: trunk/pol-core/pol/cliface.cpp =================================================================== --- trunk/pol-core/pol/cliface.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/cliface.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -1,262 +0,0 @@ -/* -History -======= -2009/07/23 MuadDib: updates for new Enum::Packet Out ID - -Notes -======= - -*/ - -#include "clib/stl_inc.h" -#include "clib/endian.h" - -#include "mobile/attribute.h" -#include "mobile/charactr.h" -#include "client.h" -#include "cliface.h" -#include "party.h" -#include "pktboth.h" -#include "ssopt.h" -#include "statmsg.h" -#include "ufunc.h" -#include "uoclient.h" -#include "uoskills.h" -#include "vital.h" - -UOClientInterface uo_client_interface; - -void initialize_client_interfaces() -{ - uo_client_interface.Initialize(); -} - -ClientVitalUpdaters::ClientVitalUpdaters() : - my_vital_changed(NULL), - others_vital_changed(NULL) -{ -} - -ClientAttributeUpdaters::ClientAttributeUpdaters() : - my_attr_changed(NULL) -{ -} - -void ClientInterface::register_client( Client* client ) -{ - clients.push_back( client ); -} -void ClientInterface::deregister_client( Client* client ) -{ - for( unsigned i = 0; i < clients.size(); ++i ) - { - if (clients[i] == client) - { - clients[i] = clients.back(); - clients.pop_back(); - break; - } - } -} - -// static -void ClientInterface::tell_vital_changed( Character* who, const Vital* vital ) -{ - Client* client = who->client; - if (client && client->ready) - { - const ClientVitalUpdaters& cvu = client->Interface.vital_updaters[ vital->vitalid ]; - if (cvu.my_vital_changed) - cvu.my_vital_changed(client,who,vital); - } - - // on all the client interfaces, for their connected clients, possibly tell them - uo_client_interface.bcast_vital_changed( who, vital ); -} -void ClientInterface::tell_attribute_changed( Character* who, const Attribute* attr ) -{ - Client* client = who->client; - if (client && client->ready) - { - const ClientAttributeUpdaters& cau = client->Interface.attribute_updaters[ attr->attrid ]; - if (cau.my_attr_changed) - cau.my_attr_changed(client,who,attr); - } -} - - -void send_uo_hits( Client* client, Character* me, const Vital* vital ) -{ - PKTOUT_A1 msg; - msg.msgtype = PKTOUT_A1_ID; - msg.serial = me->serial_ext; - - long v = me->vital( vital->vitalid ).current_ones(); - if (v > 0xFFFF) - v = 0xFFFF; - msg.hits = ctBEu16( static_cast<u16>(v) ); - - v = me->vital( vital->vitalid ).maximum_ones(); - if (v > 0xFFFF) - v = 0xFFFF; - msg.max_hits = ctBEu16( static_cast<u16>(v) ); - - client->transmit( &msg, sizeof msg ); - -} - -void send_uo_mana( Client* client, Character* me, const Vital* vital ) -{ - PKTOUT_A2 msg; - msg.msgtype = PKTOUT_A2_ID; - msg.serial = me->serial_ext; - - long v = me->vital( vital->vitalid ).current_ones(); - if (v > 0xFFFF) - v = 0xFFFF; - msg.mana = ctBEu16( static_cast<u16>(v) ); - - v = me->vital( vital->vitalid ).maximum_ones(); - if (v > 0xFFFF) - v = 0xFFFF; - msg.max_mana = ctBEu16( static_cast<u16>(v) ); - - client->transmit( &msg, sizeof msg ); - - if (me->party() != NULL) - me->party()->on_mana_changed(me); - -} - -void send_uo_stamina( Client* client, Character* me, const Vital* vital ) -{ - PKTOUT_A3 msg; - msg.msgtype = PKTOUT_A3_ID; - msg.serial = me->serial_ext; - - long v = me->vital( vital->vitalid ).current_ones(); - if (v > 0xFFFF) - v = 0xFFFF; - msg.stamina = ctBEu16( static_cast<u16>(v) ); - - v = me->vital( vital->vitalid ).maximum_ones(); - if (v > 0xFFFF) - v = 0xFFFF; - msg.max_stamina = ctBEu16( static_cast<u16>(v) ); - - client->transmit( &msg, sizeof msg ); - - if (me->party()!=NULL) - me->party()->on_stam_changed(me); -} -void send_uo_strength( Client* client, Character* me, const Attribute* attr ) -{ - send_full_statmsg( client, me ); -} -void send_uo_dexterity( Client* client, Character* me, const Attribute* attr ) -{ - send_full_statmsg( client, me ); -} -void send_uo_intelligence( Client* client, Character* me, const Attribute* attr ) -{ - send_full_statmsg( client, me ); -} -void send_uo_skill( Client* client, Character* me, const Attribute* attr ) -{ - ClientAttributeUpdaters& cau = client->Interface.attribute_updaters[ attr->attrid ]; - - if (!ssopt.core_sends_caps) { - PKTBI_3A_VALUES msg; - unsigned short msglen = offsetof(PKTBI_3A_VALUES,skills) + - sizeof(msg.skills[0]); - - msg.msgtype = PKTBI_3A_VALUES_ID; - msg.msglen = ctBEu16( msglen ); - msg.unk3 = PKTBI_3A_VALUES::SINGLE_SKILL; - msg.skills[0].skillid = ctBEu16(cau.pUOSkill->skillid); // er, no conversion here. !! - const AttributeValue& av = me->attribute(attr->attrid); - msg.skills[0].value = ctBEu16( static_cast<u16>(av.effective_tenths()) ); - msg.skills[0].value_unmod = ctBEu16( static_cast<u16>(av.base()) ); // base is always in tenths... - msg.skills[0].lock_mode = (u8)av.lock();//PKTBI_3A_VALUES::LOCK_NONE; - client->transmit( &msg, msglen ); - } else { - PKTBI_3A_CAPS msg; - unsigned short msglen = offsetof(PKTBI_3A_VALUES,skills) + - sizeof(msg.skills[0]); - - msg.msgtype = PKTBI_3A_VALUES_ID; - msg.msglen = ctBEu16( msglen ); - msg.unk3 = PKTBI_3A_VALUES::SINGLE_SKILL_CAP; - msg.skills[0].skillid = ctBEu16(cau.pUOSkill->skillid); // er, no conversion here. !! - const AttributeValue& av = me->attribute(attr->attrid); - msg.skills[0].value = ctBEu16( static_cast<u16>(av.effective_tenths()) ); - msg.skills[0].value_unmod = ctBEu16( static_cast<u16>(av.base()) ); // base is always in tenths... - msg.skills[0].lock_mode = (u8)av.lock();//PKTBI_3A_VALUES::LOCK_NONE; - msg.skills[0].cap = ctBEu16( static_cast<u16>(av.cap()) ); - client->transmit( &msg, msglen ); - } -} -void ClientInterface::Initialize() -{ - vital_updaters.resize( vitals.size() ); - attribute_updaters.resize( attributes.size() ); -} - -void UOClientInterface::Initialize() -{ - ClientInterface::Initialize(); - - // tell a player's own client when his life changes - if (uoclient_general.hits.any) - { - vital_updaters[ uoclient_general.hits.id ].my_vital_changed = send_uo_hits; - vital_updaters[ uoclient_general.hits.id ].others_vital_changed = send_uo_hits; - } - if (uoclient_general.mana.any) - { - vital_updaters[ uoclient_general.mana.id ].my_vital_changed = send_uo_mana; - } - if (uoclient_general.stamina.any) - { - vital_updaters[ uoclient_general.stamina.id ].my_vital_changed = send_uo_stamina; - } - - if (uoclient_general.strength.any) - { - attribute_updaters[ uoclient_general.strength.id ].my_attr_changed = send_uo_strength; - } - if (uoclient_general.intelligence.any) - { - attribute_updaters[ uoclient_general.intelligence.id ].my_attr_changed = send_uo_intelligence; - } - if (uoclient_general.dexterity.any) - { - attribute_updaters[ uoclient_general.dexterity.id ].my_attr_changed = send_uo_dexterity; - } - - for( unsigned i = 0; i < uoclient_general.maxskills+1; ++i ) - { - const UOSkill& uoskill = GetUOSkill( i ); - if (uoskill.inited && uoskill.pAttr) - { - attribute_updaters[ uoskill.pAttr->attrid ].my_attr_changed = send_uo_skill; - attribute_updaters[ uoskill.pAttr->attrid ].pUOSkill = &uoskill; - } - } -} - -void UOClientInterface::bcast_vital_changed( Character* who, const Vital* vital ) const -{ - const ClientVitalUpdaters& cvu = vital_updaters[ vital->vitalid ]; - if (cvu.others_vital_changed != NULL) - { - for( unsigned i = 0; i < clients.size(); ++i ) - { - Client* client = clients[i]; - if (client->ready && inrange(who, client->chr)) - { - cvu.others_vital_changed(client,who,vital); - } - } - } -} Deleted: trunk/pol-core/pol/cliface.h =================================================================== --- trunk/pol-core/pol/cliface.h 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/cliface.h 2009-09-07 20:37:38 UTC (rev 33) @@ -1,77 +0,0 @@ -/* -History -======= - - -Notes -======= - -*/ - -#ifndef CLIFACE_H -#define CLIFACE_H - -#include <vector> - -class Attribute; -class Client; -class Character; -class Vital; -class UOSkill; - -struct ClientVitalUpdaters -{ -public: - ClientVitalUpdaters(); - - void (*my_vital_changed)(Client* client, Character* me, const Vital* vital); - void (*others_vital_changed)(Client* client, Character* him, const Vital* vital); -}; - -struct ClientAttributeUpdaters -{ -public: - ClientAttributeUpdaters(); - - void (*my_attr_changed)(Client* client, Character* me, const Attribute* attr); - - const UOSkill* pUOSkill; -}; - -class ClientInterface -{ -public: - virtual ~ClientInterface() {} - - void register_client( Client* client ); - void deregister_client( Client* client ); - - static void tell_vital_changed( Character* who, const Vital* vital ); - static void tell_attribute_changed( Character* who, const Attribute* attr ); - -protected: - virtual void Initialize(); - - virtual void bcast_vital_changed( Character* who, const Vital* vital ) const = 0; - - std::vector<ClientVitalUpdaters> vital_updaters; - std::vector<ClientAttributeUpdaters> attribute_updaters; - - std::vector<Client*> clients; - - friend void send_uo_skill( Client* client, Character* me, const Attribute* attr ); - -}; - -class UOClientInterface : public ClientInterface -{ -public: - void Initialize(); - -protected: - friend class ClientInterface; - virtual void bcast_vital_changed( Character* who, const Vital* vital ) const; -}; -extern UOClientInterface uo_client_interface; - -#endif Modified: trunk/pol-core/pol/containr.cpp =================================================================== --- trunk/pol-core/pol/containr.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/containr.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -30,7 +30,7 @@ #include "clib/random.h" #include "clib/stlutil.h" -#include "client.h" +#include "network/client.h" #include "mobile/charactr.h" #include "core.h" #include "equipmnt.h" Modified: trunk/pol-core/pol/core.cpp =================================================================== --- trunk/pol-core/pol/core.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/core.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -13,8 +13,8 @@ #include "plib/realm.h" #include "mobile/charactr.h" -#include "cgdata.h" -#include "client.h" +#include "network/cgdata.h" +#include "network/client.h" #include "core.h" #include "itemdesc.h" #include "polsem.h" Modified: trunk/pol-core/pol/create.cpp =================================================================== --- trunk/pol-core/pol/create.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/create.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -30,7 +30,7 @@ #include "mobile/attribute.h" #include "mobile/charactr.h" #include "clidata.h" -#include "client.h" +#include "network/client.h" #include "gameclck.h" #include "layers.h" #include "mkscrobj.h" Modified: trunk/pol-core/pol/dblclick.cpp =================================================================== --- trunk/pol-core/pol/dblclick.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/dblclick.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -25,7 +25,7 @@ #include "plib/realm.h" -#include "client.h" +#include "network/client.h" #include "eventid.h" #include "itemdesc.h" #include "msghandl.h" Modified: trunk/pol-core/pol/door.cpp =================================================================== --- trunk/pol-core/pol/door.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/door.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -16,7 +16,7 @@ #include "clib/endian.h" #include "clib/passert.h" -#include "client.h" +#include "network/client.h" #include "door.h" #include "itemdesc.h" #include "objtype.h" Modified: trunk/pol-core/pol/dropitem.cpp =================================================================== --- trunk/pol-core/pol/dropitem.cpp 2009-09-07 18:27:08 UTC (rev 32) +++ trunk/pol-core/pol/dropitem.cpp 2009-09-07 20:37:38 UTC (rev 33) @@ -40,7 +40,7 @@ #include "multi/boat.h" #include "mobile/charactr.h" -#include "client.h" +#include "network/client.h" #include "dtrace.h" #include "getitem.h" #incl... [truncated message content] |