Skip to content

Commit

Permalink
In api server move actions with remove timer into separate functions
Browse files Browse the repository at this point in the history
  • Loading branch information
4144 committed Apr 11, 2023
1 parent efb1ce4 commit fb63faa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/api/aclif.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,7 +787,7 @@ static void aclif_delete_online_player(int account_id)
ShowInfo("test disconnect account: %d\n", account_id);
struct online_api_login_data *data = idb_get(aclif->online_db, account_id);
if (data != NULL) {
data->remove_tick = timer->gettick() + aclif->remove_disconnected_delay;
aclif->add_remove_timer(data);
}
}

Expand All @@ -804,7 +804,7 @@ static void aclif_add_online_player(int account_id, const unsigned char *auth_to

struct online_api_login_data *user = idb_ensure(aclif->online_db, account_id, aclif->create_online_login_data);
if (user->remove_tick != 0)
user->remove_tick = 0;
aclif->remove_remove_timer(user);
memcpy(user->auth_token, auth_token, AUTH_TOKEN_SIZE);
}

Expand All @@ -826,7 +826,7 @@ static void aclif_add_online_char(int account_id, int char_id)
user->char_id = char_id;
}
if (user->remove_tick != 0)
user->remove_tick = 0;
aclif->remove_remove_timer(user);
ShowInfo("test connect char: %d, %d (%d)\n", account_id, char_id, user->char_id);
}

Expand Down Expand Up @@ -955,6 +955,18 @@ static int aclif_get_char_server_id(struct api_session_data *sd)
return data->id;
}

static void aclif_add_remove_timer(struct online_api_login_data *user)
{
nullpo_retv(user);
user->remove_tick = timer->gettick() + aclif->remove_disconnected_delay;
}

static void aclif_remove_remove_timer(struct online_api_login_data *user)
{
nullpo_retv(user);
user->remove_tick = 0;
}

static int do_init_aclif(bool minimal)
{
if (minimal)
Expand Down Expand Up @@ -1054,6 +1066,8 @@ void aclif_defaults(void)
aclif->purge_disconnected_user = aclif_purge_disconnected_user;
aclif->get_char_server_id = aclif_get_char_server_id;
aclif->add_online_char = aclif_add_online_char;
aclif->add_remove_timer = aclif_add_remove_timer;
aclif->remove_remove_timer = aclif_remove_remove_timer;

aclif->reportError = aclif_reportError;
}
2 changes: 2 additions & 0 deletions src/api/aclif.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ struct aclif_interface {
int (*purge_disconnected_users) (int tid, int64 tick, int id, intptr_t data);
int (*purge_disconnected_user) (union DBKey key, struct DBData *data, va_list ap);
int (*get_char_server_id) (struct api_session_data *sd);
void (*add_remove_timer) (struct online_api_login_data *data);
void (*remove_remove_timer) (struct online_api_login_data *data);

void (*show_request) (int fd, struct api_session_data *sd, bool show_http_headers);
};
Expand Down

0 comments on commit fb63faa

Please sign in to comment.