summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-06-28 18:45:38 -0300
committershennetsind <ind@henn.et>2013-06-28 18:45:38 -0300
commit918b1123963ac2f91a4d074b092ceef1db71b4e8 (patch)
tree15eda3833d2fab779b02ef22573c21812b1c3aec /src
parent203e44e51c8cb133bf3fb20b372d16ea92be7667 (diff)
downloadhercules-918b1123963ac2f91a4d074b092ceef1db71b4e8.tar.gz
hercules-918b1123963ac2f91a4d074b092ceef1db71b4e8.tar.bz2
hercules-918b1123963ac2f91a4d074b092ceef1db71b4e8.tar.xz
hercules-918b1123963ac2f91a4d074b092ceef1db71b4e8.zip
BG Queue Testing
http://hercules.ws/board/topic/1302-bg-queue-debug/ Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src')
-rw-r--r--src/common/socket.h2
-rw-r--r--src/map/battleground.c62
-rw-r--r--src/map/battleground.h2
-rw-r--r--src/map/clif.c29
-rw-r--r--src/map/clif.h2
-rw-r--r--src/map/map.c3
-rw-r--r--src/map/packets_struct.h6
-rw-r--r--src/map/script.c109
-rw-r--r--src/map/script.h2
9 files changed, 180 insertions, 37 deletions
diff --git a/src/common/socket.h b/src/common/socket.h
index b58cbdccf..82f8b84c3 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -50,7 +50,7 @@
} while(0)
/* [Ind/Hercules] */
-#define RFIFO2PTR(fd,len) (void*)(session[fd]->rdata + len)
+#define RFIFO2PTR(fd) (void*)(session[fd]->rdata + session[fd]->rdata_pos)
// buffer I/O macros
#define RBUFP(p,pos) (((uint8*)(p)) + (pos))
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 88cc323bf..d54178347 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -21,6 +21,7 @@
#include "pet.h"
#include "homunculus.h"
#include "mercenary.h"
+#include "mapreg.h"
#include <string.h>
#include <stdio.h>
@@ -264,7 +265,7 @@ void bg_config_read(void) {
config_setting_lookup_int(settings, "maximum_afk_seconds", &bg->mafksec);
config_setting_lookup_bool(settings, "feature_off", &offline);
-
+
if( offline == 0 )
bg->queue_on = true;
@@ -279,7 +280,7 @@ void bg_config_read(void) {
int prizeWin, prizeLoss, prizeDraw;
int minPlayers, maxPlayers, minTeamPlayers;
int maxDuration;
- int fillup_duration, pregame_duration;
+ int fillup_duration = 0, pregame_duration = 0;
bg->arena[i] = NULL;
@@ -305,7 +306,7 @@ void bg_config_read(void) {
maxLevel = MAX_LEVEL;
}
- if( !(reward = config_setting_get_member(settings, "reward")) ) {
+ if( !(reward = config_setting_get_member(arena, "reward")) ) {
ShowError("bg_config_read: failed to find 'reward' for arena '%s'/#%d\n",aName,i);
continue;
}
@@ -385,7 +386,7 @@ void bg_config_read(void) {
bg->arena[i]->min_team_players = minTeamPlayers;
safestrncpy(bg->arena[i]->delay_var, aDelayVar, NAME_LENGTH);
bg->arena[i]->maxDuration = maxDuration;
- bg->arena[i]->queue_id = -1;
+ bg->arena[i]->queue_id = script->queue_create();
bg->arena[i]->begin_timer = INVALID_TIMER;
bg->arena[i]->fillup_timer = INVALID_TIMER;
bg->arena[i]->pregame_duration = pregame_duration;
@@ -425,17 +426,35 @@ void bg_queue_ready_ack (struct bg_arena *arena, struct map_session_data *sd, bo
bg->queue_pc_cleanup(sd);
return;
}
- if( response ) {
+ if( !response )
+ bg->queue_pc_cleanup(sd);
+ else {
+ struct hQueue *queue = &script->hq[arena->queue_id];
+ int i, count = 0;
sd->bg_queue.ready = 1;
+
+ for( i = 0; i < queue->items; i++ ) {
+ if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
+ if( sd->bg_queue.ready == 1 )
+ count++;
+ }
+ }
/* check if all are ready then cancell timer, and start game */
- } else
- bg->queue_pc_cleanup(sd);
+ if( count == i ) {
+ iTimer->delete_timer(arena->begin_timer,bg->begin_timer);
+ arena->begin_timer = INVALID_TIMER;
+ bg->begin(arena);
+ }
+
+ }
+
}
void bg_queue_player_cleanup(struct map_session_data *sd) {
if ( sd->bg_queue.client_has_bg_data ) {
clif->bgqueue_notice_delete(sd,BGQND_CLOSEWINDOW, sd->bg_queue.arena ? sd->bg_queue.arena->id : 0);
}
- script->queue_remove(sd->bg_queue.arena->queue_id,sd->status.account_id);
+ if( sd->bg_queue.arena )
+ script->queue_remove(sd->bg_queue.arena->queue_id,sd->status.account_id);
sd->bg_queue.arena = NULL;
sd->bg_queue.ready = 0;
sd->bg_queue.client_has_bg_data = 0;
@@ -443,27 +462,27 @@ void bg_queue_player_cleanup(struct map_session_data *sd) {
}
void bg_match_over(struct bg_arena *arena, bool canceled) {
struct hQueue *queue = &script->hq[arena->queue_id];
- int i;//, count = 0;
-
- /* if( !canceled ) <check time/score> */
+ int i;
for( i = 0; i < queue->items; i++ ) {
struct map_session_data * sd = NULL;
if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
bg->queue_pc_cleanup(sd);
- clif->colormes(sd->fd,COLOR_RED,"BG Match Cancelled: not enough players");
+ if( canceled )
+ clif->colormes(sd->fd,COLOR_RED,"BG Match Cancelled: not enough players");
}
}
bg->arena[i]->begin_timer = INVALID_TIMER;
bg->arena[i]->fillup_timer = INVALID_TIMER;
/* reset queue */
+ script->queue_clear(arena->queue_id);
}
void bg_begin(struct bg_arena *arena) {
struct hQueue *queue = &script->hq[arena->queue_id];
int i, count = 0;
-
+
for( i = 0; i < queue->items; i++ ) {
struct map_session_data * sd = NULL;
@@ -476,12 +495,14 @@ void bg_begin(struct bg_arena *arena) {
}
if( count < arena->min_players ) {
- bg_match_over(arena,true);
+ bg->match_over(arena,true);
} else {
- ;
+ mapreg_setreg(add_str("$@bg_queue_id"),arena->queue_id);/* TODO: make this a arena-independant var? or just .@? */
+ npc_event_do(arena->npc_event);
/* we split evenly? */
/* but if a party of say 10 joins, it cant be split evenly unless by luck there are 10 soloers in the queue besides them */
/* not sure how to split T_T needs more info */
+ /* currently running only on solo mode so we do it evenly */
}
}
int bg_begin_timer(int tid, unsigned int tick, int id, intptr_t data) {
@@ -599,11 +620,12 @@ void bg_queue_add(struct map_session_data *sd, struct bg_arena *arena, enum bg_q
clif->bgqueue_ack(sd,BGQA_SUCCESS,arena->id);
+ bg->queue_check(arena);
}
enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_arena *arena, enum bg_queue_types type) {
int tick;
unsigned int tsec;
- if ( sd->status.base_level > arena->max_level || sd->status.base_level < arena->max_level )
+ if ( sd->status.base_level > arena->max_level || sd->status.base_level < arena->min_level )
return BGQA_FAIL_LEVEL_INCORRECT;
if ( !(sd->class_&JOBL_2) ) /* TODO: maybe make this a per-arena setting, so users may make custom arenas like baby-only,whatever. */
@@ -633,6 +655,11 @@ enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, struct bg_
if( sd->bg_queue.arena != NULL )
return BGQA_DUPLICATE_REQUEST;
+
+ if( type != BGQT_INDIVIDUAL ) {/* until we get the damn balancing correct */
+ clif->colormes(sd->fd,COLOR_RED,"Queueing is only currently enabled only for Solo Mode");
+ return BGQA_FAIL_TEAM_COUNT;
+ }
switch(type) {
case BGQT_GUILD:
@@ -704,6 +731,7 @@ void do_init_battleground(void) {
bg_team_db = idb_alloc(DB_OPT_RELEASE_DATA);
iTimer->add_timer_func_list(bg_send_xy_timer, "bg_send_xy_timer");
iTimer->add_timer_interval(iTimer->gettick() + battle_config.bg_update_interval, bg_send_xy_timer, 0, 0, battle_config.bg_update_interval);
+ bg->config_read();
}
void do_final_battleground(void) {
@@ -738,6 +766,8 @@ void battleground_defaults(void) {
bg->queue_pregame = bg_queue_pregame;
bg->fillup_timer = bg_fillup_timer;
bg->queue_ready_ack = bg_queue_ready_ack;
+ bg->match_over = bg_match_over;
+ bg->queue_check = bg_queue_check;
/* */
bg->config_read = bg_config_read;
}
diff --git a/src/map/battleground.h b/src/map/battleground.h
index 030d13d90..f76d84d0c 100644
--- a/src/map/battleground.h
+++ b/src/map/battleground.h
@@ -97,6 +97,8 @@ struct battleground_interface {
void (*queue_pregame) (struct bg_arena *arena);
int (*fillup_timer) (int tid, unsigned int tick, int id, intptr_t data);
void (*queue_ready_ack) (struct bg_arena *arena, struct map_session_data *sd, bool response);
+ void (*match_over) (struct bg_arena *arena, bool canceled);
+ void (*queue_check) (struct bg_arena *arena);
/* */
void (*config_read) (void);
} bg_s;
diff --git a/src/map/clif.c b/src/map/clif.c
index e5132a938..373d510ba 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -545,8 +545,24 @@ int clif_send(const void* buf, int len, struct block_list* bl, enum send_target
}
break;
+ case BG_QUEUE:
+ if( sd && sd->bg_queue.arena ) {
+ struct hQueue *queue = &script->hq[sd->bg_queue.arena->queue_id];
+
+ for( i = 0; i < queue->items; i++ ) {
+ struct map_session_data * sd = NULL;
+
+ if( ( sd = iMap->id2sd(queue->item[i]) ) ) {
+ WFIFOHEAD(sd->fd,len);
+ memcpy(WFIFOP(sd->fd,0), buf, len);
+ WFIFOSET(sd->fd,len);
+ }
+ }
+ }
+ break;
+
default:
- ShowError("clif->send: Unrecognized type %d\n",type);
+ ShowError("clif_send: Unrecognized type %d\n",type);
return -1;
}
@@ -17317,7 +17333,6 @@ void clif_status_change_end(struct block_list *bl, int tid, enum send_target tar
}
void clif_bgqueue_ack(struct map_session_data *sd, enum BATTLEGROUNDS_QUEUE_ACK response, unsigned char arena_id) {
-
switch (response) {
case BGQA_FAIL_COOLDOWN:
case BGQA_FAIL_DESERTER:
@@ -17348,15 +17363,16 @@ void clif_bgqueue_notice_delete(struct map_session_data *sd, enum BATTLEGROUNDS_
}
void clif_parse_bgqueue_register(int fd, struct map_session_data *sd) {
- struct packet_bgqueue_register *p = P2PTR(fd, bgqueue_registerType);
+ struct packet_bgqueue_register *p = P2PTR(fd);
struct bg_arena *arena = NULL;
-
if( !bg->queue_on ) return; /* temp, until feature is complete */
if( !(arena = bg->name2arena(p->bg_name)) ) {
clif->bgqueue_ack(sd,BGQA_FAIL_BGNAME_INVALID,0);
return;
}
+ //debug
+ safestrncpy(arena->name, p->bg_name, sizeof(arena->name));
switch( (enum bg_queue_types)p->type ) {
case BGQT_INDIVIDUAL:
@@ -17387,7 +17403,6 @@ void clif_parse_bgqueue_checkstate(int fd, struct map_session_data *sd) {
//struct packet_bgqueue_checkstate *p = P2PTR(fd, bgqueue_checkstateType); /* TODO: bgqueue_notice_delete should use this p->bg_name */
if( !bg->queue_on ) return; /* temp, until feature is complete */
if ( sd->bg_queue.arena && sd->bg_queue.type ) {
- sd->bg_queue.client_has_bg_data = true;
clif->bgqueue_update_info(sd,sd->bg_queue.arena->id,bg->id2pos(sd->bg_queue.arena->queue_id,sd->status.account_id));
} else
clif->bgqueue_notice_delete(sd, BGQND_FAIL_NOT_QUEUING,0);/* TODO: wrong response, should respond with p->bg_name not id 0 */
@@ -17400,10 +17415,10 @@ void clif_parse_bgqueue_revoke_req(int fd, struct map_session_data *sd) {
}
void clif_parse_bgqueue_battlebegin_ack(int fd, struct map_session_data *sd) {
- struct packet_bgqueue_battlebegin_ack *p = P2PTR(fd, bgqueue_checkstateType);
+ struct packet_bgqueue_battlebegin_ack *p = P2PTR(fd);
struct bg_arena *arena;
if( !bg->queue_on ) return; /* temp, until feature is complete */
- if( ( arena = bg->name2arena(p->bg_name) ) ) {
+ if( ( arena = bg->name2arena(p->bg_name) ) ) {
bg->queue_ready_ack(arena,sd, ( p->result == 1 ) ? true : false);
} else {
clif->bgqueue_ack(sd,BGQA_FAIL_BGNAME_INVALID, 0);
diff --git a/src/map/clif.h b/src/map/clif.h
index bea701223..81376db15 100644
--- a/src/map/clif.h
+++ b/src/map/clif.h
@@ -43,7 +43,7 @@ struct eri;
* Defines
**/
#define packet_len(cmd) packet_db[cmd].len
-#define P2PTR(fd,cmd) RFIFO2PTR(fd,packet_db[cmd].len)
+#define P2PTR(fd) RFIFO2PTR(fd)
#define clif_menuskill_clear(sd) (sd)->menuskill_id = (sd)->menuskill_val = (sd)->menuskill_val2 = 0;
#define HCHSYS_NAME_LENGTH 20
diff --git a/src/map/map.c b/src/map/map.c
index ee56f140f..99f585a8d 100644
--- a/src/map/map.c
+++ b/src/map/map.c
@@ -1657,7 +1657,8 @@ int map_quit(struct map_session_data *sd) {
}
/* two times, the npc event above may assign a new one or delete others */
for( i = 0; i < sd->queues_count; i++ ) {
- script->queue_remove(sd->queues[i],sd->status.account_id);
+ if( sd->queues[i] != -1 )
+ script->queue_remove(sd->queues[i],sd->status.account_id);
}
npc_script_event(sd, NPCE_LOGOUT);
diff --git a/src/map/packets_struct.h b/src/map/packets_struct.h
index d77784dc5..8e7506686 100644
--- a/src/map/packets_struct.h
+++ b/src/map/packets_struct.h
@@ -404,13 +404,13 @@ struct packet_maptypeproperty2 {
struct packet_bgqueue_ack {
short PacketType;
- short type;
+ unsigned char type;
char bg_name[NAME_LENGTH];
} __attribute__((packed));
struct packet_bgqueue_notice_delete {
short PacketType;
- short type;
+ unsigned char type;
char bg_name[NAME_LENGTH];
} __attribute__((packed));
@@ -438,7 +438,7 @@ struct packet_bgqueue_revoke_req {
struct packet_bgqueue_battlebegin_ack {
short PacketType;
- short result;
+ unsigned char result;
char bg_name[NAME_LENGTH];
char game_name[NAME_LENGTH];
} __attribute__((packed));
diff --git a/src/map/script.c b/src/map/script.c
index 5cc48c7ce..354ec0522 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -17016,9 +17016,7 @@ struct hQueue *script_hqueue_get(int idx) {
return NULL;
return &script->hq[idx];
}
-/* set .@id,queue(); */
-/* creates queue, returns created queue id */
-BUILDIN(queue) {
+int script_hqueue_create(void) {
int idx = script->hqs;
int i;
@@ -17039,8 +17037,12 @@ BUILDIN(queue) {
script->hq[ idx ].onDeath[0] = '\0';
script->hq[ idx ].onLogOut[0] = '\0';
script->hq[ idx ].onMapChange[0] = '\0';
-
- script_pushint(st,idx);
+ return idx;
+}
+/* set .@id,queue(); */
+/* creates queue, returns created queue id */
+BUILDIN(queue) {
+ script_pushint(st,script->queue_create());
return true;
}
/* set .@length,queuesize(.@queue_id); */
@@ -17135,7 +17137,7 @@ bool script_hqueue_remove(int idx, int var) {
if( var >= START_ACCOUNT_NUM && (sd = iMap->id2sd(var)) ) {
for(i = 0; i < sd->queues_count; i++) {
- if( sd->queues[i] == var ) {
+ if( sd->queues[i] == idx ) {
break;
}
}
@@ -17237,7 +17239,33 @@ BUILDIN(queuedel) {
return true;
}
+void script_hqueue_clear(int idx) {
+ if( idx < 0 || idx >= script->hqs || script->hq[idx].items == -1 ) {
+ ShowWarning("script_hqueue_clear: unknown queue id %d\n",idx);
+ return;
+ } else {
+ struct map_session_data *sd;
+ int i, j;
+
+ for(i = 0; i < script->hq[idx].items; i++) {
+ if( script->hq[idx].item[i] != -1 ) {
+ if( script->hq[idx].item[i] >= START_ACCOUNT_NUM && (sd = iMap->id2sd(script->hq[idx].item[i])) ) {
+ for(j = 0; j < sd->queues_count; j++) {
+ if( sd->queues[j] == idx ) {
+ break;
+ }
+ }
+
+ if( j != sd->queues_count )
+ sd->queues[j] = -1;
+ }
+ script->hq[idx].item[i] = -1;
+ }
+ }
+ }
+ return;
+}
/* set .@id, queueiterator(.@queue_id); */
/* creates a new queue iterator, returns its id */
BUILDIN(queueiterator) {
@@ -17281,7 +17309,7 @@ BUILDIN(qiget) {
if( idx < 0 || idx >= script->hqis ) {
ShowWarning("buildin_qiget: unknown queue iterator id %d\n",idx);
script_pushint(st, 0);
- } else if ( script->hqi[idx].pos == script->hqi[idx].items ) {
+ } else if ( script->hqi[idx].pos -1 == script->hqi[idx].items ) {
script_pushint(st, 0);
} else {
struct hQueueIterator *it = &script->hqi[idx];
@@ -17298,7 +17326,7 @@ BUILDIN(qicheck) {
if( idx < 0 || idx >= script->hqis ) {
ShowWarning("buildin_qicheck: unknown queue iterator id %d\n",idx);
script_pushint(st, 0);
- } else if ( script->hqi[idx].pos == script->hqi[idx].items ) {
+ } else if ( script->hqi[idx].pos -1 == script->hqi[idx].items ) {
script_pushint(st, 0);
} else {
script_pushint(st, 1);
@@ -17355,7 +17383,66 @@ BUILDIN(packageitem) {
return true;
}
+/* New Battlegrounds Stuff */
+/* bg_team_create(map_name,respawn_x,respawn_y) */
+/* returns created team id or -1 when fails */
+BUILDIN(bg_create_team) {
+ const char *map_name, *ev = "", *dev = "";//ev and dev will be dropped.
+ int x, y, mapindex = 0, bg_id;
+
+ map_name = script_getstr(st,2);
+ if( strcmp(map_name,"-") != 0 ) {
+ mapindex = mapindex_name2id(map_name);
+ if( mapindex == 0 ) { // Invalid Map
+ script_pushint(st,0);
+ return true;
+ }
+ }
+
+ x = script_getnum(st,3);
+ y = script_getnum(st,4);
+
+ if( (bg_id = bg_create(mapindex, x, y, ev, dev)) == 0 ) { // Creation failed
+ script_pushint(st,-1);
+ } else
+ script_pushint(st,bg_id);
+
+ return true;
+}
+/* bg_join_team(team_id{,optional account id}) */
+/* when account id is not present it tries to autodetect from the attached player (if any) */
+/* returns 0 when successful, 1 otherwise */
+BUILDIN(bg_join_team) {
+ struct map_session_data *sd;
+ int team_id = script_getnum(st, 2);
+
+ if( script_hasdata(st, 3) )
+ sd = iMap->id2sd(script_getnum(st, 3));
+ else
+ sd = script->rid2sd(st);
+
+ if( !sd )
+ script_pushint(st, 1);
+ else
+ script_pushint(st,bg_team_join(team_id, sd)?0:1);
+
+ return true;
+}
+/* bg_match_over( arena_name {, optional canceled } ) */
+/* returns 0 when successful, 1 otherwise */
+BUILDIN(bg_match_over) {
+ bool canceled = script_hasdata(st,3) ? true : false;
+ struct bg_arena *arena = bg->name2arena((char*)script_getstr(st, 2));
+
+ if( arena ) {
+ bg->match_over(arena,canceled);
+ script_pushint(st, 0);
+ } else
+ script_pushint(st, 1);
+
+ return true;
+}
// declarations that were supposed to be exported from npc_chat.c
#ifdef PCRE_SUPPORT
BUILDIN(defpattern);
@@ -17872,6 +17959,10 @@ void script_parse_builtin(void) {
BUILDIN_DEF(packageitem,"?"),
+ /* New BG Commands [Hercules] */
+ BUILDIN_DEF(bg_create_team,"sii"),
+ BUILDIN_DEF(bg_join_team,"i?"),
+ BUILDIN_DEF(bg_match_over,"s?"),
};
int i,n, len = ARRAYLENGTH(BUILDIN), start = script->buildin_count;
char* p;
@@ -17974,4 +18065,6 @@ void script_defaults(void) {
script->queue_add = script_hqueue_add;
script->queue_del = script_hqueue_del;
script->queue_remove = script_hqueue_remove;
+ script->queue_create = script_hqueue_create;
+ script->queue_clear = script_hqueue_clear;
}
diff --git a/src/map/script.h b/src/map/script.h
index a047779a8..a77e957c0 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -383,6 +383,8 @@ struct script_interface {
bool (*queue_add) (int idx, int var);
bool (*queue_del) (int idx);
bool (*queue_remove) (int idx, int var);
+ int (*queue_create) (void);
+ void (*queue_clear) (int idx);
} script_s;
struct script_interface *script;