Skip to content

Commit

Permalink
Refactored function indirect
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-gilliam committed Nov 8, 2023
1 parent 9e937b0 commit 207fbd5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 35 deletions.
4 changes: 2 additions & 2 deletions code/act_wiz.c
Original file line number Diff line number Diff line change
Expand Up @@ -7538,7 +7538,7 @@ void do_buglist(CHAR_DATA *ch, char *argument)
}

mysql_free_result(res_set);
do_disc(conn);
mysql_close(conn);
return;
}
else if (!strcmp(arg1, "last"))
Expand Down Expand Up @@ -7615,7 +7615,7 @@ void do_buglist(CHAR_DATA *ch, char *argument)
}

mysql_free_result(res_set);
do_disc(conn);
mysql_close(conn);
}

void buglist_end_fun(CHAR_DATA *ch, char *argument)
Expand Down
42 changes: 22 additions & 20 deletions code/devextra.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,8 @@ void do_sitetrack(CHAR_DATA *ch, char *argument)
page_to_char(buf_string(buffer), ch);
mysql_free_result(res_set);

do_disc(conn);
do_disc(conn2);
mysql_close(conn);
mysql_close(conn2);
free_buf(buffer);
return;
}
Expand All @@ -512,7 +512,7 @@ void do_sitetrack(CHAR_DATA *ch, char *argument)

auto listing = fmt::format("A new site ({}) was added to the IP listings. You should add a comment now explaining why it was added.\n\r", arg2);

do_disc(conn);
mysql_close(conn);
send_to_char(listing.c_str(), ch);
return;
}
Expand All @@ -526,7 +526,7 @@ void do_sitetrack(CHAR_DATA *ch, char *argument)
ch->pcdata->helpid = atoi(arg2);
enter_text(ch, comment_end_fun);

do_disc(conn);
mysql_close(conn);
return;
}

Expand All @@ -535,7 +535,7 @@ void do_sitetrack(CHAR_DATA *ch, char *argument)
query_buffer = fmt::format("DELETE FROM sitecomments WHERE comment_id={}", arg2);
one_query(query_buffer.data());

do_disc(conn);
mysql_close(conn);
send_to_char("Ok.\n\r", ch);
return;
}
Expand All @@ -545,7 +545,7 @@ void do_sitetrack(CHAR_DATA *ch, char *argument)
query_buffer = fmt::format("DELETE FROM sitetracker WHERE site_id={}", arg2);
one_query(query_buffer.data());

do_disc(conn);
mysql_close(conn);
send_to_char("Ok.\n\r", ch);
return;
}
Expand All @@ -561,7 +561,7 @@ void do_sitetrack(CHAR_DATA *ch, char *argument)
if (!res_set || mysql_affected_rows(conn) < 1)
{
send_to_char("Invalid ID number.\n\r", ch);
do_disc(conn);
mysql_close(conn);
return;
}

Expand Down Expand Up @@ -623,8 +623,8 @@ void do_sitetrack(CHAR_DATA *ch, char *argument)
mysql_free_result(res_set);
mysql_free_result(res2);

do_disc(conn);
do_disc(conn2);
mysql_close(conn);
mysql_close(conn2);
free_buf(buffer);
}
}
Expand Down Expand Up @@ -671,7 +671,7 @@ void show_database_info(CHAR_DATA *ch, char *argument)
if (!mysql_affected_rows(conn))
{
mysql_free_result(res_set);
do_disc(conn);
mysql_close(conn);
send_to_char(" No database entry for player found.\n\r", ch);
return;
}
Expand Down Expand Up @@ -713,8 +713,8 @@ void show_database_info(CHAR_DATA *ch, char *argument)
}

mysql_free_result(res_set);
do_disc(conn2);
do_disc(conn);
mysql_close(conn2);
mysql_close(conn);
}

void do_demo(CHAR_DATA *ch, char *name)
Expand Down Expand Up @@ -825,7 +825,7 @@ MYSQL_ROW one_fquery_row(char *query)

mysql_free_result(res_set);

do_disc(conn);
mysql_close(conn);
return row;
}

Expand All @@ -839,7 +839,7 @@ MYSQL_RES *one_query_res(char *query)
mysql_query(conn, query);
res_set = mysql_store_result(conn);

do_disc(conn);
mysql_close(conn);
return res_set;
}

Expand All @@ -857,7 +857,7 @@ int one_query_count(char *query)

mysql_free_result(res_set);

do_disc(conn);
mysql_close(conn);
return res;
}

Expand All @@ -867,7 +867,7 @@ void one_query(char *query)

conn = open_conn();
mysql_query(conn, query);
do_disc(conn);
mysql_close(conn);
}

void enter_text(CHAR_DATA *ch, DO_FUN *end_fun)
Expand Down Expand Up @@ -910,7 +910,7 @@ void one_fquery(char *query)
MYSQL *conn;
conn = open_fconn();
mysql_query(conn, query);
do_disc(conn);
mysql_close(conn);
}

void plug_graveyard(CHAR_DATA *ch, int type)
Expand Down Expand Up @@ -1161,7 +1161,7 @@ void do_pktrack(CHAR_DATA *ch, char *argument)
free_buf(buffer);
}

do_disc(conn);
mysql_close(conn);
}

bool trusts(CHAR_DATA *ch, CHAR_DATA *victim)
Expand Down Expand Up @@ -2040,11 +2040,13 @@ void do_ltrack(CHAR_DATA *ch, char *argument)
mysql_free_result(res_set);
page_to_char(buf_string(buffer), ch);
free_buf(buffer);
return do_disc(conn);
mysql_close(conn);
return;
}

send_to_char("No matching results were found.\n\r", ch);
return do_disc(conn);
mysql_close(conn);
return;
}

void do_assess_old(CHAR_DATA *ch, char *argument)
Expand Down
17 changes: 6 additions & 11 deletions code/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void modhelp_end_fun(CHAR_DATA *ch, char *argument)

sprintf(results, "%i helpfiles updated.\n\r", (int)mysql_affected_rows(conn));
send_to_char(results, ch);
do_disc(conn);
mysql_close(conn);
}
void do_modhelp(CHAR_DATA *ch, char *argument)
{
Expand Down Expand Up @@ -105,7 +105,7 @@ void do_modhelp(CHAR_DATA *ch, char *argument)
mysql_free_result(res_set);
}

do_disc(conn);
mysql_close(conn);
}

void do_help(CHAR_DATA *ch, char *argument)
Expand Down Expand Up @@ -197,7 +197,7 @@ void do_help(CHAR_DATA *ch, char *argument)
}

mysql_free_result(res_set);
do_disc(conn);
mysql_close(conn);
}

void do_delhelp(CHAR_DATA *ch, char *argument)
Expand Down Expand Up @@ -232,7 +232,7 @@ void do_delhelp(CHAR_DATA *ch, char *argument)

sprintf(buf, "%i helpfiles deleted.\n\r", (int)mysql_affected_rows(conn));
send_to_char(buf, ch);
do_disc(conn);
mysql_close(conn);
}

void addhelp_end_fun(CHAR_DATA *ch, char *argument)
Expand Down Expand Up @@ -295,7 +295,7 @@ void do_addhelp(CHAR_DATA *ch, char *argument)

sprintf(buf, "Help file added:\n\rTitle: %s\n\rSkill Required: %s\n\rMinimum Level: %d\n\rHelp Text: %s\n\r", ttitle, skill, minlevel, ch->pcdata->entered_text);
send_to_char(buf, ch);
do_disc(conn);
mysql_close(conn);
}

void do_listhelp(CHAR_DATA *ch, char *argument)
Expand Down Expand Up @@ -350,7 +350,7 @@ void do_listhelp(CHAR_DATA *ch, char *argument)
mysql_free_result(res_set);
}

do_disc(conn);
mysql_close(conn);
}

MYSQL *do_conn(const char *host_name, const char *user_name, const char *password,
Expand All @@ -375,11 +375,6 @@ MYSQL *do_conn(const char *host_name, const char *user_name, const char *passwor
return conn; /* connection is established */
}

void do_disc(MYSQL *conn)
{
mysql_close(conn);
}

void print_error(MYSQL *conn, char *message)
{
fprintf(stderr, "%s\n", message);
Expand Down
1 change: 0 additions & 1 deletion code/help.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void addhelp_end_fun (CHAR_DATA *ch, char *argument);
void do_addhelp (CHAR_DATA *ch, char *argument);
void do_listhelp (CHAR_DATA *ch, char *argument);
MYSQL *do_conn (const char *host_name, const char *user_name, const char *password, const char *db_name, unsigned int port_num, const char *socket_name, unsigned int flags);
void do_disc (MYSQL *conn);
void print_error (MYSQL *conn, char *message);

#endif /* HELP_H */
2 changes: 1 addition & 1 deletion code/update.c
Original file line number Diff line number Diff line change
Expand Up @@ -3221,7 +3221,7 @@ void save_demos()
mysql_free_result(res_set);
fprintf(fp,"\n\rTotal %d\n\r",total);
fclose(fp);
do_disc(conn);
mysql_close(conn);
*/
}

Expand Down

0 comments on commit 207fbd5

Please sign in to comment.