Go Back   EQEmulator Home > EQEmulator Forums > Development > Development: Custom Code

Development: Custom Code This is for code thatdoes not emulate live and wont be added to the official code.

Reply
 
Thread Tools Display Modes
  #1  
Old 08-11-2010, 11:24 PM
pfyon's Avatar
pfyon
Discordant
 
Join Date: Mar 2009
Location: Ottawa
Posts: 495
Default EQEmuLoginServer - Creates account upon login

This might be useful for small servers for just friends. When someone logs in and the username does not already exist in the DB, it will create a new user with username/password given (and email address nobody@localhost).

Tested on Ubuntu 10.04 with rev 1620. The revision numbers in the diff are because I was comitting against my own svn.

Code:
Index: Client.cpp
===================================================================
--- Client.cpp  (revision 60)
+++ Client.cpp  (working copy)
@@ -225,11 +225,29 @@
        _HeapDeleteCharBuffer(e_buffer);
 #endif

-       bool result;
+       bool result = false;
        if(server.db->GetLoginDataFromAccountName(e_user, d_pass_hash, d_account_id) == false)
        {
                log->Log(log_client_error, "Error logging in, user %s does not exist in the database.", e_user.c_str());
-               result = false;
+               if(server.db->CreateLoginAccount(e_user.c_str(), e_hash.c_str()))
+               {
+                       //Made the account properly
+                       if(server.db->GetLoginDataFromAccountName(e_user, d_pass_hash, d_account_id) == false)
+                       {
+                               //Somehow did not authenticate properly
+                               log->Log(log_client_error, "Error logging in, user %s does not exist in the database.", e_user.c_str());
+                               result = false;
+                       } else
+                       {
+                               if(d_pass_hash.compare(e_hash) == 0)
+                               {
+                                       result = true;
+                               } else
+                               {
+                                       result = false;
+                               }
+                       }
+               }
        }
        else
        {
Code:
Index: DatabaseMySQL.h
===================================================================
--- DatabaseMySQL.h     (revision 56)
+++ DatabaseMySQL.h     (working copy)
@@ -88,6 +88,11 @@
         * Creates new world registration for unregistered servers and returns new id
         */
        virtual bool CreateWorldRegistration(string long_name, string short_name, unsigned int &id);
+
+       /**
+        * Creates a new login account in the player accounts table
+        */
+       virtual bool CreateLoginAccount(string name, string password);
 protected:
        string user, pass, host, port, name;
        MYSQL *db;
Code:
Index: DatabaseMySQL.cpp
===================================================================
--- DatabaseMySQL.cpp   (revision 56)
+++ DatabaseMySQL.cpp   (working copy)
@@ -97,6 +97,36 @@
        return false;
 }

+bool DatabaseMySQL::CreateLoginAccount(string name, string password)
+{
+       if(!db)
+       {
+               return false;
+       }
+
+       MYSQL_RES *res;
+       MYSQL_ROW row;
+       char escaped_name[101];
+       char escaped_password[101];
+       unsigned long length;
+       length = mysql_real_escape_string(db, escaped_name, name.substr(0, 50).c_str(), name.substr(0, 100).length());
+       escaped_name[length+1] = 0;
+       length = mysql_real_escape_string(db, escaped_password, password.substr(0, 50).c_str(), password.substr(0, 100).length());
+       escaped_password[length+1] = 0;
+
+       stringstream query(stringstream::in | stringstream::out);
+       query << "INSERT INTO " << server.options.GetAccountTable() << " (AccountName, AccountPassword, AccountCreateDate, AccountEmail)";
+       query << "VALUES ('" << escaped_name << "', '" << escaped_password << "', now(), 'nobody@localhost')";
+
+       if(mysql_query(db, query.str().c_str()) != 0)
+       {
+               log->Log(log_database, "Error creating login account: %s", query.str().c_str());
+               return false;
+       }
+
+       return true;
+}
+
 bool DatabaseMySQL::GetWorldRegistration(string long_name, string short_name, unsigned int &id, string &desc, unsigned int &list_id,
                unsigned int &trusted, string &list_desc, string &account, string &password)
 {
Code:
Index: Database.h
===================================================================
--- Database.h  (revision 56)
+++ Database.h  (working copy)
@@ -73,6 +73,11 @@
         * Creates new world registration for unregistered servers and returns new id
         */
        virtual bool CreateWorldRegistration(string long_name, string short_name, unsigned int &id) { return false; }
+
+       /**
+        * Creates a new login account in the player accounts table
+        */
+       virtual bool CreateLoginAccount(string name, string password) { return false;}
 protected:
        string user, pass, host, port, name;
 };
Reply With Quote
  #2  
Old 08-26-2010, 07:36 PM
Swiftsong_Lorekeeper
Sarnak
 
Join Date: Jun 2010
Location: Virginia Beach
Posts: 34
Default

That is a pretty cool tool. I'm new to running my own server so I was curious, if you have time, that you could explain what to do with these :p I would like to install and be able to not have to worry about manually inputting account information.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 12:41 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3