Fimbulwinter Project  Pre-Alpha
An Ragnarok Online Emulator
ZoneServer/ZoneServer.hpp
00001 /*==================================================================*
00002 *     ___ _           _           _          _       _                          *
00003 *    / __(_)_ __ ___ | |__  _   _| |_      _(_)_ __ | |_ ___ _ __       *
00004 *   / _\ | | '_ ` _ \| '_ \| | | | \ \ /\ / / | '_ \| __/ _ \ '__|      *
00005 *  / /   | | | | | | | |_) | |_| | |\ V  V /| | | | | ||  __/ |         *
00006 *  \/    |_|_| |_| |_|_.__/ \__,_|_| \_/\_/ |_|_| |_|\__\___|_|         *
00007 *                                                                                                                                       *
00008 * ------------------------------------------------------------------*
00009 *                                                        Emulator                                       *
00010 * ------------------------------------------------------------------*
00011 *                     Licenced under GNU GPL v3                     *
00012 * ----------------------------------------------------------------- *
00013 *              Character Server Structures and classes                  *
00014 * ==================================================================*/
00015 
00016 #pragma once
00017 
00018 #include <config_file.hpp>
00019 #include <tcp_server.hpp>
00020 #include <string>
00021 #include <soci/soci.h>
00022 #include <ragnarok.hpp>
00023 #include <map_index.hpp>
00024 #include "BlockManager.hpp"
00025 #include "PlayerModules.hpp"
00026 
00027 using namespace std;
00028 
00029 #define MAX_PACKET_DB 0x900
00030 #define MAX_PACKET_POS 20
00031 
00032 enum SessionState 
00033 { 
00034         ST_LOGIN, 
00035         ST_LOGOUT, 
00036         ST_MAPCHANGE 
00037 };
00038 
00047 struct AuthNode
00048 {
00049         AuthNode()
00050         {
00051                 sd = 0;
00052                 char_dat = 0;
00053         }
00054 
00055         int account_id, char_id;
00056         int login_id1, login_id2, sex;
00057         time_t expiration_time;
00058         struct ZoneSessionData *sd;
00059         struct CharData *char_dat;
00060         unsigned int node_created;
00061         enum SessionState auth_state;
00062 
00063         tcp_connection::pointer cl;
00064 };
00065 
00073 struct OnlineChar 
00074 {
00075         int account_id;
00076         int char_id;
00077 
00078         tcp_connection::pointer cl;
00079         int disconnect_timer;
00080 };
00081 
00082 typedef boost::function<void (tcp_connection::pointer, ZoneSessionData *)> PacketCallback;
00083 struct PacketData
00084 {
00085         short len;
00086         PacketCallback callback;
00087         unsigned short pos[MAX_PACKET_POS];
00088 };
00089 
00090 #define addpacket(id, size, func, ...) ZoneServer::client_add_packet(id, size, func, __VA_ARGS__, 0xFFFF)
00091 
00100 class ZoneServer
00101 {
00102 public:
00103         typedef std::map<int, struct AuthNode> auth_node_db;
00104         typedef std::map<int, struct OnlineChar> online_account_db;
00105 
00106         struct login_config
00107         {
00108                 // Network
00109                 string                  network_bindip;
00110                 unsigned short  network_bindport;
00111 
00112                 // IP to sent to CharServer
00113                 string                  network_zoneip;
00114 
00115                 // Interconnection
00116                 string                  inter_char_ip;
00117                 unsigned short  inter_char_port;
00118                 string                  inter_char_user;
00119                 string                  inter_char_pass;
00120         }; 
00121 
00122         static void run();
00123         static int parse_from_client(tcp_connection::pointer cl);
00124         static int parse_from_char(tcp_connection::pointer cl);
00125         
00126         // Char InterConn
00127         static void connect_to_char();
00128         static void send_maps();
00129         static void inter_confirm_auth(ZoneSessionData *sd);
00130         static void create_auth_entry(ZoneSessionData *sd, enum SessionState state);
00131 
00132         // Client
00133         static PacketData *client_packets[MAX_PACKET_DB];
00134         static void set_char_offline(int account_id, char char_id);
00135         static void disconnect_timeout(int timer, int accid);
00136 
00137         static void init_packets();
00138         static void client_add_packet(unsigned short id, short size, PacketCallback func, ...);
00139 
00140         static void auth_fail(tcp_connection::pointer cl, int err);
00141         static void auth_ok( ZoneSessionData * sd );
00142 
00143         static void request_registry( ZoneSessionData * sd, int flag );
00144         static void clif_spawn( struct BlockList* bl );
00145         static void addblock( struct BlockList* bl );
00146 
00147         // Char InterConn
00148         static bool char_conn_ok;
00149         static tcp_connection::pointer char_conn;
00150 
00151         // Config
00152         static config_file *char_config;
00153 
00154         static struct login_config config;
00155 
00156         // Network
00157         static boost::asio::io_service *io_service;
00158         static tcp_server *server;
00159 
00160         // Database
00161         static soci::session *database;
00162 
00163         // Auth
00164         static auth_node_db auth_nodes;
00165         static online_account_db online_chars;
00166 };
 All Classes Functions