summaryrefslogtreecommitdiff
path: root/src/char/int_party.c
diff options
context:
space:
mode:
authorHaru <haru@dotalux.com>2018-07-01 18:32:57 +0200
committerGitHub <noreply@github.com>2018-07-01 18:32:57 +0200
commit56bed6dba78e3d65f6ff5aeec924b3ba2d06459d (patch)
tree9dea571701ae7879b79d663ad45948ddced6f58a /src/char/int_party.c
parentb1a1da3ac1b4a6465afe7b773b5f19178cd98ad2 (diff)
parent596428fa49b09ea1a0e0f17670ee127472576f37 (diff)
downloadhercules-56bed6dba78e3d65f6ff5aeec924b3ba2d06459d.tar.gz
hercules-56bed6dba78e3d65f6ff5aeec924b3ba2d06459d.tar.bz2
hercules-56bed6dba78e3d65f6ff5aeec924b3ba2d06459d.tar.xz
hercules-56bed6dba78e3d65f6ff5aeec924b3ba2d06459d.zip
Merge pull request #2108 from MishimaHaruna/mapifcleanup
Mapif cleanup
Diffstat (limited to 'src/char/int_party.c')
-rw-r--r--src/char/int_party.c260
1 files changed, 46 insertions, 214 deletions
diff --git a/src/char/int_party.c b/src/char/int_party.c
index 144e6661c..e089d1567 100644
--- a/src/char/int_party.c
+++ b/src/char/int_party.c
@@ -333,161 +333,16 @@ int inter_party_check_empty(struct party_data *p)
return 1;
}
-//-------------------------------------------------------------------
-// Communication to the map server
-
-
-// Create a party whether or not
-int mapif_party_created(int fd, int account_id, int char_id, struct party *p)
-{
- WFIFOHEAD(fd, 39);
- WFIFOW(fd,0)=0x3820;
- WFIFOL(fd,2)=account_id;
- WFIFOL(fd,6)=char_id;
- if(p!=NULL){
- WFIFOB(fd,10)=0;
- WFIFOL(fd,11)=p->party_id;
- memcpy(WFIFOP(fd,15),p->name,NAME_LENGTH);
- ShowInfo("int_party: Party created (%d - %s)\n",p->party_id,p->name);
- }else{
- WFIFOB(fd,10)=1;
- WFIFOL(fd,11)=0;
- memset(WFIFOP(fd,15),0,NAME_LENGTH);
- }
- WFIFOSET(fd,39);
-
- return 0;
-}
-
-//Party information not found
-void mapif_party_noinfo(int fd, int party_id, int char_id)
-{
- WFIFOHEAD(fd, 12);
- WFIFOW(fd,0) = 0x3821;
- WFIFOW(fd,2) = 12;
- WFIFOL(fd,4) = char_id;
- WFIFOL(fd,8) = party_id;
- WFIFOSET(fd,12);
- ShowWarning("int_party: info not found (party_id=%d char_id=%d)\n", party_id, char_id);
-}
-
-//Digest party information
-void mapif_party_info(int fd, struct party* p, int char_id)
-{
- unsigned char buf[8 + sizeof(struct party)];
- nullpo_retv(p);
- WBUFW(buf,0) = 0x3821;
- WBUFW(buf,2) = 8 + sizeof(struct party);
- WBUFL(buf,4) = char_id;
- memcpy(WBUFP(buf,8), p, sizeof(struct party));
-
- if(fd<0)
- mapif->sendall(buf,WBUFW(buf,2));
- else
- mapif->send(fd,buf,WBUFW(buf,2));
-}
-
-//Whether or not additional party members
-int mapif_party_memberadded(int fd, int party_id, int account_id, int char_id, int flag) {
- WFIFOHEAD(fd, 15);
- WFIFOW(fd,0) = 0x3822;
- WFIFOL(fd,2) = party_id;
- WFIFOL(fd,6) = account_id;
- WFIFOL(fd,10) = char_id;
- WFIFOB(fd,14) = flag;
- WFIFOSET(fd,15);
-
- return 0;
-}
-
-// Party setting change notification
-int mapif_party_optionchanged(int fd, struct party *p, int account_id, int flag)
-{
- unsigned char buf[16];
- nullpo_ret(p);
- WBUFW(buf,0)=0x3823;
- WBUFL(buf,2)=p->party_id;
- WBUFL(buf,6)=account_id;
- WBUFW(buf,10)=p->exp;
- WBUFW(buf,12)=p->item;
- WBUFB(buf,14)=flag;
- if(flag==0)
- mapif->sendall(buf,15);
- else
- mapif->send(fd,buf,15);
- return 0;
-}
-
-//Withdrawal notification party
-int mapif_party_withdraw(int party_id,int account_id, int char_id) {
- unsigned char buf[16];
-
- WBUFW(buf,0) = 0x3824;
- WBUFL(buf,2) = party_id;
- WBUFL(buf,6) = account_id;
- WBUFL(buf,10) = char_id;
- mapif->sendall(buf, 14);
- return 0;
-}
-
-//Party map update notification
-int mapif_party_membermoved(struct party *p, int idx)
-{
- unsigned char buf[20];
-
- nullpo_ret(p);
- Assert_ret(idx >= 0 && idx < MAX_PARTY);
- WBUFW(buf,0) = 0x3825;
- WBUFL(buf,2) = p->party_id;
- WBUFL(buf,6) = p->member[idx].account_id;
- WBUFL(buf,10) = p->member[idx].char_id;
- WBUFW(buf,14) = p->member[idx].map;
- WBUFB(buf,16) = p->member[idx].online;
- WBUFW(buf,17) = p->member[idx].lv;
- mapif->sendall(buf, 19);
- return 0;
-}
-
-//Dissolution party notification
-int mapif_party_broken(int party_id, int flag)
-{
- unsigned char buf[16];
- WBUFW(buf,0)=0x3826;
- WBUFL(buf,2)=party_id;
- WBUFB(buf,6)=flag;
- mapif->sendall(buf,7);
- //printf("int_party: broken %d\n",party_id);
- return 0;
-}
-
-//Remarks in the party
-int mapif_party_message(int party_id, int account_id, const char *mes, int len, int sfd)
-{
- unsigned char buf[512];
- nullpo_ret(mes);
- WBUFW(buf,0)=0x3827;
- WBUFW(buf,2)=len+12;
- WBUFL(buf,4)=party_id;
- WBUFL(buf,8)=account_id;
- memcpy(WBUFP(buf,12),mes,len);
- mapif->sendallwos(sfd, buf,len+12);
- return 0;
-}
-
-//-------------------------------------------------------------------
-// Communication from the map server
-
-
// Create Party
-int mapif_parse_CreateParty(int fd, const char *name, int item, int item2, const struct party_member *leader)
+struct party_data *inter_party_create(const char *name, int item, int item2, const struct party_member *leader)
{
struct party_data *p;
int i;
nullpo_ret(name);
nullpo_ret(leader);
- if (!*name || (p = inter_party->search_partyname(name)) != NULL) {
- mapif->party_created(fd,leader->account_id,leader->char_id,NULL);
- return 0;
+
+ if (!*name || inter_party->search_partyname(name) != NULL) {
+ return NULL;
}
// Check Authorized letters/symbols in the name of the character
if (char_name_option == 1) { // only letters/symbols in char_name_letters are authorized
@@ -497,18 +352,16 @@ int mapif_parse_CreateParty(int fd, const char *name, int item, int item2, const
char *newname = aStrndup(name, NAME_LENGTH-1);
normalize_name(newname,"\"");
trim(newname);
- mapif->parse_CreateParty(fd, newname, item, item2, leader);
+ p = inter_party->create(newname, item, item2, leader);
aFree(newname);
- return 0;
+ return p;
}
- mapif->party_created(fd,leader->account_id,leader->char_id,NULL);
- return 0;
+ return NULL;
}
} else if (char_name_option == 2) { // letters/symbols in char_name_letters are forbidden
for (i = 0; i < NAME_LENGTH && name[i]; i++)
if (strchr(char_name_letters, name[i]) != NULL) {
- mapif->party_created(fd,leader->account_id,leader->char_id,NULL);
- return 0;
+ return NULL;
}
}
@@ -523,34 +376,20 @@ int mapif_parse_CreateParty(int fd, const char *name, int item, int item2, const
p->party.member[0].online=1;
p->party.party_id=-1;//New party.
- if (inter_party->tosql(&p->party,PS_CREATE|PS_ADDMEMBER,0)) {
- //Add party to db
- inter_party->calc_state(p);
- idb_put(inter_party->db, p->party.party_id, p);
- mapif->party_info(fd, &p->party, 0);
- mapif->party_created(fd,leader->account_id,leader->char_id,&p->party);
- } else { //Failed to create party.
+ if (!inter_party->tosql(&p->party, PS_CREATE | PS_ADDMEMBER, 0)) {
aFree(p);
- mapif->party_created(fd,leader->account_id,leader->char_id,NULL);
+ return NULL;
}
- return 0;
-}
-
-// Party information request
-void mapif_parse_PartyInfo(int fd, int party_id, int char_id)
-{
- struct party_data *p;
- p = inter_party->fromsql(party_id);
+ //Add party to db
+ inter_party->calc_state(p);
+ idb_put(inter_party->db, p->party.party_id, p);
- if (p)
- mapif->party_info(fd, &p->party, char_id);
- else
- mapif->party_noinfo(fd, party_id, char_id);
+ return p;
}
// Add a player to party request
-int mapif_parse_PartyAddMember(int fd, int party_id, const struct party_member *member)
+bool inter_party_add_member(int party_id, const struct party_member *member)
{
struct party_data *p;
int i;
@@ -558,15 +397,13 @@ int mapif_parse_PartyAddMember(int fd, int party_id, const struct party_member *
nullpo_ret(member);
p = inter_party->fromsql(party_id);
if( p == NULL || p->size == MAX_PARTY ) {
- mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 1);
- return 0;
+ return false;
}
ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == 0 );
- if( i == MAX_PARTY )
- {// Party full
- mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 1);
- return 0;
+ if (i == MAX_PARTY) {
+ // Party full
+ return false;
}
memcpy(&p->party.member[i], member, sizeof(struct party_member));
@@ -582,21 +419,20 @@ int mapif_parse_PartyAddMember(int fd, int party_id, const struct party_member *
}
mapif->party_info(-1, &p->party, 0);
- mapif->party_memberadded(fd, party_id, member->account_id, member->char_id, 0);
inter_party->tosql(&p->party, PS_ADDMEMBER, i);
- return 0;
+ return true;
}
//Party setting change request
-int mapif_parse_PartyChangeOption(int fd,int party_id,int account_id,int exp,int item)
+bool inter_party_change_option(int party_id, int account_id, int exp, int item, int map_fd)
{
struct party_data *p;
int flag = 0;
p = inter_party->fromsql(party_id);
if(!p)
- return 0;
+ return false;
p->party.exp=exp;
if( exp && !inter_party->check_exp_share(p) ){
@@ -604,13 +440,13 @@ int mapif_parse_PartyChangeOption(int fd,int party_id,int account_id,int exp,int
p->party.exp=0;
}
p->party.item = item&0x3; //Filter out invalid values.
- mapif->party_optionchanged(fd,&p->party,account_id,flag);
+ mapif->party_optionchanged(map_fd, &p->party, account_id, flag);
inter_party->tosql(&p->party, PS_BASIC, 0);
- return 0;
+ return true;
}
//Request leave party
-int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id)
+bool inter_party_leave(int party_id, int account_id, int char_id)
{
struct party_data *p;
int i,j;
@@ -620,7 +456,7 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id)
{// Party does not exists?
if( SQL_ERROR == SQL->Query(inter->sql_handle, "UPDATE `%s` SET `party_id`='0' WHERE `party_id`='%d'", char_db, party_id) )
Sql_ShowDebug(inter->sql_handle);
- return 0;
+ return false;
}
for (i = 0; i < MAX_PARTY; i++) {
@@ -630,7 +466,7 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id)
}
}
if (i >= MAX_PARTY)
- return 0; //Member not found?
+ return false; //Member not found?
mapif->party_withdraw(party_id, account_id, char_id);
@@ -648,23 +484,25 @@ int mapif_parse_PartyLeave(int fd, int party_id, int account_id, int char_id)
inter_party->tosql(&p->party, PS_DELMEMBER, i);
mapif->party_info(-1, &p->party, 0);
}
- return 0;
+ return true;
}
+
// When member goes to other map or levels up.
-int mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, int char_id, unsigned short map, int online, unsigned int lv)
+bool inter_party_change_map(int party_id, int account_id, int char_id, unsigned short map, int online, unsigned int lv)
{
struct party_data *p;
int i;
p = inter_party->fromsql(party_id);
if (p == NULL)
- return 0;
+ return false;
for(i = 0; i < MAX_PARTY &&
(p->party.member[i].account_id != account_id ||
p->party.member[i].char_id != char_id); i++);
- if (i == MAX_PARTY) return 0;
+ if (i == MAX_PARTY)
+ return false;
if (p->party.member[i].online != online)
{
@@ -704,30 +542,24 @@ int mapif_parse_PartyChangeMap(int fd, int party_id, int account_id, int char_id
p->party.member[i].map = map;
mapif->party_membermoved(&p->party, i);
}
- return 0;
+ return true;
}
//Request party dissolution
-int mapif_parse_BreakParty(int fd, int party_id)
+bool inter_party_disband(int party_id)
{
struct party_data *p;
p = inter_party->fromsql(party_id);
if(!p)
- return 0;
+ return false;
inter_party->tosql(&p->party,PS_BREAK,0);
mapif->party_broken(party_id, 1);
return 0;
}
-//Party sending the message
-int mapif_parse_PartyMessage(int fd, int party_id, int account_id, const char *mes, int len)
-{
- return mapif->party_message(party_id,account_id,mes,len, fd);
-}
-
-int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char_id)
+bool inter_party_change_leader(int party_id, int account_id, int char_id)
{
struct party_data *p;
int i;
@@ -735,7 +567,7 @@ int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char
p = inter_party->fromsql(party_id);
if(!p)
- return 0;
+ return false;
for (i = 0; i < MAX_PARTY; i++) {
if(p->party.member[i].leader)
@@ -745,10 +577,9 @@ int mapif_parse_PartyLeaderChange(int fd, int party_id, int account_id, int char
inter_party->tosql(&p->party,PS_LEADER, i);
}
}
- return 1;
+ return true;
}
-
// Communication from the map server
//-Analysis that only one packet
// Data packet length is set to inter.c that you
@@ -775,12 +606,6 @@ int inter_party_parse_frommap(int fd)
return 1;
}
-//Leave request from the server (for delete character)
-int inter_party_leave(int party_id,int account_id, int char_id)
-{
- return mapif->parse_PartyLeave(-1,party_id,account_id, char_id);
-}
-
int inter_party_CharOnline(int char_id, int party_id)
{
struct party_data* p;
@@ -895,4 +720,11 @@ void inter_party_defaults(void)
inter_party->leave = inter_party_leave;
inter_party->CharOnline = inter_party_CharOnline;
inter_party->CharOffline = inter_party_CharOffline;
+
+ inter_party->create = inter_party_create;
+ inter_party->add_member = inter_party_add_member;
+ inter_party->change_option = inter_party_change_option;
+ inter_party->change_map = inter_party_change_map;
+ inter_party->disband = inter_party_disband;
+ inter_party->change_leader = inter_party_change_leader;
}