viewing paste Unknown #9417 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
===================================================================
--- src/login/account_sql.c (revision 17484)
+++ src/login/account_sql.c (working copy)
@@ -4,6 +4,7 @@
 #include "../common/malloc.h"
 #include "../common/mmo.h"
 #include "../common/showmsg.h"
+#include "../common/harmony.h"
 #include "../common/sql.h"
 #include "../common/strlib.h"
 #include "../common/timer.h"
@@ -68,6 +69,9 @@
 static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id);
 static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new);
 
+// Harmony
+static bool account_db_sql_is_mac_banned(AccountDB* db, const char *mac);
+
 /// public constructor
 AccountDB* account_db_sql(void)
 {
@@ -84,6 +88,7 @@
    db->vtable.load_num     = &account_db_sql_load_num;
    db->vtable.load_str     = &account_db_sql_load_str;
    db->vtable.iterator     = &account_db_sql_iterator;
+   db->vtable.is_mac_banned= &account_db_sql_is_mac_banned;
 
    // initialize to default values
    db->accounts = NULL;
@@ -401,6 +406,26 @@
    return result;
 }
 
+static bool account_db_sql_is_mac_banned(AccountDB* self, const char *mac) {
+   AccountDB_SQL* db = (AccountDB_SQL*)self;
+   Sql *db_handle = db->accounts;
+   SqlStmt* stmt = SqlStmt_Malloc(db_handle);
+
+   bool result = false;
+
+   if (SQL_SUCCESS != SqlStmt_Prepare(stmt, "SELECT 1 FROM mac_bans WHERE mac = ?") ||
+       SQL_SUCCESS != SqlStmt_BindParam(stmt, 0, SQLDT_STRING, (void*)mac, strlen(mac)) ||
+       SQL_SUCCESS != SqlStmt_Execute(stmt)) {
+           Sql_ShowDebug(db_handle);
+   } else {
+       result = (SqlStmt_NumRows(stmt) > 0);
+       SqlStmt_FreeResult(stmt);
+   }
+   SqlStmt_Free(stmt);
+
+   return result;
+}
+
 /// update an existing account with the provided new data (both account and regs)
 static bool account_db_sql_save(AccountDB* self, const struct mmo_account* acc)
 {
@@ -522,7 +547,7 @@
 
    // retrieve login entry for the specified account
    if( SQL_ERROR == Sql_Query(sql_handle,
-       "SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`group_id`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip`,`birthdate`,`character_slots`,`pincode`, `pincode_change` FROM `%s` WHERE `account_id` = %d",
+       "SELECT `account_id`,`userid`,`user_pass`,`sex`,`email`,`group_id`,`state`,`unban_time`,`expiration_time`,`logincount`,`lastlogin`,`last_ip`,`birthdate`,`character_slots`,`pincode`, `pincode_change`,`last_mac` FROM `%s` WHERE `account_id` = %d",
        db->account_db, account_id )
    ) {
        Sql_ShowDebug(sql_handle);
@@ -551,6 +576,7 @@
    Sql_GetData(sql_handle, 13, &data, NULL); acc->char_slots = atoi(data);
    Sql_GetData(sql_handle, 14, &data, NULL); safestrncpy(acc->pincode, data, sizeof(acc->pincode));
    Sql_GetData(sql_handle, 15, &data, NULL); acc->pincode_change = atol(data);
+   Sql_GetData(sql_handle, 16, &data, NULL); safestrncpy(acc->mac_address, data, sizeof(acc->mac_address));
 
    Sql_FreeResult(sql_handle);
 
@@ -599,7 +625,7 @@
    if( is_new )
    {// insert into account table
        if( SQL_SUCCESS != SqlStmt_Prepare(stmt,
-           "INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`, `birthdate`, `character_slots`, `pincode`, `pincode_change`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
+           "INSERT INTO `%s` (`account_id`, `userid`, `user_pass`, `sex`, `email`, `group_id`, `state`, `unban_time`, `expiration_time`, `logincount`, `lastlogin`, `last_ip`, `birthdate`, `character_slots`, `pincode`, `pincode_change`, `last_mac`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
            db->account_db)
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  0, SQLDT_INT,    (void*)&acc->account_id,      sizeof(acc->account_id))
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  1, SQLDT_STRING, (void*)acc->userid,           strlen(acc->userid))
@@ -617,6 +643,7 @@
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 13, SQLDT_UCHAR,  (void*)&acc->char_slots,      sizeof(acc->char_slots))
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 14, SQLDT_STRING, (void*)&acc->pincode,         strlen(acc->pincode))
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 15, SQLDT_LONG,   (void*)&acc->pincode_change,  sizeof(acc->pincode_change))
+       ||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 16, SQLDT_STRING, (void*)acc->mac_address,      strlen(acc->mac_address))
        ||  SQL_SUCCESS != SqlStmt_Execute(stmt)
        ) {
            SqlStmt_ShowDebug(stmt);
@@ -625,7 +652,7 @@
    }
    else
    {// update account table
-       if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`group_id`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=?,`birthdate`=?,`character_slots`=?,`pincode`=?, `pincode_change`=? WHERE `account_id` = '%d'", db->account_db, acc->account_id)
+       if( SQL_SUCCESS != SqlStmt_Prepare(stmt, "UPDATE `%s` SET `userid`=?,`user_pass`=?,`sex`=?,`email`=?,`group_id`=?,`state`=?,`unban_time`=?,`expiration_time`=?,`logincount`=?,`lastlogin`=?,`last_ip`=?,`birthdate`=?,`character_slots`=?,`pincode`=?, `pincode_change`=?,`last_mac`=? WHERE `account_id` = '%d'", db->account_db, acc->account_id)
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  0, SQLDT_STRING, (void*)acc->userid,           strlen(acc->userid))
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  1, SQLDT_STRING, (void*)acc->pass,             strlen(acc->pass))
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt,  2, SQLDT_ENUM,   (void*)&acc->sex,             sizeof(acc->sex))
@@ -641,6 +668,7 @@
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 12, SQLDT_UCHAR,  (void*)&acc->char_slots,      sizeof(acc->char_slots))
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 13, SQLDT_STRING, (void*)&acc->pincode,         strlen(acc->pincode))
        ||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 14, SQLDT_LONG,   (void*)&acc->pincode_change,  sizeof(acc->pincode_change))
+       ||  SQL_SUCCESS != SqlStmt_BindParam(stmt, 15, SQLDT_STRING, (void*)acc->mac_address,      strlen(acc->mac_address))
        ||  SQL_SUCCESS != SqlStmt_Execute(stmt)
        ) {
            SqlStmt_ShowDebug(stmt);
Viewed 713 times, submitted by Guest.