From 28eedb41600c4c6617cd38905b3e55c879180754 Mon Sep 17 00:00:00 2001 From: FlavioJS Date: Sat, 5 May 2007 14:50:07 +0000 Subject: * Removed the dependency on winsock.h for definitions, it's all winsock2.h now. * Minor documentation/re-coding in chat.c. * More work on ticket #41. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@10471 54d463be-8e91-2dee-dedb-b68131a5f0ec --- Changelog-Trunk.txt | 3 + src/char_sql/inter.h | 9 +- src/common/cbasetypes.h | 4 + src/common/lock.c | 8 +- src/common/plugin.h | 4 +- src/common/plugins.h | 5 + src/common/showmsg.c | 9 +- src/common/socket.c | 25 +-- src/common/socket.h | 9 +- src/common/timer.c | 17 +- src/common/timer.h | 11 +- src/login_sql/login.c | 3 + src/map/chat.c | 156 ++++++++-------- src/map/map.h | 16 +- src/map/script.c | 467 +++++++++++++++++++++++++++++------------------- 15 files changed, 439 insertions(+), 307 deletions(-) diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 3efea78cd..c60aa2a20 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -4,6 +4,9 @@ AS OF SVN REV. 5091, WE ARE NOW USING TRUNK. ALL UNTESTED BUGFIXES/FEATURES GO IF YOU HAVE A WORKING AND TESTED BUGFIX PUT IT INTO STABLE AS WELL AS TRUNK. 2007/05/06 + * Removed the dependency on winsock.h for definitions, it's all winsock2.h now. + * Minor documentation/re-coding in chat.c. + * More work on ticket #41. [FLavioJS] * Fixed Red Pouch overriding nobranch mapflag [Playtester] * Attempt to fix Kyrie Eleison not castable on enemy players [Playtester] - please test, I can't double client to test it in pvp diff --git a/src/char_sql/inter.h b/src/char_sql/inter.h index c1567cfe6..98b0fc49d 100644 --- a/src/char_sql/inter.h +++ b/src/char_sql/inter.h @@ -4,6 +4,10 @@ #ifndef _INTER_SQL_H_ #define _INTER_SQL_H_ +#ifndef _CBASETYPES_H_ +#include "../common/cbasetypes.h" +#endif + int inter_init_sql(const char *file); void inter_final(void); int inter_parse_frommap(int fd); @@ -21,9 +25,8 @@ int inter_log(char *fmt,...); extern unsigned int party_share_level; extern char inter_log_filename[1024]; -#ifdef __WIN32 -//Windows.h need to be included before mysql.h -#include +#ifdef WIN32 +#include #endif //add include for DBMS(mysql) #include diff --git a/src/common/cbasetypes.h b/src/common/cbasetypes.h index 00296588e..468c0c8d0 100644 --- a/src/common/cbasetypes.h +++ b/src/common/cbasetypes.h @@ -307,4 +307,8 @@ typedef char bool; #define TOLOWER(c) (tolower((unsigned char)(c))) #define TOUPPER(c) (toupper((unsigned char)(c))) +////////////////////////////////////////////////////////////////////////// +// length of a static array +#define ARRAYLENGTH(A) ( sizeof(A)/sizeof((A)[0]) ) + #endif /* _CBASETYPES_H_ */ diff --git a/src/common/lock.c b/src/common/lock.c index a08b46756..e4ec36302 100644 --- a/src/common/lock.c +++ b/src/common/lock.c @@ -1,6 +1,10 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder +#include "../common/cbasetypes.h" +#include "../common/showmsg.h" +#include "lock.h" + #include #include #include @@ -11,10 +15,8 @@ #define F_OK 0x0 #define R_OK 0x4 #endif -#include "lock.h" -#include "showmsg.h" -#ifndef _WIN32 +#ifndef WIN32 #define exists(filename) (!access(filename, F_OK)) #else // could be speed up maybe? diff --git a/src/common/plugin.h b/src/common/plugin.h index 3ddbaae98..8aef934d0 100644 --- a/src/common/plugin.h +++ b/src/common/plugin.h @@ -4,7 +4,9 @@ #ifndef _PLUGIN_H_ #define _PLUGIN_H_ -#include "cbasetypes.h" +#ifndef _CBASETYPES_H_ +#include "../common/cbasetypes.h" +#endif ////// Plugin functions /////////////// diff --git a/src/common/plugins.h b/src/common/plugins.h index 70dd6b326..b4235e72d 100644 --- a/src/common/plugins.h +++ b/src/common/plugins.h @@ -4,12 +4,17 @@ #ifndef _PLUGINS_H_ #define _PLUGINS_H_ +#ifndef _CBASETYPES_H_ +#include "../common/cbasetypes.h" +#endif + #include "../common/plugin.h" ////// Dynamic Link Library functions /////////////// #ifdef WIN32 + #define WIN32_LEAN_AND_MEAN #include #define DLL_OPEN(x) LoadLibrary(x) #define DLL_SYM(x,y,z) (FARPROC)(x) = GetProcAddress(y,z) diff --git a/src/common/showmsg.c b/src/common/showmsg.c index f56c66525..34338da4b 100644 --- a/src/common/showmsg.c +++ b/src/common/showmsg.c @@ -1,16 +1,17 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder +#include "../common/cbasetypes.h" +#include "../common/utils.h" +#include "showmsg.h" + #include #include #include #include #include // atexit -#include "cbasetypes.h" -#include "showmsg.h" -#include "utils.h" -#ifdef _WIN32 +#ifdef WIN32 #define WIN32_LEAN_AND_MEAN #include diff --git a/src/common/socket.c b/src/common/socket.c index 73b0fb06b..efc51b99d 100644 --- a/src/common/socket.c +++ b/src/common/socket.c @@ -1,14 +1,22 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder +#include "../common/cbasetypes.h" +#include "../common/mmo.h" +#include "../common/timer.h" +#include "../common/malloc.h" +#include "../common/showmsg.h" +#include "../common/strlib.h" +#include "socket.h" + #include #include #include #include -#ifdef __WIN32 - #define WIN32_LEAN_AND_MEAN - #include +#ifdef WIN32 + //#define WIN32_LEAN_AND_MEAN + //#include #include #include #else @@ -29,7 +37,7 @@ #endif // portability layer -#ifdef _WIN32 +#ifdef WIN32 typedef int socklen_t; #define s_errno WSAGetLastError() @@ -52,13 +60,6 @@ #define S_ECONNABORTED ECONNABORTED #endif -#include "../common/socket.h" -#include "../common/mmo.h" -#include "../common/timer.h" -#include "../common/malloc.h" -#include "../common/showmsg.h" -#include "../common/strlib.h" - fd_set readfds; int fd_max; time_t last_tick; @@ -561,7 +562,7 @@ int do_sendrecv(int next) fd_max = ret; } -#ifdef _WIN32 +#ifdef WIN32 // on windows, enumerating all members of the fd_set is way faster if we access the internals for(i=0;i<(int)rfd.fd_count;i++) { diff --git a/src/common/socket.h b/src/common/socket.h index 64190d6e7..3d860e166 100644 --- a/src/common/socket.h +++ b/src/common/socket.h @@ -4,10 +4,12 @@ #ifndef _SOCKET_H_ #define _SOCKET_H_ +#ifndef _CBASETYPES_H_ +#include "../common/cbasetypes.h" +#endif + #ifdef WIN32 - #define WIN32_LEAN_AND_MEAN - #include - #include + #include typedef long in_addr_t; #else #include @@ -15,7 +17,6 @@ #include #endif -#include "../common/cbasetypes.h" #include diff --git a/src/common/timer.c b/src/common/timer.c index 6c228839c..09be7d949 100644 --- a/src/common/timer.c +++ b/src/common/timer.c @@ -3,11 +3,17 @@ #include -#ifdef __WIN32 -#define __USE_W32_SOCKETS +#include "../common/cbasetypes.h" +#include "../common/malloc.h" +#include "../common/showmsg.h" +#include "timer.h" + +#ifdef WIN32 +//#define __USE_W32_SOCKETS // Well, this won't last another 30++ years (where conversion will truncate). //#define _USE_32BIT_TIME_T // use 32 bit time variables on 64bit windows -#include +//#include +#include #else #include #include @@ -18,11 +24,6 @@ #include #include -#include "../common/cbasetypes.h" -#include "../common/malloc.h" -#include "../common/showmsg.h" -#include "timer.h" - // タイマー間隔の最小値。モンスターの大量召還時、多数のクライアント接続時に // サーバーが反応しなくなる場合は、TIMER_MIN_INTERVAL を増やしてください。 diff --git a/src/common/timer.h b/src/common/timer.h index 23cb6beaa..24534de2a 100644 --- a/src/common/timer.h +++ b/src/common/timer.h @@ -4,10 +4,15 @@ #ifndef _TIMER_H_ #define _TIMER_H_ -#ifdef __WIN32 +#ifndef _CBASETYPES_H_ +#include "../common/cbasetypes.h" +#endif + +#ifdef WIN32 /* We need winsock lib to have timeval struct - windows is weirdo */ -#define __USE_W32_SOCKETS -#include +//#define __USE_W32_SOCKETS +//#include +#include #endif #define BASE_TICK 5 diff --git a/src/login_sql/login.c b/src/login_sql/login.c index bff047492..4b3c4c4a2 100644 --- a/src/login_sql/login.c +++ b/src/login_sql/login.c @@ -22,6 +22,9 @@ #include "login.h" //add include for DBMS(mysql) +#ifdef WIN32 +#include +#endif #include struct Login_Config { diff --git a/src/map/chat.c b/src/map/chat.c index 28ddbe8c4..e66ed7dc3 100644 --- a/src/map/chat.c +++ b/src/map/chat.c @@ -1,18 +1,19 @@ // Copyright (c) Athena Dev Teams - Licensed under GNU GPL // For more information, see LICENCE in the main folder -#include -#include - +#include "../common/cbasetypes.h" #include "../common/nullpo.h" #include "../common/malloc.h" #include "battle.h" -#include "chat.h" #include "map.h" #include "clif.h" #include "pc.h" #include "npc.h" #include "atcommand.h" +#include "chat.h" + +#include +#include int chat_triggerevent(struct chat_data *cd); @@ -107,57 +108,58 @@ int chat_joinchat(struct map_session_data* sd, int chatid, char* pass) return 0; } -/*========================================== - * チャットルームから抜ける - *------------------------------------------ - */ -int chat_leavechat(struct map_session_data *sd) +/// Removes the user from the chat room. +int chat_leavechat(struct map_session_data* sd) { - struct chat_data *cd; - int i,leavechar; + struct chat_data* cd; + int i; + int leavechar; nullpo_retr(1, sd); - cd=(struct chat_data*)map_id2bl(sd->chatID); - if(cd==NULL) { - sd->chatID = 0; + cd = (struct chat_data*)map_id2bl(sd->chatID); + if( cd == NULL ) + { + pc_setchatid(sd, 0); return 1; } - for(i = 0,leavechar=-1;i < cd->users;i++){ + for( i = 0, leavechar = -1; i < cd->users; i++ ) + { if(cd->usersd[i] == sd){ leavechar=i; break; } } - if(leavechar<0) - { //Not found in the chatroom? - sd->chatID = 0; + if( leavechar < 0 ) + {// Not found in the chatroom? + pc_setchatid(sd, 0); return -1; } - if(leavechar==0 && cd->users>1 && (*cd->owner)->type==BL_PC){ - // 所有者だった&他に人が居る&PCのチャット - clif_changechatowner(cd,cd->usersd[1]); - clif_clearchat(cd,0); + if( leavechar == 0 && cd->users > 1 && (*cd->owner)->type == BL_PC ) + {// Change ownership to the next user + clif_changechatowner(cd, cd->usersd[1]); + clif_clearchat(cd, 0); } // 抜けるPCにも送るのでusersを減らす前に実行 - clif_leavechat(cd,sd); + clif_leavechat(cd, sd); cd->users--; - pc_setchatid(sd,0); + pc_setchatid(sd, 0); - if(cd->users == 0 && (*cd->owner)->type==BL_PC){ - //Delete empty chatroom - clif_clearchat(cd,0); + if( cd->users == 0 && (*cd->owner)->type==BL_PC ) + {// Delete empty chatroom + clif_clearchat(cd, 0); map_delobject(cd->bl.id); return 1; } - for(i=leavechar;i < cd->users;i++) - cd->usersd[i] = cd->usersd[i+1]; + for( i = leavechar; i < cd->users; i++ ) + cd->usersd[i] = cd->usersd[i + 1]; - if(leavechar==0 && (*cd->owner)->type==BL_PC){ + if( leavechar == 0 && (*cd->owner)->type==BL_PC ) + { //Adjust Chat location after owner has been changed. map_delblock( &cd->bl ); cd->bl.x=cd->usersd[0]->bl.x; @@ -272,11 +274,8 @@ int chat_kickchat(struct map_session_data *sd,char *kickusername) return -1; } -/*========================================== - * npcチャットルーム作成 - *------------------------------------------ - */ -int chat_createnpcchat(struct npc_data *nd,int limit,int pub,int trigger,const char* title,int titlelen,const char *ev) +/// Creates a chat room for the npc. +int chat_createnpcchat(struct npc_data* nd,int limit,int pub,int trigger,const char* title,int titlelen,const char *ev) { struct chat_data *cd; @@ -285,45 +284,40 @@ int chat_createnpcchat(struct npc_data *nd,int limit,int pub,int trigger,const c cd = (struct chat_data *) aMalloc(sizeof(struct chat_data)); cd->limit = cd->trigger = limit; - if(trigger>0) + if( trigger > 0 ) cd->trigger = trigger; cd->pub = pub; cd->users = 0; - memcpy(cd->pass,"",1); - if(titlelen>=sizeof(cd->title)-1) titlelen=sizeof(cd->title)-1; - memcpy(cd->title,title,titlelen); - cd->title[titlelen]=0; - - cd->bl.m = nd->bl.m; - cd->bl.x = nd->bl.x; - cd->bl.y = nd->bl.y; + cd->pass[0] = '\0'; + if( titlelen > sizeof(cd->title) - 1 ) + titlelen = sizeof(cd->title) - 1; + memcpy(cd->title, title, titlelen); + cd->title[titlelen] = '\0'; + + cd->bl.m = nd->bl.m; + cd->bl.x = nd->bl.x; + cd->bl.y = nd->bl.y; cd->bl.type = BL_CHAT; - cd->bl.prev= cd->bl.next = NULL; - cd->owner_ = (struct block_list *)nd; - cd->owner = &cd->owner_; - if (strlen(ev) > 49) - { //npc_event is a char[50] [Skotlex] - memcpy(cd->npc_event,ev,49); - cd->npc_event[49] = '\0'; - } else - memcpy(cd->npc_event,ev,strlen(ev)+1); //Include the \0 - + cd->bl.prev = cd->bl.next = NULL; + cd->owner_ = (struct block_list *)nd; + cd->owner = &cd->owner_; + strncpy(cd->npc_event, ev, ARRAYLENGTH(cd->npc_event)); + cd->npc_event[ARRAYLENGTH(cd->npc_event)-1] = '\0'; cd->bl.id = map_addobject(&cd->bl); - if(cd->bl.id==0){ + if( cd->bl.id == 0) + { aFree(cd); return 0; } - nd->chat_id=cd->bl.id; + nd->chat_id = cd->bl.id; - clif_dispchat(cd,0); + clif_dispchat(cd, 0); return 0; } -/*========================================== - * npcチャットルーム削除 - *------------------------------------------ - */ -int chat_deletenpcchat(struct npc_data *nd) + +/// Removes the chatroom from the npc. +int chat_deletenpcchat(struct npc_data* nd) { struct chat_data *cd; @@ -331,9 +325,9 @@ int chat_deletenpcchat(struct npc_data *nd) nullpo_retr(0, cd=(struct chat_data*)map_id2bl(nd->chat_id)); chat_npckickall(cd); - clif_clearchat(cd,0); + clif_clearchat(cd, 0); map_delobject(cd->bl.id); // freeまでしてくれる - nd->chat_id=0; + nd->chat_id = 0; return 0; } @@ -346,44 +340,38 @@ int chat_triggerevent(struct chat_data *cd) { nullpo_retr(0, cd); - if(cd->users>=cd->trigger && cd->npc_event[0]) + if( cd->users >= cd->trigger && cd->npc_event[0] ) npc_event_do(cd->npc_event); return 0; } -/*========================================== - * イベントの有効化 - *------------------------------------------ - */ -int chat_enableevent(struct chat_data *cd) +/// Enables the event of the chat room. +/// At most, 127 users are needed to trigger the event. +int chat_enableevent(struct chat_data* cd) { nullpo_retr(0, cd); - cd->trigger&=0x7f; + cd->trigger &= 0x7f; chat_triggerevent(cd); return 0; } -/*========================================== - * イベントの無効化 - *------------------------------------------ - */ -int chat_disableevent(struct chat_data *cd) + +/// Disables the event of the chat room +int chat_disableevent(struct chat_data* cd) { nullpo_retr(0, cd); - cd->trigger|=0x80; + cd->trigger |= 0x80; return 0; } -/*========================================== - * チャットルームから全員蹴り出す - *------------------------------------------ - */ -int chat_npckickall(struct chat_data *cd) + +/// Kicks all the users for the chat room. +int chat_npckickall(struct chat_data* cd) { nullpo_retr(0, cd); - while(cd->users>0){ + while( cd->users > 0 ) chat_leavechat(cd->usersd[cd->users-1]); - } + return 0; } diff --git a/src/map/map.h b/src/map/map.h index 6178b364d..fc7affdf3 100644 --- a/src/map/map.h +++ b/src/map/map.h @@ -4,7 +4,9 @@ #ifndef _MAP_H_ #define _MAP_H_ -#include +#ifndef _CBASETYPES_H_ +#include "../common/cbasetypes.h" +#endif #include "../common/mmo.h" #include "../common/mapindex.h" #include "../common/db.h" @@ -12,6 +14,8 @@ #include "itemdb.h" // MAX_ITEMGROUP #include "status.h" // SC_MAX +#include + //Uncomment to enable the Cell Stack Limit mod. //It's only config is the battle_config cell_stack_limit. //Only chars affected are those defined in BL_CHAR (mobs and players currently) @@ -387,8 +391,10 @@ struct status_change_entry { struct status_change { struct status_change_entry data[SC_MAX]; short count; - unsigned short opt1,opt2; - unsigned int opt3, option; //Note that older packet versions use short here. + unsigned short opt1;// body state + unsigned short opt2;// health state + unsigned int opt3; + unsigned int option;// effect state }; struct vending { @@ -1394,8 +1400,8 @@ extern char *map_server_dns; #ifndef TXT_ONLY -#ifdef _WIN32 -#include // SOCKET +#ifdef WIN32 +#include #endif #include diff --git a/src/map/script.c b/src/map/script.c index 1538e8d10..fe102b923 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -4026,12 +4026,12 @@ struct script_function buildin_func[] = { BUILDIN_DEF(skillpointcount,""), BUILDIN_DEF(changebase,"i"), BUILDIN_DEF(changesex,""), - BUILDIN_DEF(waitingroom,"si*"), - BUILDIN_DEF(delwaitingroom,"*"), - BUILDIN_DEF2(waitingroomkickall,"kickwaitingroomall","*"), - BUILDIN_DEF(enablewaitingroomevent,"*"), - BUILDIN_DEF(disablewaitingroomevent,"*"), - BUILDIN_DEF(getwaitingroomstate,"i*"), + BUILDIN_DEF(waitingroom,"si??"), + BUILDIN_DEF(delwaitingroom,"?"), + BUILDIN_DEF2(waitingroomkickall,"kickwaitingroomall","?"), + BUILDIN_DEF(enablewaitingroomevent,"?"), + BUILDIN_DEF(disablewaitingroomevent,"?"), + BUILDIN_DEF(getwaitingroomstate,"i?"), BUILDIN_DEF(warpwaitingpc,"sii?"), BUILDIN_DEF(attachrid,"i"), BUILDIN_DEF(detachrid,""), @@ -6797,11 +6797,12 @@ BUILDIN_FUNC(statusup2) } /// See 'doc/item_bonus.txt' -/// bonus , -/// bonus2 ,, -/// bonus3 ,,, -/// bonus4 ,,,, -/// bonus5 ,,,,, +/// +/// bonus ,; +/// bonus2 ,,; +/// bonus3 ,,,; +/// bonus4 ,,,,; +/// bonus5 ,,,,,; BUILDIN_FUNC(bonus) { int type; @@ -6856,8 +6857,13 @@ BUILDIN_FUNC(bonus) } /// Changes the level of a player skill. -/// skill ,{,} -/// @see pc_skill() for flag +/// defaults to 1 +/// =0 : set the level of the skill +/// =1 : set the temporary level of the skill +/// =2 : add to the level of the skill +/// +/// skill ,, +/// skill , BUILDIN_FUNC(skill) { int id; @@ -6879,8 +6885,12 @@ BUILDIN_FUNC(skill) } /// Changes the level of a player skill. -/// addtoskill ,{,} -/// @see pc_skill() for flag +/// like skill, but defaults to 2 +/// +/// addtoskill ,, +/// addtoskill , +/// +/// @see skill BUILDIN_FUNC(addtoskill) { int id; @@ -6901,8 +6911,9 @@ BUILDIN_FUNC(addtoskill) return 0; } -/// Increases the level of the guild skill. -/// guildskill , +/// Increases the level of a guild skill. +/// +/// guildskill ,; BUILDIN_FUNC(guildskill) { int id; @@ -6923,6 +6934,7 @@ BUILDIN_FUNC(guildskill) } /// Returns the level of the player skill. +/// /// getskilllv() -> BUILDIN_FUNC(getskilllv) { @@ -6940,6 +6952,7 @@ BUILDIN_FUNC(getskilllv) } /// Returns the level of the guild skill. +/// /// getgdskilllv(,) -> BUILDIN_FUNC(getgdskilllv) { @@ -6959,7 +6972,10 @@ BUILDIN_FUNC(getgdskilllv) } /// Returns the 'basic_skill_check' setting. -/// basicskillcheck() -> +/// This config determines if the server check the skill level of NV_BASIC +/// before alowing the basic actions. +/// +/// basicskillcheck() -> BUILDIN_FUNC(basicskillcheck) { script_pushint(st, battle_config.basic_skill_check); @@ -6967,6 +6983,7 @@ BUILDIN_FUNC(basicskillcheck) } /// Returns the GM level of the player. +/// /// getgmlevel() -> BUILDIN_FUNC(getgmlevel) { @@ -6982,6 +6999,7 @@ BUILDIN_FUNC(getgmlevel) } /// Terminates the execution of this script instance. +/// /// end BUILDIN_FUNC(end) { @@ -6989,7 +7007,8 @@ BUILDIN_FUNC(end) return 0; } -/// Checks if the player has that option. +/// Checks if the player has that effect state (option). +/// /// checkoption(