|
Fimbulwinter Project
Pre-Alpha
An Ragnarok Online Emulator
|
00001 /*==================================================================* 00002 * ___ _ _ _ _ _ * 00003 * / __(_)_ __ ___ | |__ _ _| |_ _(_)_ __ | |_ ___ _ __ * 00004 * / _\ | | '_ ` _ \| '_ \| | | | \ \ /\ / / | '_ \| __/ _ \ '__| * 00005 * / / | | | | | | | |_) | |_| | |\ V V /| | | | | || __/ | * 00006 * \/ |_|_| |_| |_|_.__/ \__,_|_| \_/\_/ |_|_| |_|\__\___|_| * 00007 * * 00008 * ------------------------------------------------------------------* 00009 * Emulator * 00010 * ------------------------------------------------------------------* 00011 * Licenced under GNU GPL v3 * 00012 * ----------------------------------------------------------------- * 00013 * Authentication Server Structures and Classes * 00014 * ==================================================================*/ 00015 00016 #pragma once 00017 00018 #include <config_file.hpp> 00019 #include <tcp_server.hpp> 00020 #include <string> 00021 00022 #include <soci/soci.h> 00023 00024 #include <ragnarok.hpp> 00025 #include "AccountDB.h" 00026 #include <map> 00027 00028 using namespace std; 00029 00030 #define AUTH_TIMEOUT 30000 00031 00032 enum auth_type 00033 { 00034 auth_raw, 00035 auth_md5, 00036 auth_token, 00037 }; 00038 00039 /*==============================================================* 00040 * Structure: Authorization Server Data * 00041 * Author: GreenBox * 00042 * Date: 08/12/11 * 00043 * Description: Structure responsible for basic account * 00044 * informations. * 00045 **==============================================================*/ 00046 struct AuthSessionData 00047 { 00048 int account_id; 00049 long login_id1; 00050 long login_id2; 00051 char sex;// 'F','M','S' 00052 00053 char username[NAME_LENGTH]; 00054 char password[32+1]; 00055 enum auth_type type; 00056 00057 char md5key[20]; 00058 unsigned short md5keylen; 00059 00060 char lastlogin[24]; 00061 unsigned char level; 00062 unsigned char clienttype; 00063 unsigned int version; 00064 00065 bool gameguardChallenged; 00066 00067 tcp_connection::pointer cl; 00068 }; 00069 00070 00071 /*==============================================================* 00072 * Structure: Character server connection data * 00073 * Author: GreenBox * 00074 * Date: 08/12/11 * 00075 * Description: Structure responsible for char-server * 00076 * connection. * 00077 **==============================================================*/ 00078 struct CharServerConnection 00079 { 00080 int account_id; 00081 00082 boost::asio::ip::address_v4 addr; 00083 unsigned short port; 00084 00085 char name[20]; 00086 tcp_connection::pointer cl; 00087 00088 unsigned int users; 00089 }; 00090 00091 /*==============================================================* 00092 * Structure: Authorization Node * 00093 * Author: GreenBox * 00094 * Date: 08/12/11 * 00095 * Description: * 00096 **==============================================================*/ 00097 struct AuthNode 00098 { 00099 int login_id1; 00100 int login_id2; 00101 char sex; 00102 }; 00103 00104 /*==============================================================* 00105 * Structure: Online Account Info * 00106 * Author: GreenBox * 00107 * Date: 08/12/11 * 00108 * Description: * 00109 **==============================================================*/ 00110 struct OnlineAccount 00111 { 00112 int char_server; 00113 int enter_charserver_timeout; 00114 }; 00115 00116 /*==============================================================* 00117 * Class: Authorization Server Data * 00118 * Author: GreenBox * 00119 * Date: 08/12/11 * 00120 * Description: Class responsible for general Auth-Server * 00121 * informations. * 00122 **==============================================================*/ 00123 class AuthServer 00124 { 00125 public: 00126 typedef std::map<int, struct OnlineAccount> online_account_db; 00127 typedef std::map<int, struct AuthNode> auth_node_db; 00128 typedef std::map<int, struct CharServerConnection> char_server_db; 00129 00130 struct login_config 00131 { 00132 // Network 00133 string network_bindip; 00134 unsigned short network_bindport; 00135 00136 // Authentication Types/Settings 00137 bool auth_use_md5; 00138 //int OTP; [TODO] 00139 }; 00140 00141 static void run(); 00142 static int parse_from_client(tcp_connection::pointer cl); 00143 static int parse_from_char(tcp_connection::pointer cl); 00144 00145 // Auth 00146 static int authenticate(AuthSessionData *asd); 00147 static void send_auth_err(AuthSessionData *asd, int result); 00148 static void send_auth_ok(AuthSessionData *asd); 00149 00150 static bool check_auth(const char *md5key, enum auth_type type, const char *passwd, const char *refpass); 00151 00152 static void select_charserver_timeout(int timer, int accid); 00153 static void shutdown_account(int account_id); 00154 00155 // Inter 00156 static void char_sendallwos(int cs, unsigned char *buf, size_t len); 00157 00158 // Config 00159 static config_file *auth_config; 00160 00161 static struct login_config config; 00162 00163 // Network 00164 static tcp_server *server; 00165 00166 // Database 00167 static soci::session *database; 00168 static AccountDB *accounts; 00169 00170 // Interconnection 00171 static char_server_db servers; 00172 static auth_node_db auth_nodes; 00173 static online_account_db online_accounts; 00174 private: 00175 };
1.7.6.1