forked from metin2/server
Refactored directory structure, added game files from TMP
This commit is contained in:
57
src/libthecore/include/buffer.h
Normal file
57
src/libthecore/include/buffer.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Filename: buffer.h
|
||||
* Description: Buffer ó<><C3B3> <20><><EFBFBD><EFBFBD>
|
||||
*
|
||||
* Author: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> (aka. <20><><EFBFBD><EFBFBD>, Cronan), <20>ۿ<EFBFBD><DBBF><EFBFBD> (aka. myevan, <20><><EFBFBD>ڷ<EFBFBD>)
|
||||
*/
|
||||
#ifndef __INC_LIBTHECORE_BUFFER_H__
|
||||
#define __INC_LIBTHECORE_BUFFER_H__
|
||||
|
||||
#define SAFE_BUFFER_DELETE(buf) { if(buf != NULL) { buffer_delete(buf); buf = NULL; } }
|
||||
|
||||
typedef struct buffer BUFFER;
|
||||
typedef struct buffer * LPBUFFER;
|
||||
|
||||
struct buffer
|
||||
{
|
||||
struct buffer * next;
|
||||
|
||||
char * write_point;
|
||||
int write_point_pos;
|
||||
|
||||
const char * read_point;
|
||||
int length;
|
||||
|
||||
char * mem_data;
|
||||
int mem_size;
|
||||
|
||||
int flag;
|
||||
};
|
||||
|
||||
extern LPBUFFER buffer_new(int size); // <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
extern void buffer_delete(LPBUFFER buffer); // <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
extern void buffer_reset(LPBUFFER buffer); // <20><><EFBFBD><EFBFBD> <20><><EFBFBD>̵<EFBFBD><CCB5><EFBFBD> <20>ʱ<EFBFBD>ȭ
|
||||
|
||||
extern DWORD buffer_size(LPBUFFER buffer); // <20><><EFBFBD>ۿ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
extern int buffer_has_space(LPBUFFER buffer); // <20><> <20><> <20>ִ<EFBFBD> <20><><EFBFBD≯<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
extern void buffer_write (LPBUFFER& buffer, const void* src, int length); // <20><><EFBFBD>ۿ<EFBFBD> <20><><EFBFBD><EFBFBD>.
|
||||
extern void buffer_read(LPBUFFER buffer, void * buf, int bytes); // <20><><EFBFBD>ۿ<EFBFBD><DBBF><EFBFBD> <20>д´<D0B4>.
|
||||
extern BYTE buffer_get_byte(LPBUFFER buffer);
|
||||
extern WORD buffer_get_word(LPBUFFER buffer);
|
||||
extern DWORD buffer_get_dword(LPBUFFER buffer);
|
||||
|
||||
// buffer_proceed <20>Լ<EFBFBD><D4BC><EFBFBD> buffer_peek<65><6B><EFBFBD><EFBFBD> <20>б<EFBFBD><D0B1><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ƽ<DEBE> <20><> <20>ʿ䰡
|
||||
// <20><><EFBFBD><EFBFBD> <20><> ó<><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><EFBFBD> ó<><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ٰ<EFBFBD> <20>뺸<EFBFBD>ؾ<EFBFBD> <20><> <20><> <20><><EFBFBD><EFBFBD>.
|
||||
// (buffer_read, buffer_get_* <20>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD>쿡<EFBFBD><ECBFA1> <20>˾Ƽ<CBBE> ó<><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> peek<65><6B><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <20><><EFBFBD><EFBFBD> <20><EFBFBD><D7B7><EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>)
|
||||
extern const void * buffer_read_peek(LPBUFFER buffer); // <20>д<EFBFBD> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD>
|
||||
extern void buffer_read_proceed(LPBUFFER buffer, int length); // length<74><68>ŭ<EFBFBD><C5AD> ó<><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> write_peek<65><6B><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><EFBFBD> <20>質 <20>뺸<EFBFBD><EBBAB8> <20><>
|
||||
// buffer_write_proceed<65><64> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
||||
extern void * buffer_write_peek(LPBUFFER buffer); // <20><><EFBFBD><EFBFBD> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD>
|
||||
extern void buffer_write_proceed(LPBUFFER buffer, int length); // length<74><68> <20><><EFBFBD><EFBFBD> <20><>Ų<EFBFBD><C5B2>.
|
||||
|
||||
extern void buffer_adjust_size(LPBUFFER & buffer, int add_size); // add_size<7A><65>ŭ <20>߰<EFBFBD><DFB0><EFBFBD> ũ<>⸦ Ȯ<><C8AE>
|
||||
#endif
|
26
src/libthecore/include/heart.h
Normal file
26
src/libthecore/include/heart.h
Normal file
@ -0,0 +1,26 @@
|
||||
#ifndef __INC_LIBTHECORE_HEART_H__
|
||||
#define __INC_LIBTHECORE_HEART_H__
|
||||
|
||||
typedef struct heart HEART;
|
||||
typedef struct heart * LPHEART;
|
||||
|
||||
typedef void (*HEARTFUNC) (LPHEART heart, int pulse);
|
||||
|
||||
struct heart
|
||||
{
|
||||
HEARTFUNC func;
|
||||
|
||||
struct timeval before_sleep;
|
||||
struct timeval opt_time;
|
||||
struct timeval last_time;
|
||||
|
||||
int passes_per_sec;
|
||||
int pulse;
|
||||
};
|
||||
|
||||
extern LPHEART heart_new(int opt_usec, HEARTFUNC func);
|
||||
extern void heart_delete(LPHEART ht);
|
||||
extern int heart_idle(LPHEART ht); // <20><> pulse<73><65> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>.
|
||||
extern void heart_beat(LPHEART ht, int pulses);
|
||||
|
||||
#endif
|
39
src/libthecore/include/log.h
Normal file
39
src/libthecore/include/log.h
Normal file
@ -0,0 +1,39 @@
|
||||
#ifndef __INC_LIBTHECORE_LOG_H__
|
||||
#define __INC_LIBTHECORE_LOG_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
extern int log_init(void);
|
||||
extern void log_destroy(void);
|
||||
extern void log_rotate(void);
|
||||
|
||||
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD> ó<><C3B3> (<28><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> bitvector<6F><72> ó<><C3B3><EFBFBD>ȴ<EFBFBD>)
|
||||
extern void log_set_level(unsigned int level);
|
||||
extern void log_unset_level(unsigned int level);
|
||||
|
||||
// <20>α<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>ŭ <20><><EFBFBD><EFBFBD><EFBFBD>ϴ°<CFB4><C2B0><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Լ<EFBFBD>
|
||||
extern void log_set_expiration_days(unsigned int days);
|
||||
extern int log_get_expiration_days(void);
|
||||
|
||||
#ifndef __WIN32__
|
||||
extern void _sys_err(const char *func, int line, const char *format, ...);
|
||||
#else
|
||||
extern void _sys_err(const char *func, int line, const char *format, ...);
|
||||
#endif
|
||||
extern void sys_log_header(const char *header);
|
||||
extern void sys_log(unsigned int lv, const char *format, ...);
|
||||
extern void pt_log(const char *format, ...);
|
||||
|
||||
#ifndef __WIN32__
|
||||
#define sys_err(fmt, args...) _sys_err(__FUNCTION__, __LINE__, fmt, ##args)
|
||||
#else
|
||||
#define sys_err(fmt, ...) _sys_err(__FUNCTION__, __LINE__, fmt, __VA_ARGS__)
|
||||
#endif // __WIN32__
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // __INC_LOG_H__
|
40
src/libthecore/include/main.h
Normal file
40
src/libthecore/include/main.h
Normal file
@ -0,0 +1,40 @@
|
||||
#ifndef __INC_LIBTHECORE_MAIN_H__
|
||||
#define __INC_LIBTHECORE_MAIN_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#ifdef __LIBTHECORE__
|
||||
extern volatile int tics;
|
||||
extern volatile int shutdowned;
|
||||
#endif
|
||||
#include "heart.h"
|
||||
|
||||
extern LPHEART thecore_heart;
|
||||
|
||||
enum ENUM_PROFILER
|
||||
{
|
||||
PF_IDLE,
|
||||
PF_HEARTBEAT,
|
||||
NUM_PF
|
||||
};
|
||||
|
||||
extern unsigned int thecore_profiler[NUM_PF];
|
||||
|
||||
extern int thecore_init(int fps, HEARTFUNC heartbeat_func);
|
||||
extern int thecore_idle(void);
|
||||
extern void thecore_shutdown(void);
|
||||
extern void thecore_destroy(void);
|
||||
extern int thecore_pulse(void);
|
||||
extern float thecore_time(void);
|
||||
extern float thecore_pulse_per_second(void);
|
||||
extern int thecore_is_shutdowned(void);
|
||||
|
||||
extern void thecore_tick(void); // tics <20><><EFBFBD><EFBFBD>
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
16
src/libthecore/include/signals.h
Normal file
16
src/libthecore/include/signals.h
Normal file
@ -0,0 +1,16 @@
|
||||
#ifndef __INC_LIBTHECORE_SIGNAL_H__
|
||||
#define __INC_LIBTHECORE_SIGNAL_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
extern void signal_setup();
|
||||
extern void signal_timer_disable();
|
||||
extern void signal_timer_enable(int timeout_seconds);
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
42
src/libthecore/include/stdafx.h
Normal file
42
src/libthecore/include/stdafx.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef __INC_LIBTHECORE_STDAFX_H__
|
||||
#define __INC_LIBTHECORE_STDAFX_H__
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <cstdarg>
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <climits>
|
||||
#include <string>
|
||||
#include <dirent.h>
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
#include <sys/signal.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include <bsd/string.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include "typedef.h"
|
||||
#include "heart.h"
|
||||
#include "buffer.h"
|
||||
#include "signals.h"
|
||||
#include "log.h"
|
||||
#include "main.h"
|
||||
#include "utils.h"
|
||||
|
||||
#endif // __INC_LIBTHECORE_STDAFX_H__
|
58
src/libthecore/include/typedef.h
Normal file
58
src/libthecore/include/typedef.h
Normal file
@ -0,0 +1,58 @@
|
||||
#ifndef __INC_LIBTHECORE_TYPEDEF_H__
|
||||
#define __INC_LIBTHECORE_TYPEDEF_H__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
typedef uint64_t QWORD;
|
||||
typedef uint8_t UBYTE;
|
||||
typedef int8_t sbyte;
|
||||
typedef uint16_t sh_int;
|
||||
|
||||
#ifndef __WIN32__
|
||||
|
||||
typedef uint32_t DWORD;
|
||||
typedef uint32_t BOOL;
|
||||
typedef uint8_t BYTE;
|
||||
typedef uint16_t WORD;
|
||||
typedef int32_t LONG;
|
||||
typedef uint32_t ULONG;
|
||||
typedef int32_t INT;
|
||||
typedef uint32_t UINT;
|
||||
|
||||
#else
|
||||
|
||||
struct timezone
|
||||
{
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
typedef SOCKET socket_t;
|
||||
|
||||
#if !defined(_W64)
|
||||
#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
#define _W64 __w64
|
||||
#else
|
||||
#define _W64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _WIN64
|
||||
typedef __int64 ssize_t;
|
||||
#else
|
||||
typedef _W64 int ssize_t;
|
||||
#endif
|
||||
|
||||
// Fixed-size integer types
|
||||
#if defined(_MSC_VER) && (_MSC_VER >= 1300)
|
||||
typedef __int32 int32_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
#endif
|
||||
|
||||
typedef unsigned int uint;
|
||||
|
||||
#endif
|
||||
|
||||
#endif // __INC_LIBTHECORE_TYPEDEF_H__
|
127
src/libthecore/include/utils.h
Normal file
127
src/libthecore/include/utils.h
Normal file
@ -0,0 +1,127 @@
|
||||
#ifndef __INC_LIBTHECORE_UTILS_H__
|
||||
#define __INC_LIBTHECORE_UTILS_H__
|
||||
|
||||
// Random number generator
|
||||
#include "effolkronium/random.hpp"
|
||||
using Random = effolkronium::random_static;
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#define LOWER(c) (((c)>='A' && (c) <= 'Z') ? ((c)+('a'-'A')) : (c))
|
||||
#define UPPER(c) (((c)>='a' && (c) <= 'z') ? ((c)+('A'-'a')) : (c))
|
||||
|
||||
#define str_cmp strcasecmp
|
||||
|
||||
#define core_dump() core_dump_unix(__FILE__, __LINE__)
|
||||
extern void core_dump_unix(const char *who, WORD line); // <20>ھ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
#define TOKEN(string) if (!str_cmp(token_string, string))
|
||||
// src = <20><>ū : <20><>
|
||||
extern void parse_token(char * src, char * token, char * value);
|
||||
|
||||
extern void trim_and_lower(const char * src, char * dest, size_t dest_size);
|
||||
|
||||
// a<><61> b<><62> <20>ð<EFBFBD><C3B0><EFBFBD> <20><EFBFBD> <20><><EFBFBD>̳<EFBFBD><CCB3><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
extern struct timeval * timediff(const struct timeval *a, const struct timeval *b);
|
||||
|
||||
// a<><61> <20>ð<EFBFBD><C3B0><EFBFBD> b<><62> <20>ð<EFBFBD><C3B0><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
extern struct timeval * timeadd(struct timeval *a, struct timeval *b);
|
||||
|
||||
// <20><><EFBFBD><EFBFBD> <20>ð<EFBFBD> curr_tm<74><6D><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> days<79><73> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
extern struct tm * tm_calc(const struct tm *curr_tm, int days);
|
||||
|
||||
extern void thecore_sleep(struct timeval * timeout); // timeout<75><74>ŭ <20><><EFBFBD>μ<EFBFBD><CEBC><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
|
||||
extern float get_float_time();
|
||||
extern DWORD get_dword_time();
|
||||
|
||||
extern char * time_str(time_t ct);
|
||||
|
||||
std::string GetSocketHost(const sockaddr * address);
|
||||
in_port_t GetSocketPort(const sockaddr * address);
|
||||
|
||||
#define CREATE(result, type, number) do { \
|
||||
if (!((result) = (type *) calloc ((number), sizeof(type)))) { \
|
||||
sys_err("calloc failed [%d] %s", errno, strerror(errno)); \
|
||||
abort(); } } while(0)
|
||||
|
||||
#define RECREATE(result,type,number) do { \
|
||||
if (!((result) = (type *) realloc ((result), sizeof(type) * (number)))) { \
|
||||
sys_err("realloc failed [%d] %s", errno, strerror(errno)); \
|
||||
abort(); } } while(0)
|
||||
|
||||
// Next <20><> Prev <20><> <20>ִ<EFBFBD> <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20>߰<EFBFBD>
|
||||
#define INSERT_TO_TW_LIST(item, head, prev, next) \
|
||||
if (!(head)) \
|
||||
{ \
|
||||
head = item; \
|
||||
(head)->prev = (head)->next = NULL; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
(head)->prev = item; \
|
||||
(item)->next = head; \
|
||||
(item)->prev = NULL; \
|
||||
head = item; \
|
||||
}
|
||||
|
||||
#define REMOVE_FROM_TW_LIST(item, head, prev, next) \
|
||||
if ((item) == (head)) \
|
||||
{ \
|
||||
if (((head) = (item)->next)) \
|
||||
(head)->prev = NULL; \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
if ((item)->next) \
|
||||
(item)->next->prev = (item)->prev; \
|
||||
\
|
||||
if ((item)->prev) \
|
||||
(item)->prev->next = (item)->next; \
|
||||
}
|
||||
|
||||
|
||||
#define INSERT_TO_LIST(item, head, next) \
|
||||
(item)->next = (head); \
|
||||
(head) = (item); \
|
||||
|
||||
#define REMOVE_FROM_LIST(item, head, next) \
|
||||
if ((item) == (head)) \
|
||||
head = (item)->next; \
|
||||
else \
|
||||
{ \
|
||||
temp = head; \
|
||||
\
|
||||
while (temp && (temp->next != (item))) \
|
||||
temp = temp->next; \
|
||||
\
|
||||
if (temp) \
|
||||
temp->next = (item)->next; \
|
||||
} \
|
||||
|
||||
#ifndef MAKEFOURCC
|
||||
#define MAKEFOURCC(ch0, ch1, ch2, ch3) \
|
||||
((DWORD)(BYTE) (ch0 ) | ((DWORD)(BYTE) (ch1) << 8) | \
|
||||
((DWORD)(BYTE) (ch2) << 16) | ((DWORD)(BYTE) (ch3) << 24))
|
||||
#endif // defined(MAKEFOURCC)
|
||||
|
||||
|
||||
// _countof for gcc/g++
|
||||
#if !defined(_countof)
|
||||
#if !defined(__cplusplus)
|
||||
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
|
||||
#else
|
||||
extern "C++"
|
||||
{
|
||||
template <typename _CountofType, size_t _SizeOfArray>
|
||||
char (*__countof_helper(_CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray];
|
||||
#define _countof(_Array) sizeof(*__countof_helper(_Array))
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef __WIN32__
|
||||
extern void gettimeofday(struct timeval* t, struct timezone* dummy);
|
||||
#endif
|
||||
|
||||
#endif // __INC_UTILS_H__
|
Reference in New Issue
Block a user