summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/HPM.c4
-rw-r--r--src/common/HPM.h2
-rw-r--r--src/common/Makefile.in2
-rw-r--r--src/common/db.c2
-rw-r--r--src/common/db.h4
-rw-r--r--src/common/ers.h14
-rw-r--r--src/common/memmgr.c22
-rw-r--r--src/common/memmgr.h2
-rw-r--r--src/common/mmo.h25
-rw-r--r--src/common/mutex.h4
-rw-r--r--src/common/showmsg.c2
-rw-r--r--src/common/socket.c14
-rw-r--r--src/common/socket.h5
-rw-r--r--src/common/sql.h4
-rw-r--r--src/common/sysinfo.c2
-rw-r--r--src/common/utils.c43
-rw-r--r--src/common/utils.h3
17 files changed, 109 insertions, 45 deletions
diff --git a/src/common/HPM.c b/src/common/HPM.c
index 62ef54499..d9c3262d7 100644
--- a/src/common/HPM.c
+++ b/src/common/HPM.c
@@ -718,13 +718,13 @@ CPCMD(plugins)
* @retval 1 OK
* @retval 2 incomplete packet
*/
-unsigned char hplugins_parse_packets(int fd, enum HPluginPacketHookingPoints point)
+unsigned char hplugins_parse_packets(int fd, int packet_id, enum HPluginPacketHookingPoints point)
{
struct HPluginPacket *packet = NULL;
int i;
int16 length;
- ARR_FIND(0, VECTOR_LENGTH(HPM->packets[point]), i, VECTOR_INDEX(HPM->packets[point], i).cmd == RFIFOW(fd,0));
+ ARR_FIND(0, VECTOR_LENGTH(HPM->packets[point]), i, VECTOR_INDEX(HPM->packets[point], i).cmd == packet_id);
if (i == VECTOR_LENGTH(HPM->packets[point]))
return 0;
diff --git a/src/common/HPM.h b/src/common/HPM.h
index 215161a86..109549aad 100644
--- a/src/common/HPM.h
+++ b/src/common/HPM.h
@@ -157,7 +157,7 @@ struct HPM_interface {
void (*share) (void *value, const char *name);
void (*config_read) (void);
char *(*pid2name) (unsigned int pid);
- unsigned char (*parse_packets) (int fd, enum HPluginPacketHookingPoints point);
+ unsigned char (*parse_packets) (int fd, int packet_id, enum HPluginPacketHookingPoints point);
void (*load_sub) (struct hplugin *plugin);
bool (*addhook_sub) (enum HPluginHookType type, const char *target, void *hook, unsigned int pID);
/* for custom config parsing */
diff --git a/src/common/Makefile.in b/src/common/Makefile.in
index df3ecaf2d..9d4b2d044 100644
--- a/src/common/Makefile.in
+++ b/src/common/Makefile.in
@@ -135,7 +135,7 @@ obj_all/sysinfo.o: sysinfo.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_
obj_all/%.o: %.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_all
@echo " CC $<"
- @$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @PCRE_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
+ @$(CC) @CFLAGS@ @DEFS@ $(COMMON_INCLUDE) $(THIRDPARTY_INCLUDE) @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
obj_all/mini%.o: %.c $(COMMON_H) $(CONFIG_H) $(MT19937AR_H) $(LIBCONFIG_H) | $(SYSINFO_INC) obj_all
@echo " CC $<"
diff --git a/src/common/db.c b/src/common/db.c
index 361e212cb..ca9a70f7c 100644
--- a/src/common/db.c
+++ b/src/common/db.c
@@ -353,7 +353,7 @@ static struct db_stats {
};
#define DB_COUNTSTAT(token) do { if ((stats.token) != UINT32_MAX) ++(stats.token); } while(0)
#else /* !defined(DB_ENABLE_STATS) */
-#define DB_COUNTSTAT(token)
+#define DB_COUNTSTAT(token) (void)0
#endif /* !defined(DB_ENABLE_STATS) */
/* [Ind/Hercules] */
diff --git a/src/common/db.h b/src/common/db.h
index 205288f13..b73970947 100644
--- a/src/common/db.h
+++ b/src/common/db.h
@@ -1717,7 +1717,7 @@ HPShared struct db_interface *DB;
* @return negative if v1 is top, positive if v2 is top, 0 if equal.
*/
#define BHEAP_MINTOPCMP(v1, v2) \
- ( v1 == v2 ? 0 : v1 < v2 ? -1 : 1 )
+ ( (v1) == (v2) ? 0 : (v1) < (v2) ? -1 : 1 )
/**
* Generic comparator for a max-heap (maximum value at top).
@@ -1732,6 +1732,6 @@ HPShared struct db_interface *DB;
* @return negative if v1 is top, positive if v2 is top, 0 if equal.
*/
#define BHEAP_MAXTOPCMP(v1, v2) \
- ( v1 == v2 ? 0 : v1 > v2 ? -1 : 1 )
+ ( (v1) == (v2) ? 0 : (v1) > (v2) ? -1 : 1 )
#endif /* COMMON_DB_H */
diff --git a/src/common/ers.h b/src/common/ers.h
index 938882edd..1689345dc 100644
--- a/src/common/ers.h
+++ b/src/common/ers.h
@@ -148,15 +148,15 @@ typedef struct eri {
#ifdef DISABLE_ERS
// Use memory manager to allocate/free and disable other interface functions
-# define ers_alloc(obj,type) (type *)aMalloc(sizeof(type))
-# define ers_free(obj,entry) aFree(entry)
-# define ers_entry_size(obj) (size_t)0
-# define ers_destroy(obj)
-# define ers_chunk_size(obj,size)
+# define ers_alloc(obj,type) ((void)(obj), (type *)aMalloc(sizeof(type)))
+# define ers_free(obj,entry) ((void)(obj), aFree(entry))
+# define ers_entry_size(obj) ((void)(obj), (size_t)0)
+# define ers_destroy(obj) ((void)(obj), (void)0)
+# define ers_chunk_size(obj,size) ((void)(obj), (void)(size), (size_t)0)
// Disable the public functions
# define ers_new(size,name,options) NULL
-# define ers_report()
-# define ers_final()
+# define ers_report() (void)0
+# define ers_final() (void)0
#else /* not DISABLE_ERS */
// These defines should be used to allow the code to keep working whenever
// the system is disabled
diff --git a/src/common/memmgr.c b/src/common/memmgr.c
index 97991ceaa..93c23ff18 100644
--- a/src/common/memmgr.c
+++ b/src/common/memmgr.c
@@ -45,7 +45,7 @@ struct malloc_interface *iMalloc;
# define REALLOC(p,n,file,line,func) mwRealloc((p),(n),(file),(line))
# define STRDUP(p,file,line,func) mwStrdup((p),(file),(line))
# define FREE(p,file,line,func) mwFree((p),(file),(line))
-# define MEMORY_USAGE() (size_t)0
+# define MEMORY_USAGE() ((size_t)0)
# define MEMORY_VERIFY(ptr) mwIsSafeAddr((ptr), 1)
# define MEMORY_CHECK() CHECK()
@@ -67,21 +67,21 @@ struct malloc_interface *iMalloc;
# include <gc.h>
# ifdef GC_ADD_CALLER
-# define RETURN_ADDR 0,
+# define MALLOC(n,file,line,func) GC_debug_malloc((n), 0, (file), (line))
+# define CALLOC(m,n,file,line,func) GC_debug_malloc((m)*(n), 0, (file), (line))
+# define REALLOC(p,n,file,line,func) GC_debug_realloc((p),(n), 0, (file), (line))
+# define STRDUP(p,file,line,func) GC_debug_strdup((p), 0, (file), (line))
# else
-# define RETURN_ADDR
+# define MALLOC(n,file,line,func) GC_debug_malloc((n), (file), (line))
+# define CALLOC(m,n,file,line,func) GC_debug_malloc((m)*(n), (file), (line))
+# define REALLOC(p,n,file,line,func) GC_debug_realloc((p),(n), (file), (line))
+# define STRDUP(p,file,line,func) GC_debug_strdup((p), (file), (line))
# endif
-# define MALLOC(n,file,line,func) GC_debug_malloc((n), RETURN_ADDR (file),(line))
-# define CALLOC(m,n,file,line,func) GC_debug_malloc((m)*(n), RETURN_ADDR (file),(line))
-# define REALLOC(p,n,file,line,func) GC_debug_realloc((p),(n), RETURN_ADDR (file),(line))
-# define STRDUP(p,file,line,func) GC_debug_strdup((p), RETURN_ADDR (file),(line))
# define FREE(p,file,line,func) GC_debug_free(p)
# define MEMORY_USAGE() GC_get_heap_size()
# define MEMORY_VERIFY(ptr) (GC_base(ptr) != NULL)
# define MEMORY_CHECK() GC_gcollect()
-# undef RETURN_ADDR
-
#else
# define MALLOC(n,file,line,func) malloc(n)
@@ -89,9 +89,9 @@ struct malloc_interface *iMalloc;
# define REALLOC(p,n,file,line,func) realloc((p),(n))
# define STRDUP(p,file,line,func) strdup(p)
# define FREE(p,file,line,func) free(p)
-# define MEMORY_USAGE() (size_t)0
+# define MEMORY_USAGE() ((size_t)0)
# define MEMORY_VERIFY(ptr) true
-# define MEMORY_CHECK()
+# define MEMORY_CHECK() (void)0
#endif
diff --git a/src/common/memmgr.h b/src/common/memmgr.h
index 4b06ae56e..5975f55c4 100644
--- a/src/common/memmgr.h
+++ b/src/common/memmgr.h
@@ -60,7 +60,7 @@
#ifdef __GNUC__ // GCC has variable length arrays
#define CREATE_BUFFER(name, type, size) type name[size]
-#define DELETE_BUFFER(name)
+#define DELETE_BUFFER(name) (void)0
#else // others don't, so we emulate them
diff --git a/src/common/mmo.h b/src/common/mmo.h
index eb1d7cc8e..981c1b30b 100644
--- a/src/common/mmo.h
+++ b/src/common/mmo.h
@@ -98,13 +98,19 @@
#endif // 20090603
#endif // 20070227
-/* Feb 1st 2012 */
-#if PACKETVER >= 20120201
-# define NEW_CARTS
-# define MAX_CARTS 9
+#if PACKETVER >= 20150805 /* Cart Decoration */
+ #define CART_DECORATION
+ #define MAX_CARTDECORATION_CARTS 3 // Currently there are 3 Carts available in kRO. [Frost]
#else
-# define MAX_CARTS 5
+ #define MAX_CARTDECORATION_CARTS 0
#endif
+#if PACKETVER >= 20120201 /* New Geneticist Carts */
+ #define NEW_CARTS
+ #define MAX_BASE_CARTS 9
+#else
+ #define MAX_BASE_CARTS 5
+#endif
+#define MAX_CARTS (MAX_BASE_CARTS + MAX_CARTDECORATION_CARTS)
#define MAX_INVENTORY 100
//Max number of characters per account. Note that changing this setting alone is not enough if the client is not hexed to support more characters as well.
@@ -207,6 +213,11 @@
#define JOBL_BABY 0x2000 //8192
#define JOBL_THIRD 0x4000 //16384
+//Packet DB
+#define MIN_PACKET_DB 0x0064 //what's the point of minimum packet id ? [hemagx]
+#define MAX_PACKET_DB 0x0F00
+#define MAX_PACKET_POS 20
+
#define SCRIPT_VARNAME_LENGTH 32 ///< Maximum length of a script variable
struct hplugin_data_store;
@@ -262,6 +273,7 @@ struct item {
//Equip position constants
enum equip_pos {
+ EQP_NONE = 0x000000,
EQP_HEAD_LOW = 0x000001,
EQP_HEAD_MID = 0x000200, //512
EQP_HEAD_TOP = 0x000100, //256
@@ -742,7 +754,8 @@ enum { //Change Member Infos
enum guild_permission { // Guild permissions
GPERM_INVITE = 0x01,
GPERM_EXPEL = 0x10,
- GPERM_BOTH = GPERM_INVITE|GPERM_EXPEL,
+ GPERM_ALL = GPERM_INVITE|GPERM_EXPEL,
+ GPERM_MASK = GPERM_ALL,
};
enum {
diff --git a/src/common/mutex.h b/src/common/mutex.h
index 5127d9f4b..e49791493 100644
--- a/src/common/mutex.h
+++ b/src/common/mutex.h
@@ -32,7 +32,7 @@ typedef struct racond racond; // Condition Var
*
* @return not NULL
*/
-ramutex *ramutex_create();
+ramutex *ramutex_create(void);
/**
* Destroys a Mutex
@@ -70,7 +70,7 @@ void ramutex_unlock(ramutex *m);
*
* @return not NULL
*/
-racond *racond_create();
+racond *racond_create(void);
/**
* Destroy a Condition variable
diff --git a/src/common/showmsg.c b/src/common/showmsg.c
index e60b9f536..956222a7d 100644
--- a/src/common/showmsg.c
+++ b/src/common/showmsg.c
@@ -478,7 +478,7 @@ int FPRINTF(HANDLE handle, const char *fmt, ...) {
return ret;
}
-#define FFLUSH(handle)
+#define FFLUSH(handle) (void)(handle)
#define STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
#define STDERR GetStdHandle(STD_ERROR_HANDLE)
diff --git a/src/common/socket.c b/src/common/socket.c
index f67c3d074..740c07bdc 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -76,11 +76,11 @@ struct socket_interface *sockt;
struct socket_data **session;
#ifdef SEND_SHORTLIST
- // Add a fd to the shortlist so that it'll be recognized as a fd that needs
- // sending done on it.
- void send_shortlist_add_fd(int fd);
- // Do pending network sends (and eof handling) from the shortlist.
- void send_shortlist_do_sends();
+// Add a fd to the shortlist so that it'll be recognized as a fd that needs
+// sending done on it.
+void send_shortlist_add_fd(int fd);
+// Do pending network sends (and eof handling) from the shortlist.
+void send_shortlist_do_sends(void);
#endif
/////////////////////////////////////////////////////////////////////
@@ -1103,7 +1103,7 @@ static int connect_check_clear(int tid, int64 tick, int id, intptr_t data) {
clear++;
}
list++;
- }
+ }
dbi_destroy(iter);
if( access_debug ){
@@ -1570,7 +1570,7 @@ void send_shortlist_add_fd(int fd)
}
// Do pending network sends and eof handling from the shortlist.
-void send_shortlist_do_sends()
+void send_shortlist_do_sends(void)
{
int i;
diff --git a/src/common/socket.h b/src/common/socket.h
index b33fd2acf..8936c7772 100644
--- a/src/common/socket.h
+++ b/src/common/socket.h
@@ -77,6 +77,11 @@ struct hplugin_data_store;
/* [Ind/Hercules] */
#define RFIFO2PTR(fd) (void*)(sockt->session[fd]->rdata + sockt->session[fd]->rdata_pos)
+#define RP2PTR(fd) RFIFO2PTR(fd)
+
+/* [Hemagx/Hercules] */
+#define WFIFO2PTR(fd) (void*)(sockt->session[fd]->wdata + sockt->session[fd]->wdata_pos)
+#define WP2PTR(fd) WFIFO2PTR(fd)
// buffer I/O macros
#define RBUFP(p,pos) (((uint8*)(p)) + (pos))
diff --git a/src/common/sql.h b/src/common/sql.h
index 33643407d..e949a8280 100644
--- a/src/common/sql.h
+++ b/src/common/sql.h
@@ -272,13 +272,13 @@ void Sql_HerculesUpdateSkip(Sql* self,const char *filename);
HPShared struct sql_interface *SQL;
#if defined(SQL_REMOVE_SHOWDEBUG)
-#define Sql_ShowDebug(self) (void)0
+#define Sql_ShowDebug(self) (void)(self)
#else
#define Sql_ShowDebug(self) (SQL->ShowDebug_((self), __FILE__, __LINE__))
#endif
#if defined(SQL_REMOVE_SHOWDEBUG)
-#define SqlStmt_ShowDebug(self) (void)0
+#define SqlStmt_ShowDebug(self) (void)(self)
#else
/// Shows debug information (with statement).
#define SqlStmt_ShowDebug(self) (SQL->StmtShowDebug_((self), __FILE__, __LINE__))
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c
index dbedfa2db..7cc4cd16a 100644
--- a/src/common/sysinfo.c
+++ b/src/common/sysinfo.c
@@ -65,7 +65,7 @@ struct sysinfo_interface *sysinfo;
#define VCSTYPE_UNKNOWN 0
#define VCSTYPE_GIT 1
#define VCSTYPE_SVN 2
-#define VCSTYPE_NONE -1
+#define VCSTYPE_NONE (-1)
#ifdef WIN32
/**
diff --git a/src/common/utils.c b/src/common/utils.c
index dcf0a749a..73df3aae1 100644
--- a/src/common/utils.c
+++ b/src/common/utils.c
@@ -25,6 +25,7 @@
#include "common/cbasetypes.h"
#include "common/core.h"
#include "common/mmo.h"
+#include "common/nullpo.h"
#include "common/showmsg.h"
#include "common/socket.h"
#include "common/strlib.h"
@@ -352,6 +353,48 @@ unsigned int get_percentage(const unsigned int A, const unsigned int B)
return (unsigned int)floor(result);
}
+/**
+ * Applies a percentual rate modifier.
+ *
+ * @param value The base value.
+ * @param rate The rate modifier to apply.
+ * @param stdrate The rate modifier's divider (rate == stdrate => 100%).
+ * @return The modified value.
+ */
+int64 apply_percentrate64(int64 value, int rate, int stdrate)
+{
+ Assert_ret(stdrate > 0);
+ Assert_ret(rate >= 0);
+ if (rate == stdrate)
+ return value;
+ if (rate == 0)
+ return 0;
+ if (INT64_MAX / rate < value) {
+ // Give up some precision to prevent overflows
+ return value / stdrate * rate;
+ }
+ return value * rate / stdrate;
+}
+
+/**
+ * Applies a percentual rate modifier.
+ *
+ * @param value The base value.
+ * @param rate The rate modifier to apply. Must be <= maxrate.
+ * @param maxrate The rate modifier's divider (maxrate = 100%).
+ * @return The modified value.
+ */
+int apply_percentrate(int value, int rate, int maxrate)
+{
+ Assert_ret(maxrate > 0);
+ Assert_ret(rate >= 0);
+ if (rate == maxrate)
+ return value;
+ if (rate == 0)
+ return 0;
+ return (int)(value * (int64)rate / maxrate);
+}
+
//-----------------------------------------------------
// custom timestamp formatting (from eApp)
//-----------------------------------------------------
diff --git a/src/common/utils.h b/src/common/utils.h
index da2a29317..3f181ef12 100644
--- a/src/common/utils.h
+++ b/src/common/utils.h
@@ -42,6 +42,9 @@ bool exists(const char* filename);
/// calculates the value of A / B, in percent (rounded down)
unsigned int get_percentage(const unsigned int A, const unsigned int B);
+int64 apply_percentrate64(int64 value, int rate, int maxrate);
+int apply_percentrate(int value, int rate, int maxrate);
+
const char* timestamp2string(char* str, size_t size, time_t timestamp, const char* format);
//////////////////////////////////////////////////////////////////////////