Skip to content

Commit

Permalink
-Apply login_refac (from old refac branch) in same way as char_refac,…
Browse files Browse the repository at this point in the history
… each interface now have his own file.

-Remove _sql from some file.
Thx to Euphy for helping with documentation.
  • Loading branch information
lighta committed Jul 15, 2014
1 parent 7ccd13e commit a24da6d
Show file tree
Hide file tree
Showing 22 changed files with 2,834 additions and 1,820 deletions.
6 changes: 6 additions & 0 deletions conf/login_athena.conf
Expand Up @@ -180,5 +180,11 @@ client_hash_check: off
//client_hash: 10, cb1ea78023d337c38e8ba5124e2338ae
//client_hash: 99, disabled

//New registration flood protection [Kevin]
//Number of new registration allowed
allowed_regs: 1
//Time in second before the counter for the number of registration is reset
time_allowed: 10

import: conf/inter_athena.conf
import: conf/import/login_conf.txt
3 changes: 2 additions & 1 deletion conf/subnet_athena.conf
@@ -1,6 +1,7 @@
// Subnet support file
// Format is:
// subnet: net-submask:char_ip:map_ip
// you can add more than one subnet
// you can add more than one subnet (max 16)
// check is if((net-submask & char_ip ) == (net-submask & servip)) => ok

subnet: 255.0.0.0:127.0.0.1:127.0.0.1
38 changes: 3 additions & 35 deletions src/char/char.c
Expand Up @@ -1968,43 +1968,11 @@ int char_lan_subnetcheck(uint32 ip){
}

// Console Command Parser [Wizputer]
int parse_console(const char* buf)
{
char type[64];
char command[64];
int n=0;

if( ( n = sscanf(buf, "%63[^:]:%63[^\n]", type, command) ) < 2 ){
if((n = sscanf(buf, "%63[^\n]", type))<1) return -1; //nothing to do no arg
}
if( n != 2 ){ //end string
ShowNotice("Type: '%s'\n",type);
command[0] = '\0';
}
else
ShowNotice("Type of command: '%s' || Command: '%s'\n",type,command);

if( n == 2 && strcmpi("server", type) == 0 ){
if( strcmpi("shutdown", command) == 0 || strcmpi("exit", command) == 0 || strcmpi("quit", command) == 0 ){
runflag = CHARSERVER_ST_SHUTDOWN;
}
else if( strcmpi("alive", command) == 0 || strcmpi("status", command) == 0 )
ShowInfo(CL_CYAN"Console: "CL_BOLD"I'm Alive."CL_RESET"\n");
}
else if( strcmpi("ers_report", type) == 0 ){
ers_report();
}
else if( strcmpi("help", type) == 0 ){
ShowInfo("Available commands:\n");
ShowInfo("\t server:shutdown => Stops the server.\n");
ShowInfo("\t server:alive => Checks if the server is running.\n");
ShowInfo("\t ers_report => Displays database usage.\n");
}

return 0;
//FIXME to be remove (moved to cnslif / will be done once map/char/login, all have their cnslif interface ready)
int parse_console(const char* buf){
return cnslif_parse(buf);
}


//------------------------------------------------
//Pincode system
//------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions src/config/const.h
Expand Up @@ -89,6 +89,9 @@
/* Feb 1st 2012 */
#if PACKETVER >= 20120201
#define NEW_CARTS
#ifndef ENABLE_SC_SAVING
#warning "Cart won't be able to be saved for relog"
#endif
#define MAX_CARTS 9
#else
#define MAX_CARTS 5
Expand Down
168 changes: 115 additions & 53 deletions src/login/account_sql.c → src/login/account.c
@@ -1,5 +1,11 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
/**
* @file account.c
* Module purpose is to save, load, and update changes into the account table or file.
* Licensed under GNU GPL.
* For more information, see LICENCE in the main folder.
* @author Athena Dev Teams < r15k
* @author rAthena Dev Team
*/

#include "../common/malloc.h"
#include "../common/mmo.h"
Expand All @@ -16,8 +22,7 @@
#define ACCOUNT_SQL_DB_VERSION 20110114

/// internal structure
typedef struct AccountDB_SQL
{
typedef struct AccountDB_SQL {
AccountDB vtable; // public interface

Sql* accounts; // SQL accounts storage
Expand All @@ -44,10 +49,8 @@ typedef struct AccountDB_SQL
} AccountDB_SQL;

/// internal structure
typedef struct AccountDBIterator_SQL
{
typedef struct AccountDBIterator_SQL {
AccountDBIterator vtable; // public interface

AccountDB_SQL* db;
int last_account_id;
} AccountDBIterator_SQL;
Expand All @@ -70,8 +73,7 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new);

/// public constructor
AccountDB* account_db_sql(void)
{
AccountDB* account_db_sql(void) {
AccountDB_SQL* db = (AccountDB_SQL*)aCalloc(1, sizeof(AccountDB_SQL));

// set up the vtable
Expand Down Expand Up @@ -114,9 +116,11 @@ AccountDB* account_db_sql(void)
/* ------------------------------------------------------------------------- */


/// establishes database connection
static bool account_db_sql_init(AccountDB* self)
{
/**
* Establish the database connection.
* @param self: pointer to db
*/
static bool account_db_sql_init(AccountDB* self) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
Sql* sql_handle;
const char* username;
Expand Down Expand Up @@ -162,17 +166,27 @@ static bool account_db_sql_init(AccountDB* self)
return true;
}

/// disconnects from database
static void account_db_sql_destroy(AccountDB* self)
{
/**
* Destroy the database and close the connection to it.
* @param self: pointer to db
*/
static void account_db_sql_destroy(AccountDB* self){
AccountDB_SQL* db = (AccountDB_SQL*)self;

Sql_Free(db->accounts);
db->accounts = NULL;
aFree(db);
}

/// Gets a property from this database.
/**
* Get configuration information into buf.
* If the option is supported, adjust the internal state.
* @param self: pointer to db
* @param key: config keyword
* @param buf: value set of the keyword
* @param buflen: size of buffer to avoid out of bound
* @return true if successful, false if something has failed
*/
static bool account_db_sql_get_property(AccountDB* self, const char* key, char* buf, size_t buflen)
{
AccountDB_SQL* db = (AccountDB_SQL*)self;
Expand Down Expand Up @@ -259,9 +273,15 @@ static bool account_db_sql_get_property(AccountDB* self, const char* key, char*
return false;// not found
}

/// if the option is supported, adjusts the internal state
static bool account_db_sql_set_property(AccountDB* self, const char* key, const char* value)
{
/**
* Read and set configuration.
* If the option is supported, adjust the internal state.
* @param self: pointer to db
* @param key: config keyword
* @param value: config value for keyword
* @return true if successful, false if something has failed
*/
static bool account_db_sql_set_property(AccountDB* self, const char* key, const char* value) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
const char* signature;

Expand Down Expand Up @@ -330,11 +350,15 @@ static bool account_db_sql_set_property(AccountDB* self, const char* key, const
return false;// not found
}

/// create a new account entry
/// If acc->account_id is -1, the account id will be auto-generated,
/// and its value will be written to acc->account_id if everything succeeds.
static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc)
{
/**
* Create a new account entry.
* If acc->account_id is -1, the account id will be auto-generated,
* and its value will be written to acc->account_id if everything succeeds.
* @param self: pointer to db
* @param acc: pointer of mmo_account to save
* @return true if successful, false if something has failed
*/
static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
Sql* sql_handle = db->accounts;

Expand Down Expand Up @@ -383,9 +407,13 @@ static bool account_db_sql_create(AccountDB* self, struct mmo_account* acc)
return mmo_auth_tosql(db, acc, true);
}

/// delete an existing account entry + its regs
static bool account_db_sql_remove(AccountDB* self, const int account_id)
{
/**
* Delete an existing account entry and its regs.
* @param self: pointer to db
* @param account_id: id of user account
* @return true if successful, false if something has failed
*/
static bool account_db_sql_remove(AccountDB* self, const int account_id) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
Sql* sql_handle = db->accounts;
bool result = false;
Expand All @@ -402,23 +430,40 @@ static bool account_db_sql_remove(AccountDB* self, const int account_id)
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)
{
/**
* Update an existing account with the new data provided (both account and regs).
* @param self: pointer to db
* @param acc: pointer of mmo_account to save
* @return true if successful, false if something has failed
*/
static bool account_db_sql_save(AccountDB* self, const struct mmo_account* acc) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
return mmo_auth_tosql(db, acc, false);
}

/// retrieve data from db and store it in the provided data structure
static bool account_db_sql_load_num(AccountDB* self, struct mmo_account* acc, const int account_id)
{
/**
* Retrieve data from db and store it in the provided data structure.
* Filled data structure is done by delegation to mmo_auth_fromsql.
* @param self: pointer to db
* @param acc: pointer of mmo_account to fill
* @param account_id: id of user account
* @return true if successful, false if something has failed
*/
static bool account_db_sql_load_num(AccountDB* self, struct mmo_account* acc, const int account_id) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
return mmo_auth_fromsql(db, acc, account_id);
}

/// retrieve data from db and store it in the provided data structure
static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid)
{
/**
* Retrieve data from db and store it in the provided data structure.
* Doesn't actually retrieve data yet: escapes and checks userid, then transforms it to accid for fetching.
* Filled data structure is done by delegation to account_db_sql_load_num.
* @param self: pointer to db
* @param acc: pointer of mmo_account to fill
* @param userid: name of user account
* @return true if successful, false if something has failed
*/
static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, const char* userid) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
Sql* sql_handle = db->accounts;
char esc_userid[2*NAME_LENGTH+1];
Expand Down Expand Up @@ -454,10 +499,12 @@ static bool account_db_sql_load_str(AccountDB* self, struct mmo_account* acc, co
return account_db_sql_load_num(self, acc, account_id);
}


/// Returns a new forward iterator.
static AccountDBIterator* account_db_sql_iterator(AccountDB* self)
{
/**
* Create a new forward iterator.
* @param self: pointer to db iterator
* @return a new db iterator
*/
static AccountDBIterator* account_db_sql_iterator(AccountDB* self) {
AccountDB_SQL* db = (AccountDB_SQL*)self;
AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)aCalloc(1, sizeof(AccountDBIterator_SQL));

Expand All @@ -472,18 +519,22 @@ static AccountDBIterator* account_db_sql_iterator(AccountDB* self)
return &iter->vtable;
}


/// Destroys this iterator, releasing all allocated memory (including itself).
static void account_db_sql_iter_destroy(AccountDBIterator* self)
{
/**
* Destroys this iterator, releasing all allocated memory (including itself).
* @param self: pointer to db iterator
*/
static void account_db_sql_iter_destroy(AccountDBIterator* self) {
AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self;
aFree(iter);
}


/// Fetches the next account in the database.
static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc)
{
/**
* Fetches the next account in the database.
* @param self: pointer to db iterator
* @param acc: pointer of mmo_account to fill
* @return true if next account found and filled, false if something has failed
*/
static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account* acc) {
AccountDBIterator_SQL* iter = (AccountDBIterator_SQL*)self;
AccountDB_SQL* db = (AccountDB_SQL*)iter->db;
Sql* sql_handle = db->accounts;
Expand Down Expand Up @@ -514,9 +565,14 @@ static bool account_db_sql_iter_next(AccountDBIterator* self, struct mmo_account
return false;
}


static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id)
{
/**
* Fetch a struct mmo_account from sql.
* @param db: pointer to db
* @param acc: pointer of mmo_account to fill
* @param account_id: id of user account to take data from
* @return true if successful, false if something has failed
*/
static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int account_id) {
Sql* sql_handle = db->accounts;
char* data;
int i = 0;
Expand Down Expand Up @@ -587,8 +643,14 @@ static bool mmo_auth_fromsql(AccountDB_SQL* db, struct mmo_account* acc, int acc
return true;
}

static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new)
{
/**
* Save a struct mmo_account in sql.
* @param db: pointer to db
* @param acc: pointer of mmo_account to save
* @param is_new: if it's a new entry or should we update
* @return true if successful, false if something has failed
*/
static bool mmo_auth_tosql(AccountDB_SQL* db, const struct mmo_account* acc, bool is_new) {
Sql* sql_handle = db->accounts;
SqlStmt* stmt = SqlStmt_Malloc(sql_handle);
bool result = false;
Expand Down
16 changes: 10 additions & 6 deletions src/login/account.h
@@ -1,5 +1,11 @@
// Copyright (c) Athena Dev Teams - Licensed under GNU GPL
// For more information, see LICENCE in the main folder
/**
* @file account.h
* Module purpose is to save, load, and update changes into the account table or file.
* Licensed under GNU GPL.
* For more information, see LICENCE in the main folder.
* @author Athena Dev Teams < r15k
* @author rAthena Dev Team
*/

#ifndef __ACCOUNT_H_INCLUDED__
#define __ACCOUNT_H_INCLUDED__
Expand Down Expand Up @@ -61,8 +67,7 @@ struct mmo_account {
};


struct AccountDBIterator
{
struct AccountDBIterator {
/// Destroys this iterator, releasing all allocated memory (including itself).
///
/// @param self Iterator
Expand All @@ -77,8 +82,7 @@ struct AccountDBIterator
};


struct AccountDB
{
struct AccountDB {
/// Initializes this database, making it ready for use.
/// Call this after setting the properties.
///
Expand Down

1 comment on commit a24da6d

@cydh
Copy link
Contributor

@cydh cydh commented on a24da6d Jul 16, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

u didn't add the filters. xD

Please sign in to comment.