diff options
Diffstat (limited to 'src/char')
-rw-r--r-- | src/char/HPMchar.c | 18 | ||||
-rw-r--r-- | src/char/HPMchar.h | 2 | ||||
-rw-r--r-- | src/char/char.c | 92 | ||||
-rw-r--r-- | src/char/char.h | 3 | ||||
-rw-r--r-- | src/char/loginif.c | 4 |
5 files changed, 64 insertions, 55 deletions
diff --git a/src/char/HPMchar.c b/src/char/HPMchar.c index a67f017c1..d3150bc11 100644 --- a/src/char/HPMchar.c +++ b/src/char/HPMchar.c @@ -47,13 +47,19 @@ // HPMDataCheck comes after all the other includes #include "common/HPMDataCheck.h" -bool HPM_char_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr) { - /* record address */ - switch( type ) { +/** + * HPM plugin data store validator sub-handler (char-server) + * + * @see HPM_interface::data_store_validate + */ +bool HPM_char_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize) +{ + switch (type) { + // No supported types at the moment. default: - return false; + break; } - return true; + return false; } void HPM_char_plugin_load_sub(struct hplugin *plugin) { @@ -61,6 +67,8 @@ void HPM_char_plugin_load_sub(struct hplugin *plugin) { } void HPM_char_do_init(void) { + HPM->load_sub = HPM_char_plugin_load_sub; + HPM->data_store_validate_sub = HPM_char_data_store_validate; HPM->datacheck_init(HPMDataCheck, HPMDataCheckLen, HPMDataCheckVer); HPM_shared_symbols(SERVER_TYPE_CHAR); } diff --git a/src/char/HPMchar.h b/src/char/HPMchar.h index e3e000ef3..431017b7a 100644 --- a/src/char/HPMchar.h +++ b/src/char/HPMchar.h @@ -13,7 +13,7 @@ struct hplugin; -bool HPM_char_grabHPData(struct HPDataOperationStorage *ret, enum HPluginDataTypes type, void *ptr); +bool HPM_char_data_store_validate(enum HPluginDataTypes type, struct hplugin_data_store **storeptr, bool initialize); void HPM_char_plugin_load_sub(struct hplugin *plugin); diff --git a/src/char/char.c b/src/char/char.c index 3cc8853a4..1e0428a3d 100644 --- a/src/char/char.c +++ b/src/char/char.c @@ -2626,10 +2626,12 @@ int char_parse_fromlogin(int fd) { while(RFIFOREST(fd) >= 2) { uint16 command = RFIFOW(fd,0); - if( HPM->packetsc[hpParse_FromLogin] ) { - int success = HPM->parse_packets(fd,hpParse_FromLogin); - if( success == 1 ) continue; - else if( success == 2 ) return 0; + if (VECTOR_LENGTH(HPM->packets[hpParse_FromLogin]) > 0) { + int result = HPM->parse_packets(fd,hpParse_FromLogin); + if (result == 1) + continue; + if (result == 2) + return 0; } switch (command) { @@ -2965,9 +2967,11 @@ void mapif_server_reset(int id) WBUFL(buf,4) = htonl(chr->server[id].ip); WBUFW(buf,8) = htons(chr->server[id].port); j = 0; - for(i = 0; i < chr->server[id].maps; i++) - if (chr->server[id].map[i]) - WBUFW(buf,10+(j++)*4) = chr->server[id].map[i]; + for (i = 0; i < VECTOR_LENGTH(chr->server[id].maps); i++) { + uint16 m = VECTOR_INDEX(chr->server[id].maps, i); + if (m != 0) + WBUFW(buf,10+(j++)*4) = m; + } if (j > 0) { WBUFW(buf,2) = j * 4 + 10; mapif->sendallwos(fd, buf, WBUFW(buf,2)); @@ -3050,14 +3054,16 @@ void char_send_maps(int fd, int id, int j) // Transmitting the maps of the other map-servers to the new map-server for(k = 0; k < ARRAYLENGTH(chr->server); k++) { if (chr->server[k].fd > 0 && k != id) { - WFIFOHEAD(fd,10 +4*chr->server[k].maps); + WFIFOHEAD(fd,10 + 4 * VECTOR_LENGTH(chr->server[k].maps)); WFIFOW(fd,0) = 0x2b04; WFIFOL(fd,4) = htonl(chr->server[k].ip); WFIFOW(fd,8) = htons(chr->server[k].port); j = 0; - for(i = 0; i < chr->server[k].maps; i++) - if (chr->server[k].map[i]) - WFIFOW(fd,10+(j++)*4) = chr->server[k].map[i]; + for(i = 0; i < VECTOR_LENGTH(chr->server[k].maps); i++) { + uint16 m = VECTOR_INDEX(chr->server[k].maps, i); + if (m != 0) + WFIFOW(fd,10+(j++)*4) = m; + } if (j > 0) { WFIFOW(fd,2) = j * 4 + 10; WFIFOSET(fd,WFIFOW(fd,2)); @@ -3068,27 +3074,22 @@ void char_send_maps(int fd, int id, int j) void char_parse_frommap_map_names(int fd, int id) { - int i,j = 0; - - if( chr->server[id].map != NULL ) { aFree(chr->server[id].map); chr->server[id].map = NULL; } - - chr->server[id].maps = ( RFIFOW(fd, 2) - 4 ) / 4; - CREATE(chr->server[id].map, unsigned short, chr->server[id].maps); - + int i; - for(i = 4; i < RFIFOW(fd,2); i += 4) { - chr->server[id].map[j] = RFIFOW(fd,i); - j++; + VECTOR_CLEAR(chr->server[id].maps); + VECTOR_ENSURE(chr->server[id].maps, (RFIFOW(fd, 2) - 4) / 4, 1); + for (i = 4; i < RFIFOW(fd,2); i += 4) { + VECTOR_PUSH(chr->server[id].maps, RFIFOW(fd,i)); } ShowStatus("Map-Server %d connected: %d maps, from IP %d.%d.%d.%d port %d.\n", - id, j, CONVIP(chr->server[id].ip), chr->server[id].port); + id, (int)VECTOR_LENGTH(chr->server[id].maps), CONVIP(chr->server[id].ip), chr->server[id].port); ShowStatus("Map-server %d loading complete.\n", id); // send name for wisp to player chr->map_received_ok(fd); chr->send_fame_list(fd); //Send fame list. - chr->send_maps(fd, id, j); + chr->send_maps(fd, id, (int)VECTOR_LENGTH(chr->server[id].maps)); RFIFOSKIP(fd,RFIFOW(fd,2)); } @@ -3896,7 +3897,6 @@ void char_parse_frommap_scdata_delete(int fd) int char_parse_frommap(int fd) { - int i; int id; ARR_FIND( 0, ARRAYLENGTH(chr->server), id, chr->server[id].fd == fd ); @@ -3913,11 +3913,12 @@ int char_parse_frommap(int fd) } while(RFIFOREST(fd) >= 2) { - if( HPM->packetsc[hpParse_FromMap] ) { - if( (i = HPM->parse_packets(fd,hpParse_FromMap)) ) { - if( i == 1 ) continue; - if( i == 2 ) return 0; - } + if (VECTOR_LENGTH(HPM->packets[hpParse_FromMap]) > 0) { + int result = HPM->parse_packets(fd,hpParse_FromMap); + if (result == 1) + continue; + if (result == 2) + return 0; } switch(RFIFOW(fd,0)) { @@ -4154,11 +4155,11 @@ int char_search_mapserver(unsigned short map, uint32 ip, uint16 port) { if (chr->server[i].fd > 0 && (ip == (uint32)-1 || chr->server[i].ip == ip) - && (port == (uint16)-1 || chr->server[i].port == port)) - { - for (j = 0; chr->server[i].map[j]; j++) - if (chr->server[i].map[j] == map) - return i; + && (port == (uint16)-1 || chr->server[i].port == port) + ) { + ARR_FIND(0, VECTOR_LENGTH(chr->server[i].maps), j, VECTOR_INDEX(chr->server[i].maps, j) == map); + if (j != VECTOR_LENGTH(chr->server[i].maps)) + return i; } } @@ -4577,7 +4578,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) } #endif - ARR_FIND( 0, ARRAYLENGTH(chr->server), server_id, chr->server[server_id].fd > 0 && chr->server[server_id].map ); + ARR_FIND(0, ARRAYLENGTH(chr->server), server_id, chr->server[server_id].fd > 0 && VECTOR_LENGTH(chr->server[server_id].maps) > 0); /* not available, tell it to wait (client wont close; char select will respawn). * magic response found by Ind thanks to Yommy <3 */ if( server_id == ARRAYLENGTH(chr->server) ) { @@ -4638,7 +4639,7 @@ void char_parse_char_select(int fd, struct char_session_data* sd, uint32 ipl) if (i < 0 || !cd->last_point.map) { unsigned short j; //First check that there's actually a map server online. - ARR_FIND( 0, ARRAYLENGTH(chr->server), j, chr->server[j].fd >= 0 && chr->server[j].map ); + ARR_FIND(0, ARRAYLENGTH(chr->server), j, chr->server[j].fd >= 0 && VECTOR_LENGTH(chr->server[j].maps) > 0); if (j == ARRAYLENGTH(chr->server)) { ShowInfo("Connection Closed. No map servers available.\n"); chr->authfail_fd(fd, 1); // 1 = Server closed @@ -5095,10 +5096,12 @@ int char_parse_char(int fd) //For use in packets that depend on an sd being present [Skotlex] #define FIFOSD_CHECK(rest) do { if(RFIFOREST(fd) < (rest)) return 0; if (sd==NULL || !sd->auth) { RFIFOSKIP(fd,(rest)); return 0; } } while (0) - if( HPM->packetsc[hpParse_Char] ) { - int success = HPM->parse_packets(fd,hpParse_Char); - if( success == 1 ) continue; - else if( success == 2 ) return 0; + if (VECTOR_LENGTH(HPM->packets[hpParse_Char]) > 0) { + int result = HPM->parse_packets(fd,hpParse_Char); + if (result == 1) + continue; + if (result == 2) + return 0; } cmd = RFIFOW(fd,0); @@ -5785,9 +5788,8 @@ int do_final(void) { SQL->Free(inter->sql_handle); mapindex->final(); - for(i = 0; i < MAX_MAP_SERVERS; i++ ) - if( chr->server[i].map ) - aFree(chr->server[i].map); + for (i = 0; i < MAX_MAP_SERVERS; i++) + VECTOR_CLEAR(chr->server[i].maps); aFree(chr->CHAR_CONF_NAME); aFree(chr->NET_CONF_NAME); @@ -5886,8 +5888,8 @@ int do_init(int argc, char **argv) { chr->SQL_CONF_NAME = aStrdup("conf/inter-server.conf"); chr->INTER_CONF_NAME = aStrdup("conf/inter-server.conf"); - for(i = 0; i < MAX_MAP_SERVERS; i++ ) - chr->server[i].map = NULL; + for (i = 0; i < MAX_MAP_SERVERS; i++) + VECTOR_INIT(chr->server[i].maps); HPM_char_do_init(); cmdline->exec(argc, argv, CMDLINE_OPT_PREINIT); diff --git a/src/char/char.h b/src/char/char.h index e79cc1898..fe6c0b9da 100644 --- a/src/char/char.h +++ b/src/char/char.h @@ -49,8 +49,7 @@ struct mmo_map_server { uint32 ip; uint16 port; int users; - unsigned short *map; - unsigned short maps; + VECTOR_DECL(uint16) maps; }; #define MAX_MAP_SERVERS 2 diff --git a/src/char/loginif.c b/src/char/loginif.c index 422c7c589..e99e05237 100644 --- a/src/char/loginif.c +++ b/src/char/loginif.c @@ -63,8 +63,8 @@ void loginif_on_ready(void) chr->send_accounts_tologin(INVALID_TIMER, timer->gettick(), 0, 0); // if no map-server already connected, display a message... - ARR_FIND( 0, ARRAYLENGTH(chr->server), i, chr->server[i].fd > 0 && chr->server[i].map ); - if( i == ARRAYLENGTH(chr->server) ) + ARR_FIND(0, ARRAYLENGTH(chr->server), i, chr->server[i].fd > 0 && VECTOR_LENGTH(chr->server[i].maps)); + if (i == ARRAYLENGTH(chr->server)) ShowStatus("Awaiting maps from map-server.\n"); } |