summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2010-12-11 01:23:38 +0000
committerai4rei <ai4rei@54d463be-8e91-2dee-dedb-b68131a5f0ec>2010-12-11 01:23:38 +0000
commit8dee756c8e774cd44d652d1606ab21126233a9f6 (patch)
tree310bf3bcd3d4d4dd92cdf73aaeae20e79222e6fe
parent2f22817e6ab822590613e9777f87a5690918b843 (diff)
downloadhercules-8dee756c8e774cd44d652d1606ab21126233a9f6.tar.gz
hercules-8dee756c8e774cd44d652d1606ab21126233a9f6.tar.bz2
hercules-8dee756c8e774cd44d652d1606ab21126233a9f6.tar.xz
hercules-8dee756c8e774cd44d652d1606ab21126233a9f6.zip
* Replaced buildin_getpartyname_sub, buildin_getguildname_sub and buildin_getguildmaster_sub, which create only unnecessary overhead, with equivalent inlined code.
- Fixed a memory leak in getguildmasterid, when the guild leader was not online (bugreport:2743). - Command getguildmasterid no longer requires the guild leader to be online. git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14575 54d463be-8e91-2dee-dedb-b68131a5f0ec
-rw-r--r--Changelog-Trunk.txt3
-rw-r--r--src/map/script.c131
2 files changed, 57 insertions, 77 deletions
diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt
index da347adde..c4cb57182 100644
--- a/Changelog-Trunk.txt
+++ b/Changelog-Trunk.txt
@@ -1,6 +1,9 @@
Date Added
2010/12/10
+ * Replaced buildin_getpartyname_sub, buildin_getguildname_sub and buildin_getguildmaster_sub, which create only unnecessary overhead, with equivalent inlined code. [Ai4rei]
+ - Fixed a memory leak in getguildmasterid, when the guild leader was not online (bugreport:2743).
+ - Command getguildmasterid no longer requires the guild leader to be online.
* Fixed bAutoSpellOnSkill bonuses not working independently of each other (bugreport:4617, since r13596, related r14536). [Ai4rei]
* Revised argument declaration of all script commands according to the actual functions' argument usage. [Ai4rei]
- Fixed many script commands with fixed amount of optional parameters to no longer accept any amount of arguments due to faulty declaration.
diff --git a/src/map/script.c b/src/map/script.c
index 3566222ab..e50867905 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -5938,34 +5938,21 @@ BUILDIN_FUNC(getcharid)
/*==========================================
*指定IDのPT名取得
*------------------------------------------*/
-char *buildin_getpartyname_sub(int party_id)
-{
- struct party_data *p;
-
- p=party_search(party_id);
-
- if(p!=NULL){
- char *buf;
- buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
- memcpy(buf, p->party.name, NAME_LENGTH);
- buf[NAME_LENGTH-1] = '\0';
- return buf;
- }
-
- return 0;
-}
BUILDIN_FUNC(getpartyname)
{
- char *name;
int party_id;
+ struct party_data* p;
- party_id=script_getnum(st,2);
- name=buildin_getpartyname_sub(party_id);
- if(name != NULL)
- script_pushstr(st,name);
+ party_id = script_getnum(st,2);
+
+ if( ( p = party_search(party_id) ) != NULL )
+ {
+ script_pushstrcopy(st,p->party.name);
+ }
else
+ {
script_pushconststr(st,"null");
-
+ }
return 0;
}
/*==========================================
@@ -6043,75 +6030,58 @@ BUILDIN_FUNC(getpartyleader)
/*==========================================
*指定IDのギルド名取得
*------------------------------------------*/
-char *buildin_getguildname_sub(int guild_id)
+BUILDIN_FUNC(getguildname)
{
- struct guild *g=NULL;
- g=guild_search(guild_id);
+ int guild_id;
+ struct guild* g;
+
+ guild_id = script_getnum(st,2);
- if(g!=NULL){
- char *buf;
- buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
- memcpy(buf, g->name, NAME_LENGTH);
- buf[NAME_LENGTH-1] = '\0';
- return buf;
+ if( ( g = guild_search(guild_id) ) != NULL )
+ {
+ script_pushstrcopy(st,g->name);
}
- return NULL;
-}
-BUILDIN_FUNC(getguildname)
-{
- char *name;
- int guild_id=script_getnum(st,2);
- name=buildin_getguildname_sub(guild_id);
- if(name != NULL)
- script_pushstr(st,name);
else
+ {
script_pushconststr(st,"null");
+ }
return 0;
}
/*==========================================
*指定IDのGuildMaster名取得
*------------------------------------------*/
-char *buildin_getguildmaster_sub(int guild_id)
+BUILDIN_FUNC(getguildmaster)
{
- struct guild *g=NULL;
- g=guild_search(guild_id);
+ int guild_id;
+ struct guild* g;
- if(g!=NULL){
- char *buf;
- buf=(char *)aMallocA(NAME_LENGTH*sizeof(char));
- memcpy(buf, g->master, NAME_LENGTH);
- buf[NAME_LENGTH-1] = '\0';
- return buf;
- }
+ guild_id = script_getnum(st,2);
- return 0;
-}
-BUILDIN_FUNC(getguildmaster)
-{
- char *master;
- int guild_id=script_getnum(st,2);
- master=buildin_getguildmaster_sub(guild_id);
- if(master!=0)
- script_pushstr(st,master);
+ if( ( g = guild_search(guild_id) ) != NULL )
+ {
+ script_pushstrcopy(st,g->member[0].name);
+ }
else
+ {
script_pushconststr(st,"null");
+ }
return 0;
}
BUILDIN_FUNC(getguildmasterid)
{
- char *master;
- TBL_PC *sd=NULL;
- int guild_id=script_getnum(st,2);
- master=buildin_getguildmaster_sub(guild_id);
- if(master!=0){
- if((sd=map_nick2sd(master)) == NULL){
- script_pushint(st,0);
- return 0;
- }
- script_pushint(st,sd->status.char_id);
- }else{
+ int guild_id;
+ struct guild* g;
+
+ guild_id = script_getnum(st,2);
+
+ if( ( g = guild_search(guild_id) ) != NULL )
+ {
+ script_pushint(st,g->member[0].char_id);
+ }
+ else
+ {
script_pushint(st,0);
}
return 0;
@@ -6124,7 +6094,8 @@ BUILDIN_FUNC(strcharinfo)
{
TBL_PC *sd;
int num;
- char *buf;
+ struct guild* g;
+ struct party_data* p;
sd=script_rid2sd(st);
if (!sd) { //Avoid crashing....
@@ -6137,18 +6108,24 @@ BUILDIN_FUNC(strcharinfo)
script_pushstrcopy(st,sd->status.name);
break;
case 1:
- buf=buildin_getpartyname_sub(sd->status.party_id);
- if(buf!=0)
- script_pushstr(st,buf);
+ if( ( p = party_search(sd->status.party_id) ) != NULL )
+ {
+ script_pushstrcopy(st,p->party.name);
+ }
else
+ {
script_pushconststr(st,"");
+ }
break;
case 2:
- buf=buildin_getguildname_sub(sd->status.guild_id);
- if(buf != NULL)
- script_pushstr(st,buf);
+ if( ( g = guild_search(sd->status.guild_id) ) != NULL )
+ {
+ script_pushstrcopy(st,g->name);
+ }
else
+ {
script_pushconststr(st,"");
+ }
break;
case 3:
script_pushconststr(st,map[sd->bl.m].name);