Merge pull request #240 from RElesgoe/master
Use standard typedefs and fix format specifiers
This commit is contained in:
commit
b9beb3b495
37 changed files with 549 additions and 895 deletions
ConfigureChecks.cmake
cmake/Modules
config.h.cmakesrc
bnetd
anongame.cppanongame.hcharacter.cppcharacter.hclan.cpphandle_bnet.cpphandle_wol.cpphandle_wol_gameres.cpphandle_wol_gameres.hipban.cppirc.cppluainterface.cpp
bniutils
bntrackd
common
asnprintf.cppbigint.cppbigint.hbn_type.cppbn_type.hbnethash.cppbnethash.hbnetsrp3.cppfdwatch_epoll.htag.hwolhash.h
compat
test
|
@ -11,7 +11,6 @@ include(DefineInstallationPaths)
|
|||
include(CheckIncludeFileCXX)
|
||||
include(CheckFunctionExists)
|
||||
include(CheckSymbolExists)
|
||||
include(CheckTypeSize)
|
||||
include(CheckLibraryExists)
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckCXXSourceCompiles)
|
||||
|
@ -136,19 +135,6 @@ check_include_file_cxx(ndir.h HAVE_NDIR_H)
|
|||
check_include_file_cxx(sys/dir.h HAVE_SYS_DIR_H)
|
||||
check_include_file_cxx(sys/ndir.h HAVE_SYS_NDIR_H)
|
||||
check_include_file_cxx(sys/poll.h HAVE_SYS_POLL_H)
|
||||
#Keep for now
|
||||
check_include_file_cxx(stdint.h HAVE_STDINT_H)
|
||||
|
||||
check_type_size("unsigned char" SIZEOF_UNSIGNED_CHAR)
|
||||
check_type_size("unsigned short" SIZEOF_UNSIGNED_SHORT)
|
||||
check_type_size("unsigned int" SIZEOF_UNSIGNED_INT)
|
||||
check_type_size("unsigned long" SIZEOF_UNSIGNED_LONG)
|
||||
check_type_size("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
|
||||
check_type_size("signed char" SIZEOF_SIGNED_CHAR)
|
||||
check_type_size("signed short" SIZEOF_SIGNED_SHORT)
|
||||
check_type_size("signed int" SIZEOF_SIGNED_INT)
|
||||
check_type_size("signed long" SIZEOF_SIGNED_LONG)
|
||||
check_type_size("signed long long" SIZEOF_SIGNED_LONG_LONG)
|
||||
|
||||
check_function_exists(chdir HAVE_CHDIR)
|
||||
check_function_exists(epoll_create HAVE_EPOLL_CREATE)
|
||||
|
|
|
@ -1,68 +0,0 @@
|
|||
# - Check sizeof a type
|
||||
# CHECK_TYPE_SIZE_CXX(TYPE VARIABLE)
|
||||
# Check if the type exists and determine size of type. if the type
|
||||
# exists, the size will be stored to the variable.
|
||||
# VARIABLE - variable to store size if the type exists.
|
||||
# HAVE_${VARIABLE} - does the variable exists or not
|
||||
# The following variables may be set before calling this macro to
|
||||
# modify the way the check is run:
|
||||
#
|
||||
# CMAKE_REQUIRED_FLAGS = string of compile command line flags
|
||||
# CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
|
||||
# CMAKE_REQUIRED_INCLUDES = list of include directories
|
||||
# CMAKE_REQUIRED_LIBRARIES = list of libraries to link
|
||||
|
||||
MACRO(CHECK_TYPE_SIZE_CXX TYPE VARIABLE)
|
||||
SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS 1)
|
||||
IF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
|
||||
SET(CHECK_TYPE_SIZE_CXX_TYPE "${TYPE}")
|
||||
SET(MACRO_CHECK_TYPE_CXX_SIZE_FLAGS
|
||||
"${CMAKE_REQUIRED_FLAGS}")
|
||||
FOREACH(def HAVE_SYS_TYPES_H HAVE_STDINT_H HAVE_STDDEF_H)
|
||||
IF("${def}")
|
||||
SET(MACRO_CHECK_TYPE_SIZE_CXX_FLAGS
|
||||
"${MACRO_CHECK_TYPE_SIZE_CXX_FLAGS} -D${def}")
|
||||
ENDIF("${def}")
|
||||
ENDFOREACH(def)
|
||||
SET(CHECK_TYPE_SIZE_CXX_PREINCLUDE)
|
||||
SET(CHECK_TYPE_SIZE_CXX_PREMAIN)
|
||||
FOREACH(def ${CMAKE_EXTRA_INCLUDE_FILES})
|
||||
SET(CHECK_TYPE_SIZE_CXX_PREMAIN "${CHECK_TYPE_SIZE_CXX_PREMAIN}#include \"${def}\"\n")
|
||||
ENDFOREACH(def)
|
||||
CONFIGURE_FILE("${CMAKE_MODULE_PATH}/CheckTypeSizeCXX.cxx.in"
|
||||
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckTypeSizeCXX.cxx" IMMEDIATE @ONLY)
|
||||
FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckTypeSizeCXX.cxx"
|
||||
CHECK_TYPE_SIZE_CXX_FILE_CONTENT)
|
||||
MESSAGE(STATUS "Check size of ${TYPE}")
|
||||
IF(CMAKE_REQUIRED_LIBRARIES)
|
||||
SET(CHECK_TYPE_SIZE_CXX_ADD_LIBRARIES
|
||||
"-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
|
||||
ELSE(CMAKE_REQUIRED_LIBRARIES)
|
||||
SET(CHECK_TYPE_SIZE_CXX_ADD_LIBRARIES)
|
||||
ENDIF(CMAKE_REQUIRED_LIBRARIES)
|
||||
IF(CMAKE_REQUIRED_INCLUDES)
|
||||
SET(CHECK_TYPE_SIZE_CXX_ADD_INCLUDES
|
||||
"-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
|
||||
ELSE(CMAKE_REQUIRED_INCLUDES)
|
||||
SET(CHECK_TYPE_SIZE_CXX_ADD_INCLUDES)
|
||||
ENDIF(CMAKE_REQUIRED_INCLUDES)
|
||||
TRY_RUN(${VARIABLE} HAVE_${VARIABLE}
|
||||
${CMAKE_BINARY_DIR}
|
||||
"${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckTypeSizeCXX.cxx"
|
||||
COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
|
||||
CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_TYPE_SIZE_CXX_FLAGS}
|
||||
"${CHECK_TYPE_SIZE_CXX_ADD_LIBRARIES}"
|
||||
"${CHECK_TYPE_SIZE_CXX_ADD_INCLUDES}"
|
||||
OUTPUT_VARIABLE OUTPUT)
|
||||
IF(HAVE_${VARIABLE})
|
||||
MESSAGE(STATUS "Check size of ${TYPE} - done")
|
||||
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
||||
"Determining size of ${TYPE} passed with the following output:\n${OUTPUT}\n\n")
|
||||
ELSE(HAVE_${VARIABLE})
|
||||
MESSAGE(STATUS "Check size of ${TYPE} - failed")
|
||||
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
||||
"Determining size of ${TYPE} failed with the following output:\n${OUTPUT}\nCheckTypeSizeCXX.cxx:\n${CHECK_TYPE_SIZE_CXX_FILE_CONTENT}\n\n")
|
||||
ENDIF(HAVE_${VARIABLE})
|
||||
ENDIF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
|
||||
SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS )
|
||||
ENDMACRO(CHECK_TYPE_SIZE_CXX)
|
|
@ -1,28 +0,0 @@
|
|||
#cmakedefine CHECK_TYPE_SIZE_CXX_TYPE @CHECK_TYPE_SIZE_CXX_TYPE@
|
||||
#ifdef CHECK_TYPE_SIZE_CXX_TYPE
|
||||
|
||||
@CHECK_TYPE_SIZE_CXX_PREINCLUDE@
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif /* HAVE_SYS_TYPES_H */
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#endif /* HAVE_STDINT_H */
|
||||
|
||||
#ifdef HAVE_STDDEF_H
|
||||
# include <stddef.h>
|
||||
#endif /* HAVE_STDDEF_H */
|
||||
|
||||
@CHECK_TYPE_SIZE_CXX_PREMAIN@
|
||||
|
||||
int main(int ac, char*av[]){
|
||||
if(ac > 1000){return *av[0];}
|
||||
return sizeof(CHECK_TYPE_SIZE_CXX_TYPE);
|
||||
}
|
||||
|
||||
#else /* CHECK_TYPE_SIZE_CXX_TYPE */
|
||||
|
||||
# error "CHECK_TYPE_SIZE_CXX_TYPE has to specify the type"
|
||||
|
||||
#endif /* CHECK_TYPE_SIZE_CXX_TYPE */
|
|
@ -15,7 +15,6 @@
|
|||
#cmakedefine HAVE_TERMIOS_H
|
||||
#cmakedefine HAVE_SYS_TYPES_H
|
||||
#cmakedefine HAVE_SYS_WAIT_H
|
||||
#cmakedefine HAVE_STDINT_H
|
||||
#cmakedefine HAVE_SYS_FILE_H
|
||||
#cmakedefine HAVE_POLL_H
|
||||
#cmakedefine HAVE_SYS_POLL_H
|
||||
|
@ -37,17 +36,6 @@
|
|||
#cmakedefine HAVE_WS2TCPIP_H
|
||||
#cmakedefine HAVE_PROCESS_H
|
||||
|
||||
#cmakedefine SIZEOF_UNSIGNED_CHAR ${SIZEOF_UNSIGNED_CHAR}
|
||||
#cmakedefine SIZEOF_UNSIGNED_SHORT ${SIZEOF_UNSIGNED_SHORT}
|
||||
#cmakedefine SIZEOF_UNSIGNED_INT ${SIZEOF_UNSIGNED_INT}
|
||||
#cmakedefine SIZEOF_UNSIGNED_LONG ${SIZEOF_UNSIGNED_LONG}
|
||||
#cmakedefine SIZEOF_UNSIGNED_LONG_LONG ${SIZEOF_UNSIGNED_LONG_LONG}
|
||||
#cmakedefine SIZEOF_SIGNED_CHAR ${SIZEOF_SIGNED_CHAR}
|
||||
#cmakedefine SIZEOF_SIGNED_SHORT ${SIZEOF_SIGNED_SHORT}
|
||||
#cmakedefine SIZEOF_SIGNED_INT ${SIZEOF_SIGNED_INT}
|
||||
#cmakedefine SIZEOF_SIGNED_LONG ${SIZEOF_SIGNED_LONG}
|
||||
#cmakedefine SIZEOF_SIGNED_LONG_LONG ${SIZEOF_SIGNED_LONG_LONG}
|
||||
|
||||
#cmakedefine HAVE_CHDIR
|
||||
#cmakedefine HAVE_EPOLL_CREATE
|
||||
#cmakedefine HAVE_FORK
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "anongame.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "compat/strdup.h"
|
||||
#include "common/packet.h"
|
||||
|
@ -75,14 +76,14 @@ namespace pvpgn
|
|||
|
||||
static int _anongame_gametype_to_queue(int type, int gametype);
|
||||
static int _anongame_level_by_queue(t_connection * c, int queue);
|
||||
static const char * _get_map_from_prefs(int queue, t_uint32 cur_prefs, t_clienttag clienttag);
|
||||
static const char * _get_map_from_prefs(int queue, std::uint32_t cur_prefs, t_clienttag clienttag);
|
||||
static unsigned int _anongame_get_gametype_tab(int queue);
|
||||
|
||||
static int _anongame_totalplayers(int queue);
|
||||
static int _anongame_totalteams(int queue);
|
||||
|
||||
static int _handle_anongame_search(t_connection * c, t_packet const *packet);
|
||||
static int _anongame_queue(t_connection * c, int queue, t_uint32 map_prefs);
|
||||
static int _anongame_queue(t_connection * c, int queue, std::uint32_t map_prefs);
|
||||
static int _anongame_compare_level(void const *a, void const *b);
|
||||
static int _anongame_order_queue(int queue);
|
||||
static int _anongame_match(t_connection * c, int queue);
|
||||
|
@ -235,7 +236,7 @@ namespace pvpgn
|
|||
}
|
||||
}
|
||||
|
||||
static const char * _get_map_from_prefs(int queue, t_uint32 cur_prefs, t_clienttag clienttag)
|
||||
static const char * _get_map_from_prefs(int queue, std::uint32_t cur_prefs, t_clienttag clienttag)
|
||||
{
|
||||
int i, j = 0;
|
||||
const char *default_map, *selected;
|
||||
|
@ -386,8 +387,8 @@ namespace pvpgn
|
|||
t_packet *rpacket;
|
||||
t_connection *tc[6];
|
||||
t_anongame *a, *ta;
|
||||
t_uint8 teamsize = 0;
|
||||
t_uint8 option = bn_byte_get(packet->u.client_findanongame.option);
|
||||
std::uint8_t teamsize = 0;
|
||||
std::uint8_t option = bn_byte_get(packet->u.client_findanongame.option);
|
||||
|
||||
if (!(a = conn_get_anongame(c))) {
|
||||
if (!(a = conn_create_anongame(c))) {
|
||||
|
@ -518,7 +519,7 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int _anongame_queue(t_connection * c, int queue, t_uint32 map_prefs)
|
||||
static int _anongame_queue(t_connection * c, int queue, std::uint32_t map_prefs)
|
||||
{
|
||||
int level;
|
||||
t_matchdata *md;
|
||||
|
@ -815,7 +816,7 @@ namespace pvpgn
|
|||
t_elem *curr;
|
||||
int diff;
|
||||
t_anongame *a = conn_get_anongame(c);
|
||||
t_uint32 cur_prefs = a->map_prefs;
|
||||
std::uint32_t cur_prefs = a->map_prefs;
|
||||
t_connection *inv_c[ANONGAME_MAX_TEAMS];
|
||||
int maxlevel, minlevel;
|
||||
int teams = 0;
|
||||
|
@ -1173,8 +1174,8 @@ namespace pvpgn
|
|||
t_anongame *a = conn_get_anongame(gamec);
|
||||
int tp = anongame_get_totalplayers(a);
|
||||
int oppon_level[ANONGAME_MAX_GAMECOUNT];
|
||||
t_uint8 gametype = a->queue;
|
||||
t_uint8 plnum = a->playernum;
|
||||
std::uint8_t gametype = a->queue;
|
||||
std::uint8_t plnum = a->playernum;
|
||||
t_clienttag ct = conn_get_clienttag(c);
|
||||
int tt = _anongame_totalteams(gametype);
|
||||
|
||||
|
@ -1440,7 +1441,7 @@ namespace pvpgn
|
|||
return a->count;
|
||||
}
|
||||
|
||||
extern t_uint32 anongame_get_id(t_anongame * a)
|
||||
extern std::uint32_t anongame_get_id(t_anongame * a)
|
||||
{
|
||||
if (!a) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL anongame");
|
||||
|
@ -1458,7 +1459,7 @@ namespace pvpgn
|
|||
return a->tc[tpnumber];
|
||||
}
|
||||
|
||||
extern t_uint32 anongame_get_race(t_anongame * a)
|
||||
extern std::uint32_t anongame_get_race(t_anongame * a)
|
||||
{
|
||||
if (!a) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL anongame");
|
||||
|
@ -1467,7 +1468,7 @@ namespace pvpgn
|
|||
return a->race;
|
||||
}
|
||||
|
||||
extern t_uint32 anongame_get_handle(t_anongame * a)
|
||||
extern std::uint32_t anongame_get_handle(t_anongame * a)
|
||||
{
|
||||
if (!a) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL anongame");
|
||||
|
@ -1503,7 +1504,7 @@ namespace pvpgn
|
|||
return a->joined;
|
||||
}
|
||||
|
||||
extern t_uint8 anongame_get_playernum(t_anongame * a)
|
||||
extern std::uint8_t anongame_get_playernum(t_anongame * a)
|
||||
{
|
||||
if (!a) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL anongame");
|
||||
|
@ -1512,7 +1513,7 @@ namespace pvpgn
|
|||
return a->playernum;
|
||||
}
|
||||
|
||||
extern t_uint8 anongame_get_queue(t_anongame * a)
|
||||
extern std::uint8_t anongame_get_queue(t_anongame * a)
|
||||
{
|
||||
if (!a) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL anongame");
|
||||
|
@ -1560,7 +1561,7 @@ namespace pvpgn
|
|||
a->info->results[a->playernum - 1] = results;
|
||||
}
|
||||
|
||||
extern void anongame_set_handle(t_anongame * a, t_uint32 h)
|
||||
extern void anongame_set_handle(t_anongame * a, std::uint32_t h)
|
||||
{
|
||||
if (!a) {
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL anongame");
|
||||
|
@ -1617,7 +1618,7 @@ namespace pvpgn
|
|||
t_connection *gamec;
|
||||
char const *username;
|
||||
t_anongame *a = NULL;
|
||||
t_uint8 gametype, plnum;
|
||||
std::uint8_t gametype, plnum;
|
||||
int tp, i;
|
||||
|
||||
if (!c) {
|
||||
|
|
|
@ -16,15 +16,15 @@
|
|||
#ifndef INCLUDED_ANONGAME_TYPES
|
||||
#define INCLUDED_ANONGAME_TYPES
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#ifdef JUST_NEED_TYPES
|
||||
# include "account.h"
|
||||
# include "connection.h"
|
||||
# include "compat/uint.h"
|
||||
#else
|
||||
# define JUST_NEED_TYPES
|
||||
# include "account.h"
|
||||
# include "connection.h"
|
||||
# include "compat/uint.h"
|
||||
# undef JUST_NEED_TYPES
|
||||
#endif
|
||||
# include "anongame_gameresult.h"
|
||||
|
@ -49,25 +49,25 @@ namespace pvpgn
|
|||
{
|
||||
t_anongameinfo * info;
|
||||
int count;
|
||||
t_uint32 id;
|
||||
t_uint32 tid;
|
||||
std::uint32_t id;
|
||||
std::uint32_t tid;
|
||||
struct connection * tc[ANONGAME_MAX_GAMECOUNT / 2];
|
||||
t_uint32 race;
|
||||
t_uint32 handle;
|
||||
std::uint32_t race;
|
||||
std::uint32_t handle;
|
||||
unsigned int addr;
|
||||
char loaded;
|
||||
char joined;
|
||||
t_uint8 playernum;
|
||||
t_uint32 map_prefs;
|
||||
t_uint8 type;
|
||||
t_uint8 gametype;
|
||||
std::uint8_t playernum;
|
||||
std::uint32_t map_prefs;
|
||||
std::uint8_t type;
|
||||
std::uint8_t gametype;
|
||||
int queue;
|
||||
} t_anongame;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
struct connection * c;
|
||||
t_uint32 map_prefs;
|
||||
std::uint32_t map_prefs;
|
||||
char const * versiontag;
|
||||
} t_matchdata;
|
||||
|
||||
|
@ -110,19 +110,19 @@ namespace pvpgn
|
|||
extern int anongame_get_totalplayers(t_anongame *a);
|
||||
extern t_connection * anongame_get_player(t_anongame * a, int plnum);
|
||||
extern int anongame_get_count(t_anongame *a);
|
||||
extern t_uint32 anongame_get_id(t_anongame * a);
|
||||
extern std::uint32_t anongame_get_id(t_anongame * a);
|
||||
extern t_connection * anongame_get_tc(t_anongame *a, int tpnumber);
|
||||
extern t_uint32 anongame_get_race(t_anongame * a);
|
||||
extern t_uint32 anongame_get_handle(t_anongame * a);
|
||||
extern std::uint32_t anongame_get_race(t_anongame * a);
|
||||
extern std::uint32_t anongame_get_handle(t_anongame * a);
|
||||
extern unsigned int anongame_get_addr(t_anongame * a);
|
||||
extern char anongame_get_loaded(t_anongame * a);
|
||||
extern char anongame_get_joined(t_anongame * a);
|
||||
extern t_uint8 anongame_get_playernum(t_anongame * a);
|
||||
extern t_uint8 anongame_get_queue(t_anongame *a);
|
||||
extern std::uint8_t anongame_get_playernum(t_anongame * a);
|
||||
extern std::uint8_t anongame_get_queue(t_anongame *a);
|
||||
|
||||
extern void anongame_set_result(t_anongame * a, int result);
|
||||
extern void anongame_set_gameresults(t_anongame * a, t_anongame_gameresult * results);
|
||||
extern void anongame_set_handle(t_anongame *a, t_uint32 h);
|
||||
extern void anongame_set_handle(t_anongame *a, std::uint32_t h);
|
||||
extern void anongame_set_addr(t_anongame *a, unsigned int addr);
|
||||
extern void anongame_set_loaded(t_anongame * a, char loaded);
|
||||
extern void anongame_set_joined(t_anongame * a, char joined);
|
||||
|
|
|
@ -19,12 +19,12 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "character.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "compat/strcasecmp.h"
|
||||
#include "common/eventlog.h"
|
||||
#include "common/list.h"
|
||||
#include "compat/uint.h"
|
||||
#include "common/bnet_protocol.h"
|
||||
#include "account.h"
|
||||
#include "account_wrap.h"
|
||||
|
@ -43,7 +43,7 @@ namespace pvpgn
|
|||
static t_list * characterlist_head = NULL;
|
||||
|
||||
|
||||
static t_character_class bncharacter_class_to_character_class(t_uint8 cclass)
|
||||
static t_character_class bncharacter_class_to_character_class(std::uint8_t cclass)
|
||||
{
|
||||
switch (cclass)
|
||||
{
|
||||
|
|
|
@ -18,17 +18,7 @@
|
|||
#ifndef INCLUDED_CHARACTER_TYPES
|
||||
#define INCLUDED_CHARACTER_TYPES
|
||||
|
||||
#ifdef CHARACTER_INTERNAL_ACCESS
|
||||
|
||||
#ifdef JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
#else
|
||||
# define JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
# undef JUST_NEED_TYPES
|
||||
#endif
|
||||
|
||||
#endif
|
||||
#include <cstdint>
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
@ -63,43 +53,43 @@ namespace pvpgn
|
|||
char const * guildname; /* max 3 chars */
|
||||
|
||||
/* stored in Battle.net format for now */
|
||||
t_uint8 helmgfx;
|
||||
t_uint8 bodygfx;
|
||||
t_uint8 leggfx;
|
||||
t_uint8 lhandweapon;
|
||||
t_uint8 lhandgfx;
|
||||
t_uint8 rhandweapon;
|
||||
t_uint8 rhandgfx;
|
||||
t_uint8 chclass;
|
||||
t_uint8 level;
|
||||
t_uint8 status;
|
||||
t_uint8 title;
|
||||
t_uint8 emblembgc;
|
||||
t_uint8 emblemfgc;
|
||||
t_uint8 emblemnum;
|
||||
std::uint8_t helmgfx;
|
||||
std::uint8_t bodygfx;
|
||||
std::uint8_t leggfx;
|
||||
std::uint8_t lhandweapon;
|
||||
std::uint8_t lhandgfx;
|
||||
std::uint8_t rhandweapon;
|
||||
std::uint8_t rhandgfx;
|
||||
std::uint8_t chclass;
|
||||
std::uint8_t level;
|
||||
std::uint8_t status;
|
||||
std::uint8_t title;
|
||||
std::uint8_t emblembgc;
|
||||
std::uint8_t emblemfgc;
|
||||
std::uint8_t emblemnum;
|
||||
|
||||
/* not sure what these represent */
|
||||
t_uint32 unknown1;
|
||||
t_uint32 unknown2;
|
||||
t_uint32 unknown3;
|
||||
t_uint32 unknown4;
|
||||
t_uint8 unknownb1;
|
||||
t_uint8 unknownb2;
|
||||
t_uint8 unknownb3;
|
||||
t_uint8 unknownb4;
|
||||
t_uint8 unknownb5;
|
||||
t_uint8 unknownb6;
|
||||
t_uint8 unknownb7;
|
||||
t_uint8 unknownb8;
|
||||
t_uint8 unknownb9;
|
||||
t_uint8 unknownb10;
|
||||
t_uint8 unknownb11;
|
||||
t_uint8 unknownb13;
|
||||
t_uint8 unknownb14;
|
||||
std::uint32_t unknown1;
|
||||
std::uint32_t unknown2;
|
||||
std::uint32_t unknown3;
|
||||
std::uint32_t unknown4;
|
||||
std::uint8_t unknownb1;
|
||||
std::uint8_t unknownb2;
|
||||
std::uint8_t unknownb3;
|
||||
std::uint8_t unknownb4;
|
||||
std::uint8_t unknownb5;
|
||||
std::uint8_t unknownb6;
|
||||
std::uint8_t unknownb7;
|
||||
std::uint8_t unknownb8;
|
||||
std::uint8_t unknownb9;
|
||||
std::uint8_t unknownb10;
|
||||
std::uint8_t unknownb11;
|
||||
std::uint8_t unknownb13;
|
||||
std::uint8_t unknownb14;
|
||||
|
||||
/* Keep some generic "data", basically the blob that is sent between client and server, in an array */
|
||||
t_uint8 data[64];
|
||||
t_uint8 datalen;
|
||||
std::uint8_t data[64];
|
||||
std::uint8_t datalen;
|
||||
}
|
||||
#endif
|
||||
t_character;
|
||||
|
@ -117,7 +107,6 @@ namespace pvpgn
|
|||
#define INCLUDED_CHARACTER_PROTOS
|
||||
|
||||
#define JUST_NEED_TYPES
|
||||
#include "compat/uint.h"
|
||||
#include "account.h"
|
||||
#undef JUST_NEED_TYPES
|
||||
|
||||
|
|
|
@ -16,12 +16,17 @@
|
|||
#define CLAN_INTERNAL_ACCESS
|
||||
#include "common/setup_before.h"
|
||||
#include "clan.h"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "compat/strcasecmp.h"
|
||||
#include "compat/strncasecmp.h"
|
||||
#include "compat/pdir.h"
|
||||
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "common/packet.h"
|
||||
#include "common/bnet_protocol.h"
|
||||
#include "common/util.h"
|
||||
|
@ -31,6 +36,7 @@
|
|||
#include "common/proginfo.h"
|
||||
#include "common/bn_type.h"
|
||||
#include "common/xalloc.h"
|
||||
|
||||
#include "connection.h"
|
||||
#include "anongame.h"
|
||||
#include "prefs.h"
|
||||
|
@ -42,7 +48,7 @@
|
|||
#include "anongame.h"
|
||||
#include "storage.h"
|
||||
#include "server.h"
|
||||
#include "compat/uint.h"
|
||||
|
||||
#include "common/setup_after.h"
|
||||
|
||||
namespace pvpgn
|
||||
|
|
|
@ -23,12 +23,13 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "handle_bnet.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <fstream>
|
||||
#include <cerrno>
|
||||
#include <sstream>
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
|
||||
#include "compat/strcasecmp.h"
|
||||
#include "compat/strncasecmp.h"
|
||||
|
@ -3492,7 +3493,7 @@ namespace pvpgn
|
|||
int found = 1;
|
||||
t_clan *user_clan;
|
||||
t_clantag clantag;
|
||||
t_uint32 clienttag;
|
||||
std::uint32_t clienttag;
|
||||
t_channel *channel;
|
||||
|
||||
if (packet_get_size(packet) < sizeof(t_client_joinchannel)) {
|
||||
|
|
|
@ -21,9 +21,11 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "handle_wol.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cctype>
|
||||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "compat/strcasecmp.h"
|
||||
#include "common/irc_protocol.h"
|
||||
|
@ -1326,7 +1328,7 @@ namespace pvpgn
|
|||
|
||||
game_set_status(game, game_status_started);
|
||||
|
||||
std::snprintf(_temp_a, sizeof(_temp_a), "%u %u", game_get_id(game), game_get_start_time(game));
|
||||
std::snprintf(_temp_a, sizeof(_temp_a), "%u %" PRId64, game_get_id(game), static_cast<std::int64_t>(game_get_start_time(game)));
|
||||
std::strcat(temp, _temp_a);
|
||||
|
||||
for (i = 0; ((e) && (e[i])); i++) {
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "handle_wol_gameres.h"
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstring>
|
||||
|
||||
#include "common/wol_gameres_protocol.h"
|
||||
|
@ -740,17 +741,17 @@ namespace pvpgn
|
|||
switch (type) {
|
||||
case wol_gameres_type_bool:
|
||||
case wol_gameres_type_byte:
|
||||
std::snprintf(ch_data, sizeof(ch_data), "%u", (unsigned int)bn_byte_get(*((bn_byte *)data)));
|
||||
std::snprintf(ch_data, sizeof(ch_data), "%" PRIu8, bn_byte_get(*((bn_byte *)data)));
|
||||
break;
|
||||
case wol_gameres_type_int:
|
||||
case wol_gameres_type_time:
|
||||
std::snprintf(ch_data, sizeof(ch_data), "%u", (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
std::snprintf(ch_data, sizeof(ch_data), "%" PRIu32, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_string:
|
||||
std::snprintf(ch_data, sizeof(ch_data), "%s", (char *)data);
|
||||
std::snprintf(ch_data, sizeof(ch_data), "%s", (char*)data);
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
std::snprintf(ch_data, sizeof(ch_data), "%u", wol_gameres_get_long_from_data(datalen, data));
|
||||
std::snprintf(ch_data, sizeof(ch_data), "%lu", wol_gameres_get_long_from_data(datalen, data));
|
||||
break;
|
||||
default:
|
||||
std::snprintf(ch_data, sizeof(ch_data), "UNKNOWN");
|
||||
|
@ -831,7 +832,7 @@ namespace pvpgn
|
|||
gameidnumber = (unsigned int)bn_int_nget(*((bn_int *)data));
|
||||
break;
|
||||
default:
|
||||
WARN1("got unknown gameres type %u for IDNO", type);
|
||||
WARN1("got unknown gameres type %d for IDNO", static_cast<int>(type));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -2110,7 +2111,7 @@ namespace pvpgn
|
|||
int senderid = game_result->senderid;
|
||||
t_account * account = accountlist_find_account((char const *)data);
|
||||
|
||||
DEBUG2("Name of palyer %u: %s", (char *)num, data);
|
||||
DEBUG2("Name of player %d: %s", num, static_cast<const char*>(data));
|
||||
|
||||
game_result->otheraccount = account;
|
||||
|
||||
|
@ -2600,13 +2601,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u build %u infantry", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d build %" PRIu32 " infantry", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u build %u infantry", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d build %lu infantry", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for INB%u", type, num);
|
||||
WARN2("got unknown gameres type %d for INB%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -2662,13 +2663,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u build %u units", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d build %" PRIu32 " units", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u build %u units", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d build %lu units", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for UNB%u", type, num);
|
||||
WARN2("got unknown gameres type %d for UNB%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -2719,13 +2720,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u build %u planes", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d build %" PRIu32 " planes", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u build %u planes", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d build %lu planes", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for PLB%u", type, num);
|
||||
WARN2("got unknown gameres type %d for PLB%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -2775,13 +2776,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u build %u buildings", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d build %" PRIu32 " buildings", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u build %u buildings", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d build %lu buildings", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for BLB%u", type, num);
|
||||
WARN2("got unknown gameres type %d for BLB%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -2831,13 +2832,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u lost %u infantry", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d lost %" PRIu32 " infantry", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u lost %u infantry", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d lost %lu infantry", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for INL%u", type, num);
|
||||
WARN2("got unknown gameres type %d for INL%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -2887,13 +2888,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u lost %u units", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d lost %" PRIu32 " units", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u lost %u units", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d lost %lu units", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for UNL%u", type, num);
|
||||
WARN2("got unknown gameres type %d for UNL%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -2943,13 +2944,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u lost %u planes", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d lost %" PRIu32 " planes", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u lost %u planes", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d lost %lu planes", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for PLL%u", type, num);
|
||||
WARN2("got unknown gameres type %d for PLL%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -2999,13 +3000,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u lost %u buildings", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d lost %" PRIu32 " buildings", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u lost %u buildings", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d lost %lu buildings", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for BLL%u", type, num);
|
||||
WARN2("got unknown gameres type %d for BLL%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -3055,13 +3056,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u killed %u infantry", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d killed %" PRIu32 " infantry", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u killed %u infantry", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d killed %lu infantry", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for INK%u", type, num);
|
||||
WARN2("got unknown gameres type %d for INK%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -3111,13 +3112,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u killed %u units", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d killed %" PRIu32 " units", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u killed %u units", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d killed %lu units", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for UNK%u", type, num);
|
||||
WARN2("got unknown gameres type %du for UNK%du", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -3167,13 +3168,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u killed %u planes", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d killed %" PRIu32 " planes", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u killed %u planes", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d killed %lu planes", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for PLK%u", type, num);
|
||||
WARN2("got unknown gameres type %d for PLK%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -3223,13 +3224,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_time:
|
||||
DEBUG2("Player %u killed %u buildings", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d killed %" PRIu32 " buildings", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u killed %u buildings", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d killed %lu buildings", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for BLK%u", type, num);
|
||||
WARN2("got unknown gameres type %d for BLK%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
@ -3279,13 +3280,13 @@ namespace pvpgn
|
|||
{
|
||||
switch (type) {
|
||||
case wol_gameres_type_int:
|
||||
DEBUG2("Player %u captured %u buildings", num, (unsigned int)bn_int_nget(*((bn_int *)data)));
|
||||
DEBUG2("Player %d captured %" PRIu32 " buildings", num, bn_int_nget(*((bn_int *)data)));
|
||||
break;
|
||||
case wol_gameres_type_bigint:
|
||||
DEBUG2("Player %u captured %u buildings", num, wol_gameres_get_long_from_data(size, data));
|
||||
DEBUG2("Player %d captured %lu buildings", num, wol_gameres_get_long_from_data(size, data));
|
||||
break;
|
||||
default:
|
||||
WARN2("got unknown gameres type %u for BLC%u", type, num);
|
||||
WARN2("got unknown gameres type %d for BLC%d", static_cast<int>(type), num);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -35,7 +35,8 @@ namespace pvpgn
|
|||
namespace bnetd
|
||||
{
|
||||
|
||||
typedef enum {
|
||||
typedef enum : int
|
||||
{
|
||||
wol_gameres_type_unknown = 0,
|
||||
wol_gameres_type_byte = 1,
|
||||
wol_gameres_type_bool = 2,
|
||||
|
|
|
@ -20,11 +20,13 @@
|
|||
#define IPBAN_INTERNAL_ACCESS
|
||||
#include "ipban.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <cctype>
|
||||
#include <cerrno>
|
||||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
#include "compat/strsep.h"
|
||||
|
@ -215,9 +217,10 @@ namespace pvpgn
|
|||
continue;
|
||||
}
|
||||
if (entry->endtime == 0)
|
||||
std::sprintf(line, "%s\n", ipstr);
|
||||
std::snprintf(line, sizeof(line), "%s\n", ipstr);
|
||||
else
|
||||
std::sprintf(line, "%s %ld\n", ipstr, entry->endtime);
|
||||
std::sprintf(line, "%s %" PRId64 "\n", ipstr, static_cast<std::int64_t>(entry->endtime));
|
||||
|
||||
if (!(std::fwrite(line, std::strlen(line), 1, fp)))
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "could not write to banlist file (write: %s)", std::strerror(errno));
|
||||
xfree(ipstr);
|
||||
|
|
|
@ -21,10 +21,12 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "irc.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cinttypes>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
||||
#include "compat/strcasecmp.h"
|
||||
|
||||
|
@ -1627,17 +1629,16 @@ namespace pvpgn
|
|||
|
||||
extern int _handle_time_command(t_connection * conn, int numparams, char ** params, char * text)
|
||||
{
|
||||
char temp[MAX_IRC_MESSAGE_LEN];
|
||||
char temp[MAX_IRC_MESSAGE_LEN] = {}; // PELISH: According to RFC2812
|
||||
std::time_t now;
|
||||
char const * ircname = server_get_hostname();
|
||||
|
||||
/* PELISH: According to RFC2812 */
|
||||
std::memset(temp, 0, sizeof(temp));
|
||||
|
||||
if ((numparams >= 1) && (params[0])) {
|
||||
if (std::strcmp(params[0], ircname) == 0) {
|
||||
if ((numparams >= 1) && (params[0]))
|
||||
{
|
||||
if (std::strcmp(params[0], ircname) == 0)
|
||||
{
|
||||
now = std::time(NULL);
|
||||
std::snprintf(temp, sizeof(temp), "%s :%lu", ircname, now);
|
||||
std::snprintf(temp, sizeof(temp), "%s :%" PRId64, ircname, static_cast<std::int64_t>(now));
|
||||
irc_send(conn, RPL_TIME, temp);
|
||||
}
|
||||
else {
|
||||
|
@ -1648,7 +1649,7 @@ namespace pvpgn
|
|||
else {
|
||||
/* RPL_TIME contains time and name of this server */
|
||||
now = std::time(NULL);
|
||||
std::snprintf(temp, sizeof(temp), "%s :%lu", ircname, now);
|
||||
std::snprintf(temp, sizeof(temp), "%s :%" PRId64, ircname, static_cast<std::int64_t>(now));
|
||||
irc_send(conn, RPL_TIME, temp);
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -99,7 +99,7 @@ namespace pvpgn
|
|||
|
||||
_register_functions();
|
||||
|
||||
std::snprintf(_msgtemp, sizeof(_msgtemp), "Lua sripts were successfully loaded (%u files)", files.size());
|
||||
std::snprintf(_msgtemp, sizeof(_msgtemp), "Lua sripts were successfully loaded (%zu files)", files.size());
|
||||
eventlog(eventlog_level_info, __FUNCTION__, "%s", _msgtemp);
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "common/setup_before.h"
|
||||
#include <cstring>
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
|
@ -265,7 +267,7 @@ extern int main(int argc, char * argv[])
|
|||
img->height += bni.icons->icon[i].y;
|
||||
}
|
||||
std::fprintf(stderr, "Info: Creating TGA with %ux%ux%ubpp.\n", img->width, img->height, img->bpp);
|
||||
img->data = (t_uint8*)xmalloc(img->width*img->height*getpixelsize(img));
|
||||
img->data = (std::uint8_t*)xmalloc(img->width*img->height*getpixelsize(img));
|
||||
yline = 0;
|
||||
for (i = 0; i < bni.numicons; i++) {
|
||||
t_tgaimg *icon;
|
||||
|
|
|
@ -17,9 +17,11 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include "common/setup_before.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
|
||||
#ifdef HAVE_SYS_STAT_H
|
||||
# include <sys/stat.h>
|
||||
|
@ -55,7 +57,7 @@ namespace
|
|||
if (pixelsize == 0) return NULL;
|
||||
|
||||
dst = new_tgaimg(width, height, src->bpp, type);
|
||||
dst->data = (t_uint8*)xmalloc(width*height*pixelsize);
|
||||
dst->data = (std::uint8_t*)xmalloc(width*height*pixelsize);
|
||||
|
||||
datap = src->data;
|
||||
datap += y*src->width*pixelsize;
|
||||
|
|
|
@ -19,7 +19,6 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "fileio.h"
|
||||
|
||||
#include "compat/uint.h"
|
||||
#include "common/xalloc.h"
|
||||
#include "common/setup_after.h"
|
||||
|
||||
|
@ -80,65 +79,65 @@ namespace pvpgn
|
|||
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
extern t_uint8 file_readb(void) {
|
||||
extern std::uint8_t file_readb(void) {
|
||||
unsigned char buff[1];
|
||||
if (std::fread(buff, 1, sizeof(buff), r_file->f) < sizeof(buff)) {
|
||||
if (std::ferror(r_file->f)) std::perror("file_readb: std::fread");
|
||||
return 0;
|
||||
}
|
||||
return (((t_uint8)buff[0]));
|
||||
return (((std::uint8_t)buff[0]));
|
||||
}
|
||||
|
||||
|
||||
extern t_uint16 file_readw_le(void) {
|
||||
extern std::uint16_t file_readw_le(void) {
|
||||
unsigned char buff[2];
|
||||
if (std::fread(buff, 1, sizeof(buff), r_file->f) < sizeof(buff)) {
|
||||
if (std::ferror(r_file->f)) std::perror("file_readw_le: std::fread");
|
||||
return 0;
|
||||
}
|
||||
return (((t_uint16)buff[0])) |
|
||||
(((t_uint16)buff[1]) << 8);
|
||||
return (((std::uint16_t)buff[0])) |
|
||||
(((std::uint16_t)buff[1]) << 8);
|
||||
}
|
||||
|
||||
|
||||
extern t_uint16 file_readw_be(void) {
|
||||
extern std::uint16_t file_readw_be(void) {
|
||||
unsigned char buff[2];
|
||||
if (std::fread(buff, 1, sizeof(buff), r_file->f) < sizeof(buff)) {
|
||||
if (std::ferror(r_file->f)) std::perror("file_readw_be: std::fread");
|
||||
return 0;
|
||||
}
|
||||
return (((t_uint16)buff[0]) << 8) |
|
||||
(((t_uint16)buff[1]));
|
||||
return (((std::uint16_t)buff[0]) << 8) |
|
||||
(((std::uint16_t)buff[1]));
|
||||
}
|
||||
|
||||
|
||||
extern t_uint32 file_readd_le(void) {
|
||||
extern std::uint32_t file_readd_le(void) {
|
||||
unsigned char buff[4];
|
||||
if (std::fread(buff, 1, sizeof(buff), r_file->f) < sizeof(buff)) {
|
||||
if (std::ferror(r_file->f)) std::perror("file_readd_le: std::fread");
|
||||
return 0;
|
||||
}
|
||||
return (((t_uint32)buff[0])) |
|
||||
(((t_uint32)buff[1]) << 8) |
|
||||
(((t_uint32)buff[2]) << 16) |
|
||||
(((t_uint32)buff[3]) << 24);
|
||||
return (((std::uint32_t)buff[0])) |
|
||||
(((std::uint32_t)buff[1]) << 8) |
|
||||
(((std::uint32_t)buff[2]) << 16) |
|
||||
(((std::uint32_t)buff[3]) << 24);
|
||||
}
|
||||
|
||||
|
||||
extern t_uint32 file_readd_be(void) {
|
||||
extern std::uint32_t file_readd_be(void) {
|
||||
unsigned char buff[4];
|
||||
if (std::fread(buff, 1, sizeof(buff), r_file->f) < sizeof(buff)) {
|
||||
if (std::ferror(r_file->f)) std::perror("file_readd_be: std::fread");
|
||||
return 0;
|
||||
}
|
||||
return (((t_uint32)buff[0]) << 24) |
|
||||
(((t_uint32)buff[1]) << 16) |
|
||||
(((t_uint32)buff[2]) << 8) |
|
||||
(((t_uint32)buff[3]));
|
||||
return (((std::uint32_t)buff[0]) << 24) |
|
||||
(((std::uint32_t)buff[1]) << 16) |
|
||||
(((std::uint32_t)buff[2]) << 8) |
|
||||
(((std::uint32_t)buff[3]));
|
||||
}
|
||||
|
||||
|
||||
extern int file_writeb(t_uint8 u) {
|
||||
extern int file_writeb(std::uint8_t u) {
|
||||
unsigned char buff[1];
|
||||
buff[0] = (u);
|
||||
if (std::fwrite(buff, 1, sizeof(buff), w_file->f) < sizeof(buff)) {
|
||||
|
@ -149,7 +148,7 @@ namespace pvpgn
|
|||
}
|
||||
|
||||
|
||||
extern int file_writew_le(t_uint16 u) {
|
||||
extern int file_writew_le(std::uint16_t u) {
|
||||
unsigned char buff[2];
|
||||
buff[0] = (u);
|
||||
buff[1] = (u >> 8);
|
||||
|
@ -161,7 +160,7 @@ namespace pvpgn
|
|||
}
|
||||
|
||||
|
||||
extern int file_writew_be(t_uint16 u) {
|
||||
extern int file_writew_be(std::uint16_t u) {
|
||||
unsigned char buff[2];
|
||||
buff[0] = (u >> 8);
|
||||
buff[1] = (u);
|
||||
|
@ -173,7 +172,7 @@ namespace pvpgn
|
|||
}
|
||||
|
||||
|
||||
extern int file_writed_le(t_uint32 u) {
|
||||
extern int file_writed_le(std::uint32_t u) {
|
||||
unsigned char buff[4];
|
||||
buff[0] = (u);
|
||||
buff[1] = (u >> 8);
|
||||
|
@ -187,7 +186,7 @@ namespace pvpgn
|
|||
}
|
||||
|
||||
|
||||
extern int file_writed_be(t_uint32 u) {
|
||||
extern int file_writed_be(std::uint32_t u) {
|
||||
unsigned char buff[4];
|
||||
buff[0] = (u >> 24);
|
||||
buff[1] = (u >> 16);
|
||||
|
|
|
@ -20,10 +20,8 @@
|
|||
#ifndef INCLUDED_FILEIO_PROTOS
|
||||
#define INCLUDED_FILEIO_PROTOS
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#define JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
#undef JUST_NEED_TYPES
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
@ -36,16 +34,16 @@ namespace pvpgn
|
|||
extern void file_wpush(std::FILE *f);
|
||||
extern void file_wpop(void);
|
||||
|
||||
extern t_uint8 file_readb(void);
|
||||
extern t_uint16 file_readw_le(void);
|
||||
extern t_uint16 file_readw_be(void);
|
||||
extern t_uint32 file_readd_le(void);
|
||||
extern t_uint32 file_readd_be(void);
|
||||
extern int file_writeb(t_uint8 u);
|
||||
extern int file_writew_le(t_uint16 u);
|
||||
extern int file_writew_be(t_uint16 u);
|
||||
extern int file_writed_le(t_uint32 u);
|
||||
extern int file_writed_be(t_uint32 u);
|
||||
extern std::uint8_t file_readb(void);
|
||||
extern std::uint16_t file_readw_le(void);
|
||||
extern std::uint16_t file_readw_be(void);
|
||||
extern std::uint32_t file_readd_le(void);
|
||||
extern std::uint32_t file_readd_be(void);
|
||||
extern int file_writeb(std::uint8_t u);
|
||||
extern int file_writew_le(std::uint16_t u);
|
||||
extern int file_writew_be(std::uint16_t u);
|
||||
extern int file_writed_le(std::uint32_t u);
|
||||
extern int file_writed_be(std::uint32_t u);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,9 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "tga.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <cerrno>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "common/xalloc.h"
|
||||
#include "fileio.h"
|
||||
|
@ -353,7 +354,7 @@ namespace pvpgn
|
|||
}
|
||||
|
||||
/* Now, we can alloc img->data */
|
||||
img->data = (t_uint8*)xmalloc(img->width*img->height*pixelsize);
|
||||
img->data = (std::uint8_t*)xmalloc(img->width*img->height*pixelsize);
|
||||
if (img->imgtype == tgaimgtype_uncompressed_truecolor) {
|
||||
if (std::fread(img->data, pixelsize, img->width*img->height, f) < (unsigned)(img->width*img->height)) {
|
||||
std::fprintf(stderr, "load_tga: error while reading data!\n");
|
||||
|
|
|
@ -19,14 +19,9 @@
|
|||
#ifndef INCLUDED_TGA_H
|
||||
#define INCLUDED_TGA_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#ifdef JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
#else
|
||||
# define JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
# undef JUST_NEED_TYPES
|
||||
#endif
|
||||
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
@ -34,30 +29,32 @@ namespace pvpgn
|
|||
namespace bni
|
||||
{
|
||||
|
||||
typedef struct {
|
||||
t_uint8 idlen; /* number of bytes in Field 6: 0==no id */
|
||||
t_uint8 cmaptype; /* colormap: 0==none, 1==included, <128==TrueVision, >=128==developer */
|
||||
t_uint8 imgtype; /* pixel format: <128==TrueVision, >=128==developer */
|
||||
t_uint16 cmapfirst; /* first entry offset */
|
||||
t_uint16 cmaplen; /* number of colormap entries */
|
||||
t_uint8 cmapes; /* size of a single colormap entry in bits, 15 forces 1 attribute bit, 32 forces 8 */
|
||||
t_uint16 xorigin; /* x coordinate of lower left hand corner with origin at left of screen */
|
||||
t_uint16 yorigin; /* y coordinate of lower left hand corner with origin at bottom of screen */
|
||||
t_uint16 width; /* width in pixels */
|
||||
t_uint16 height; /* height in pixels */
|
||||
t_uint8 bpp; /* bits per pixel, including attributes and alpha channel */
|
||||
t_uint8 desc; /* image descriptor: bits 0,1,2,3==num attribute bits per pixel, bit 4==horizontal order, bit 5==vertical order, bits 6,7==interleaving */
|
||||
typedef struct
|
||||
{
|
||||
std::uint8_t idlen; /* number of bytes in Field 6: 0==no id */
|
||||
std::uint8_t cmaptype; /* colormap: 0==none, 1==included, <128==TrueVision, >=128==developer */
|
||||
std::uint8_t imgtype; /* pixel format: <128==TrueVision, >=128==developer */
|
||||
std::uint16_t cmapfirst; /* first entry offset */
|
||||
std::uint16_t cmaplen; /* number of colormap entries */
|
||||
std::uint8_t cmapes; /* size of a single colormap entry in bits, 15 forces 1 attribute bit, 32 forces 8 */
|
||||
std::uint16_t xorigin; /* x coordinate of lower left hand corner with origin at left of screen */
|
||||
std::uint16_t yorigin; /* y coordinate of lower left hand corner with origin at bottom of screen */
|
||||
std::uint16_t width; /* width in pixels */
|
||||
std::uint16_t height; /* height in pixels */
|
||||
std::uint8_t bpp; /* bits per pixel, including attributes and alpha channel */
|
||||
std::uint8_t desc; /* image descriptor: bits 0,1,2,3==num attribute bits per pixel, bit 4==horizontal order, bit 5==vertical order, bits 6,7==interleaving */
|
||||
/* field 6, optional */
|
||||
/* field 7, colormap data in ARGB, optional, entries are (min(cmapes/3,8)*3+7)/8 bits wide */
|
||||
t_uint8 *data;
|
||||
std::uint8_t* data;
|
||||
/* field 9, developer area, optional */
|
||||
/* field 10, extension area, optional */
|
||||
t_uint32 extareaoff; /* extension area offset, 0==none */
|
||||
t_uint32 devareaoff; /* developer area offset, 0==none */
|
||||
std::uint32_t extareaoff; /* extension area offset, 0==none */
|
||||
std::uint32_t devareaoff; /* developer area offset, 0==none */
|
||||
/* magic, null terminated */
|
||||
} t_tgaimg;
|
||||
|
||||
typedef enum {
|
||||
typedef enum
|
||||
{
|
||||
tgaimgtype_empty = 0,
|
||||
tgaimgtype_uncompressed_mapped = 1,
|
||||
tgaimgtype_uncompressed_truecolor = 2,
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "common/setup_before.h"
|
||||
#define TRACKER_INTERNAL_ACCESS
|
||||
|
||||
#include <cinttypes>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
|
@ -295,41 +296,41 @@ namespace {
|
|||
if (prefs.XML_mode == 1)
|
||||
{
|
||||
std::fprintf(outfile, "<server>\n\t<address>%s</address>\n", addrstr);
|
||||
std::fprintf(outfile, "\t<port>%hu</port>\n", bn_short_nget(server->info.port));
|
||||
std::fprintf(outfile, "\t<location>%s</location>\n", server->info.server_location);
|
||||
std::fprintf(outfile, "\t<software>%s</software>\n", server->info.software);
|
||||
std::fprintf(outfile, "\t<version>%s</version>\n", server->info.version);
|
||||
std::fprintf(outfile, "\t<users>%lu</users>\n", bn_int_nget(server->info.users));
|
||||
std::fprintf(outfile, "\t<channels>%lu</channels>\n", bn_int_nget(server->info.channels));
|
||||
std::fprintf(outfile, "\t<games>%lu</games>\n", bn_int_nget(server->info.games));
|
||||
std::fprintf(outfile, "\t<description>%s</description>\n", server->info.server_desc);
|
||||
std::fprintf(outfile, "\t<platform>%s</platform>\n", server->info.platform);
|
||||
std::fprintf(outfile, "\t<url>%s</url>\n", server->info.server_url);
|
||||
std::fprintf(outfile, "\t<contact_name>%s</contact_name>\n", server->info.contact_name);
|
||||
std::fprintf(outfile, "\t<contact_email>%s</contact_email>\n", server->info.contact_email);
|
||||
std::fprintf(outfile, "\t<uptime>%lu</uptime>\n", bn_int_nget(server->info.uptime));
|
||||
std::fprintf(outfile, "\t<total_games>%lu</total_games>\n", bn_int_nget(server->info.total_games));
|
||||
std::fprintf(outfile, "\t<logins>%lu</logins>\n", bn_int_nget(server->info.total_logins));
|
||||
std::fprintf(outfile, "\t<port>%" PRIu16 "</port>\n", bn_short_nget(server->info.port));
|
||||
std::fprintf(outfile, "\t<location>%s</location>\n", reinterpret_cast<char*>(server->info.server_location));
|
||||
std::fprintf(outfile, "\t<software>%s</software>\n", reinterpret_cast<char*>(server->info.software));
|
||||
std::fprintf(outfile, "\t<version>%s</version>\n", reinterpret_cast<char*>(server->info.version));
|
||||
std::fprintf(outfile, "\t<users>%" PRIu32 "</users>\n", bn_int_nget(server->info.users));
|
||||
std::fprintf(outfile, "\t<channels>%" PRIu32 "</channels>\n", bn_int_nget(server->info.channels));
|
||||
std::fprintf(outfile, "\t<games>%" PRIu32 "</games>\n", bn_int_nget(server->info.games));
|
||||
std::fprintf(outfile, "\t<description>%s</description>\n", reinterpret_cast<char*>(server->info.server_desc));
|
||||
std::fprintf(outfile, "\t<platform>%s</platform>\n", reinterpret_cast<char*>(server->info.platform));
|
||||
std::fprintf(outfile, "\t<url>%s</url>\n", reinterpret_cast<char*>(server->info.server_url));
|
||||
std::fprintf(outfile, "\t<contact_name>%s</contact_name>\n", reinterpret_cast<char*>(server->info.contact_name));
|
||||
std::fprintf(outfile, "\t<contact_email>%s</contact_email>\n", reinterpret_cast<char*>(server->info.contact_email));
|
||||
std::fprintf(outfile, "\t<uptime>%" PRIu32 "</uptime>\n", bn_int_nget(server->info.uptime));
|
||||
std::fprintf(outfile, "\t<total_games>%" PRIu32 "</total_games>\n", bn_int_nget(server->info.total_games));
|
||||
std::fprintf(outfile, "\t<logins>%" PRIu32 "</logins>\n", bn_int_nget(server->info.total_logins));
|
||||
std::fprintf(outfile, "</server>\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
std::fprintf(outfile, "%s\n##\n", addrstr);
|
||||
std::fprintf(outfile, "%hu\n##\n", bn_short_nget(server->info.port));
|
||||
std::fprintf(outfile, "%s\n##\n", server->info.server_location);
|
||||
std::fprintf(outfile, "%s\n##\n", server->info.software);
|
||||
std::fprintf(outfile, "%s\n##\n", server->info.version);
|
||||
std::fprintf(outfile, "%lu\n##\n", bn_int_nget(server->info.users));
|
||||
std::fprintf(outfile, "%lu\n##\n", bn_int_nget(server->info.channels));
|
||||
std::fprintf(outfile, "%lu\n##\n", bn_int_nget(server->info.games));
|
||||
std::fprintf(outfile, "%s\n##\n", server->info.server_desc);
|
||||
std::fprintf(outfile, "%s\n##\n", server->info.platform);
|
||||
std::fprintf(outfile, "%s\n##\n", server->info.server_url);
|
||||
std::fprintf(outfile, "%s\n##\n", server->info.contact_name);
|
||||
std::fprintf(outfile, "%s\n##\n", server->info.contact_email);
|
||||
std::fprintf(outfile, "%lu\n##\n", bn_int_nget(server->info.uptime));
|
||||
std::fprintf(outfile, "%lu\n##\n", bn_int_nget(server->info.total_games));
|
||||
std::fprintf(outfile, "%lu\n##\n", bn_int_nget(server->info.total_logins));
|
||||
std::fprintf(outfile, "%" PRIu16 "\n##\n", bn_short_nget(server->info.port));
|
||||
std::fprintf(outfile, "%s\n##\n", reinterpret_cast<char*>(server->info.server_location));
|
||||
std::fprintf(outfile, "%s\n##\n", reinterpret_cast<char*>(server->info.software));
|
||||
std::fprintf(outfile, "%s\n##\n", reinterpret_cast<char*>(server->info.version));
|
||||
std::fprintf(outfile, "%" PRIu32 "\n##\n", bn_int_nget(server->info.users));
|
||||
std::fprintf(outfile, "%" PRIu32 "\n##\n", bn_int_nget(server->info.channels));
|
||||
std::fprintf(outfile, "%" PRIu32 "\n##\n", bn_int_nget(server->info.games));
|
||||
std::fprintf(outfile, "%s\n##\n", reinterpret_cast<char*>(server->info.server_desc));
|
||||
std::fprintf(outfile, "%s\n##\n", reinterpret_cast<char*>(server->info.platform));
|
||||
std::fprintf(outfile, "%s\n##\n", reinterpret_cast<char*>(server->info.server_url));
|
||||
std::fprintf(outfile, "%s\n##\n", reinterpret_cast<char*>(server->info.contact_name));
|
||||
std::fprintf(outfile, "%s\n##\n", reinterpret_cast<char*>(server->info.contact_email));
|
||||
std::fprintf(outfile, "%" PRIu32 "\n##\n", bn_int_nget(server->info.uptime));
|
||||
std::fprintf(outfile, "%" PRIu32 "\n##\n", bn_int_nget(server->info.total_games));
|
||||
std::fprintf(outfile, "%" PRIu32 "\n##\n", bn_int_nget(server->info.total_logins));
|
||||
std::fprintf(outfile, "###\n");
|
||||
}
|
||||
}
|
||||
|
@ -424,9 +425,9 @@ namespace {
|
|||
|
||||
eventlog(eventlog_level_debug, __FUNCTION__,
|
||||
"Packet received from %s:"
|
||||
" packet_version=%u"
|
||||
" flags=0x%08lx"
|
||||
" port=%hu"
|
||||
" packet_version=%" PRIu16
|
||||
" flags=0x%08" PRIu32 "x"
|
||||
" port=%" PRIu16
|
||||
" software=\"%s\""
|
||||
" version=\"%s\""
|
||||
" platform=\"%s\""
|
||||
|
@ -435,21 +436,21 @@ namespace {
|
|||
" server_url=\"%s\""
|
||||
" contact_name=\"%s\""
|
||||
" contact_email=\"%s\""
|
||||
" uptime=%lu"
|
||||
" total_games=%lu"
|
||||
" total_logins=%lu",
|
||||
" uptime=%" PRIu32
|
||||
" total_games=%" PRIu32
|
||||
" total_logins=%" PRIu32,
|
||||
addrstr2,
|
||||
bn_short_nget(packet.packet_version),
|
||||
bn_int_nget(packet.flags),
|
||||
bn_short_nget(packet.port),
|
||||
packet.software,
|
||||
packet.version,
|
||||
packet.platform,
|
||||
packet.server_desc,
|
||||
packet.server_location,
|
||||
packet.server_url,
|
||||
packet.contact_name,
|
||||
packet.contact_email,
|
||||
reinterpret_cast<char*>(packet.software),
|
||||
reinterpret_cast<char*>(packet.version),
|
||||
reinterpret_cast<char*>(packet.platform),
|
||||
reinterpret_cast<char*>(packet.server_desc),
|
||||
reinterpret_cast<char*>(packet.server_location),
|
||||
reinterpret_cast<char*>(packet.server_url),
|
||||
reinterpret_cast<char*>(packet.contact_name),
|
||||
reinterpret_cast<char*>(packet.contact_email),
|
||||
bn_int_nget(packet.uptime),
|
||||
bn_int_nget(packet.total_games),
|
||||
bn_int_nget(packet.total_logins));
|
||||
|
|
|
@ -28,9 +28,9 @@
|
|||
#include "asnprintf.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "compat/uint.h"
|
||||
#include "common/setup_after.h"
|
||||
|
||||
namespace pvpgn
|
||||
|
@ -45,14 +45,14 @@ namespace pvpgn
|
|||
return i;
|
||||
}
|
||||
|
||||
t_uint32 do_div(t_uint64 *n, t_uint32 base)
|
||||
std::uint32_t do_div(std::uint64_t *n, std::uint32_t base)
|
||||
{
|
||||
t_uint32 remainder = *n % base;
|
||||
std::uint32_t remainder = *n % base;
|
||||
*n = *n / base;
|
||||
return remainder;
|
||||
}
|
||||
|
||||
static char * number(char * buf, char * end, t_uint64 num, int base, int size, int precision, int type)
|
||||
static char * number(char * buf, char * end, std::uint64_t num, int base, int size, int precision, int type)
|
||||
{
|
||||
char c, sign, tmp[66];
|
||||
const char *digits;
|
||||
|
@ -68,9 +68,9 @@ namespace pvpgn
|
|||
c = (type & ZEROPAD) ? '0' : ' ';
|
||||
sign = 0;
|
||||
if (type & SIGN) {
|
||||
if ((t_int64)num < 0) {
|
||||
if ((std::int64_t)num < 0) {
|
||||
sign = '-';
|
||||
num = -(t_int64)num;
|
||||
num = -(std::int64_t)num;
|
||||
size--;
|
||||
}
|
||||
else if (type & PLUS) {
|
||||
|
@ -151,7 +151,7 @@ namespace pvpgn
|
|||
int vasnprintf(char *buf, std::size_t size, t_fmtentry *entries, unsigned entlen, const char *fmt, std::va_list args)
|
||||
{
|
||||
int len;
|
||||
t_uint64 num;
|
||||
std::uint64_t num;
|
||||
int i, base;
|
||||
char *str, *end, c;
|
||||
const char *s;
|
||||
|
|
|
@ -16,22 +16,22 @@
|
|||
*/
|
||||
|
||||
#include "common/setup_before.h"
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include "bigint.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
|
||||
#include "bigint.h"
|
||||
#include "common/xalloc.h"
|
||||
|
||||
#include "compat/uint.h"
|
||||
|
||||
#include "common/setup_after.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
|
@ -44,26 +44,26 @@ namespace pvpgn
|
|||
segment[0] = 0;
|
||||
}
|
||||
|
||||
BigInt::BigInt(t_uint8 input)
|
||||
BigInt::BigInt(std::uint8_t input)
|
||||
{
|
||||
segment_count = 1;
|
||||
segment = (bigint_base*)xmalloc(segment_count * sizeof(bigint_base));
|
||||
segment[0] = input;
|
||||
}
|
||||
|
||||
BigInt::BigInt(t_uint16 input)
|
||||
BigInt::BigInt(std::uint16_t input)
|
||||
{
|
||||
segment_count = 1;
|
||||
segment = (bigint_base*)xmalloc(segment_count * sizeof(bigint_base));
|
||||
segment[0] = input;
|
||||
}
|
||||
|
||||
BigInt::BigInt(t_uint32 input)
|
||||
BigInt::BigInt(std::uint32_t input)
|
||||
{
|
||||
#ifndef HAVE_UINT64_T
|
||||
int i;
|
||||
#endif
|
||||
segment_count = sizeof(t_uint32) / sizeof(bigint_base);
|
||||
segment_count = sizeof(std::uint32_t) / sizeof(bigint_base);
|
||||
segment = (bigint_base*)xmalloc(segment_count * sizeof(bigint_base));
|
||||
#ifdef HAVE_UINT64_T
|
||||
segment[0] = input;
|
||||
|
@ -75,18 +75,16 @@ namespace pvpgn
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_UINT64_T
|
||||
BigInt::BigInt(t_uint64 input)
|
||||
BigInt::BigInt(std::uint64_t input)
|
||||
{
|
||||
int i;
|
||||
segment_count = sizeof(t_uint64) / sizeof(bigint_base);
|
||||
segment_count = sizeof(std::uint64_t) / sizeof(bigint_base);
|
||||
segment = (bigint_base*)xmalloc(segment_count * sizeof(bigint_base));
|
||||
for (i = 0; i < segment_count; i++){
|
||||
segment[i] = input & bigint_base_mask;
|
||||
input >>= bigint_base_bitcount;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
BigInt::BigInt(const BigInt& input)
|
||||
:segment_count(input.segment_count)
|
||||
|
@ -575,7 +573,7 @@ namespace pvpgn
|
|||
}
|
||||
else if (exp.segment[0] == 0x00)
|
||||
{
|
||||
return BigInt((t_uint8)0x01);
|
||||
return BigInt((std::uint8_t)0x01);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -583,14 +581,14 @@ namespace pvpgn
|
|||
if (exp.segment[0] % 2 == 0)
|
||||
{
|
||||
// exp is even
|
||||
BigInt half = exp / (BigInt((t_uint8)0x02));
|
||||
BigInt half = exp / (BigInt((std::uint8_t)0x02));
|
||||
BigInt halfpow = this->powm(half, mod);
|
||||
return (halfpow * halfpow) % mod;
|
||||
}
|
||||
else
|
||||
{
|
||||
// exp is odd
|
||||
BigInt half = exp / (BigInt((t_uint8)0x02));
|
||||
BigInt half = exp / (BigInt((std::uint8_t)0x02));
|
||||
BigInt halfpow = this->powm(half, mod);
|
||||
return (((halfpow * halfpow) % mod) * *this) % mod;
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@
|
|||
* GNU Affero General Public License for more details.
|
||||
*/
|
||||
|
||||
#ifndef __BIGINT_INCLUDED__
|
||||
#define __BIGINT_INCLUDED__
|
||||
#ifndef INCLUDED_BIGINT_H
|
||||
#define INCLUDED_BIGINT_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include "compat/uint.h"
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
@ -28,9 +28,9 @@ namespace pvpgn
|
|||
{
|
||||
public:
|
||||
BigInt();
|
||||
explicit BigInt(t_uint8 input);
|
||||
explicit BigInt(t_uint16 input);
|
||||
explicit BigInt(t_uint32 input);
|
||||
explicit BigInt(std::uint8_t input);
|
||||
explicit BigInt(std::uint16_t input);
|
||||
explicit BigInt(std::uint32_t input);
|
||||
BigInt(const BigInt& input);
|
||||
BigInt& operator=(const BigInt& input);
|
||||
BigInt(unsigned char const* input, int input_size, int blockSize = 1, bool bigEndian = true);
|
||||
|
@ -52,17 +52,11 @@ namespace pvpgn
|
|||
std::string toHexString() const;
|
||||
|
||||
private:
|
||||
|
||||
#ifdef HAVE_UINT64_T
|
||||
explicit BigInt(t_uint64 input);
|
||||
typedef t_uint32 bigint_base;
|
||||
typedef t_uint64 bigint_extended;
|
||||
|
||||
explicit BigInt(std::uint64_t input);
|
||||
using bigint_base = std::uint32_t;
|
||||
using bigint_extended = std::uint64_t;
|
||||
#define bigint_base_mask 0xffffffff
|
||||
#else
|
||||
typedef t_uint16 bigint_base;
|
||||
typedef t_uint32 bigint_extended;
|
||||
#define bigint_base_mask 0xffff
|
||||
#endif
|
||||
#define bigint_extended_carry bigint_base_mask+0x01
|
||||
#define bigint_base_bitcount (sizeof(bigint_base)*8)
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "common/bn_type.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
#include "common/eventlog.h"
|
||||
|
@ -230,9 +231,9 @@ namespace pvpgn
|
|||
/************************************************************/
|
||||
|
||||
|
||||
extern t_uint8 bn_byte_get(bn_byte const src)
|
||||
extern std::uint8_t bn_byte_get(bn_byte const src)
|
||||
{
|
||||
t_uint8 temp;
|
||||
std::uint8_t temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
|
@ -240,14 +241,14 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
temp = ((t_uint8)src[0]);
|
||||
temp = ((std::uint8_t)src[0]);
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
extern t_uint16 bn_short_get(bn_short const src)
|
||||
extern std::uint16_t bn_short_get(bn_short const src)
|
||||
{
|
||||
t_uint16 temp;
|
||||
std::uint16_t temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
|
@ -255,15 +256,15 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
temp = ((t_uint16)src[0]);
|
||||
temp |= ((t_uint16)src[1]) << 8;
|
||||
temp = ((std::uint16_t)src[0]);
|
||||
temp |= ((std::uint16_t)src[1]) << 8;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
extern t_uint16 bn_short_nget(bn_short const src)
|
||||
extern std::uint16_t bn_short_nget(bn_short const src)
|
||||
{
|
||||
t_uint16 temp;
|
||||
std::uint16_t temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
|
@ -271,15 +272,15 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
temp = ((t_uint16)src[1]);
|
||||
temp |= ((t_uint16)src[0]) << 8;
|
||||
temp = ((std::uint16_t)src[1]);
|
||||
temp |= ((std::uint16_t)src[0]) << 8;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
extern t_uint32 bn_int_get(bn_int const src)
|
||||
extern std::uint32_t bn_int_get(bn_int const src)
|
||||
{
|
||||
t_uint32 temp;
|
||||
std::uint32_t temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
|
@ -287,17 +288,17 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
temp = ((t_uint32)src[0]);
|
||||
temp |= ((t_uint32)src[1]) << 8;
|
||||
temp |= ((t_uint32)src[2]) << 16;
|
||||
temp |= ((t_uint32)src[3]) << 24;
|
||||
temp = ((std::uint32_t)src[0]);
|
||||
temp |= ((std::uint32_t)src[1]) << 8;
|
||||
temp |= ((std::uint32_t)src[2]) << 16;
|
||||
temp |= ((std::uint32_t)src[3]) << 24;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
extern t_uint32 bn_int_nget(bn_int const src)
|
||||
extern std::uint32_t bn_int_nget(bn_int const src)
|
||||
{
|
||||
t_uint32 temp;
|
||||
std::uint32_t temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
|
@ -305,18 +306,55 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
temp = ((t_uint32)src[3]);
|
||||
temp |= ((t_uint32)src[2]) << 8;
|
||||
temp |= ((t_uint32)src[1]) << 16;
|
||||
temp |= ((t_uint32)src[0]) << 24;
|
||||
temp = ((std::uint32_t)src[3]);
|
||||
temp |= ((std::uint32_t)src[2]) << 8;
|
||||
temp |= ((std::uint32_t)src[1]) << 16;
|
||||
temp |= ((std::uint32_t)src[0]) << 24;
|
||||
return temp;
|
||||
}
|
||||
|
||||
extern std::uint64_t bn_long_get(bn_long const src)
|
||||
{
|
||||
std::uint64_t temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL src");
|
||||
return 0;
|
||||
}
|
||||
|
||||
temp = ((std::uint64_t)src[0]);
|
||||
temp |= ((std::uint64_t)src[1]) << 8;
|
||||
temp |= ((std::uint64_t)src[2]) << 16;
|
||||
temp |= ((std::uint64_t)src[3]) << 24;
|
||||
temp |= ((std::uint64_t)src[4]) << 32;
|
||||
temp |= ((std::uint64_t)src[5]) << 40;
|
||||
temp |= ((std::uint64_t)src[6]) << 48;
|
||||
temp |= ((std::uint64_t)src[7]) << 56;
|
||||
return temp;
|
||||
}
|
||||
|
||||
extern std::uint32_t bn_long_get_a(bn_long const src)
|
||||
{
|
||||
std::uint32_t temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL src");
|
||||
return 0;
|
||||
}
|
||||
|
||||
temp = ((std::uint32_t)src[4]);
|
||||
temp |= ((std::uint32_t)src[5]) << 8;
|
||||
temp |= ((std::uint32_t)src[6]) << 16;
|
||||
temp |= ((std::uint32_t)src[7]) << 24;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_T_LONG
|
||||
extern t_uint64 bn_long_get(bn_long const src)
|
||||
extern std::uint32_t bn_long_get_b(bn_long const src)
|
||||
{
|
||||
t_uint64 temp;
|
||||
std::uint32_t temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
|
@ -324,51 +362,10 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
temp = ((t_uint64)src[0]);
|
||||
temp |= ((t_uint64)src[1]) << 8;
|
||||
temp |= ((t_uint64)src[2]) << 16;
|
||||
temp |= ((t_uint64)src[3]) << 24;
|
||||
temp |= ((t_uint64)src[4]) << 32;
|
||||
temp |= ((t_uint64)src[5]) << 40;
|
||||
temp |= ((t_uint64)src[6]) << 48;
|
||||
temp |= ((t_uint64)src[7]) << 56;
|
||||
return temp;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
extern t_uint32 bn_long_get_a(bn_long const src)
|
||||
{
|
||||
t_uint32 temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL src");
|
||||
return 0;
|
||||
}
|
||||
|
||||
temp = ((t_uint32)src[4]);
|
||||
temp |= ((t_uint32)src[5]) << 8;
|
||||
temp |= ((t_uint32)src[6]) << 16;
|
||||
temp |= ((t_uint32)src[7]) << 24;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
extern t_uint32 bn_long_get_b(bn_long const src)
|
||||
{
|
||||
t_uint32 temp;
|
||||
|
||||
if (!src)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL src");
|
||||
return 0;
|
||||
}
|
||||
|
||||
temp = ((t_uint32)src[0]);
|
||||
temp |= ((t_uint32)src[1]) << 8;
|
||||
temp |= ((t_uint32)src[2]) << 16;
|
||||
temp |= ((t_uint32)src[3]) << 24;
|
||||
temp = ((std::uint32_t)src[0]);
|
||||
temp |= ((std::uint32_t)src[1]) << 8;
|
||||
temp |= ((std::uint32_t)src[2]) << 16;
|
||||
temp |= ((std::uint32_t)src[3]) << 24;
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
@ -376,7 +373,7 @@ namespace pvpgn
|
|||
/************************************************************/
|
||||
|
||||
|
||||
extern int bn_byte_set(bn_byte * dst, t_uint8 src)
|
||||
extern int bn_byte_set(bn_byte * dst, std::uint8_t src)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
|
@ -384,12 +381,12 @@ namespace pvpgn
|
|||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((src));
|
||||
(*dst)[0] = (std::uint8_t)((src));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern int bn_short_set(bn_short * dst, t_uint16 src)
|
||||
extern int bn_short_set(bn_short * dst, std::uint16_t src)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
|
@ -397,13 +394,13 @@ namespace pvpgn
|
|||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((src)& 0xff);
|
||||
(*dst)[1] = (unsigned char)((src >> 8));
|
||||
(*dst)[0] = (std::uint8_t)((src)& 0xff);
|
||||
(*dst)[1] = (std::uint8_t)((src >> 8));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern int bn_short_nset(bn_short * dst, t_uint16 src)
|
||||
extern int bn_short_nset(bn_short * dst, std::uint16_t src)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
|
@ -411,13 +408,13 @@ namespace pvpgn
|
|||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((src >> 8));
|
||||
(*dst)[1] = (unsigned char)((src)& 0xff);
|
||||
(*dst)[0] = (std::uint8_t)((src >> 8));
|
||||
(*dst)[1] = (std::uint8_t)((src)& 0xff);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern int bn_int_set(bn_int * dst, t_uint32 src)
|
||||
extern int bn_int_set(bn_int * dst, std::uint32_t src)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
|
@ -425,15 +422,15 @@ namespace pvpgn
|
|||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((src)& 0xff);
|
||||
(*dst)[1] = (unsigned char)((src >> 8) & 0xff);
|
||||
(*dst)[2] = (unsigned char)((src >> 16) & 0xff);
|
||||
(*dst)[3] = (unsigned char)((src >> 24));
|
||||
(*dst)[0] = (std::uint8_t)((src)& 0xff);
|
||||
(*dst)[1] = (std::uint8_t)((src >> 8) & 0xff);
|
||||
(*dst)[2] = (std::uint8_t)((src >> 16) & 0xff);
|
||||
(*dst)[3] = (std::uint8_t)((src >> 24));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern int bn_int_nset(bn_int * dst, t_uint32 src)
|
||||
extern int bn_int_nset(bn_int * dst, std::uint32_t src)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
|
@ -441,16 +438,34 @@ namespace pvpgn
|
|||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((src >> 24));
|
||||
(*dst)[1] = (unsigned char)((src >> 16) & 0xff);
|
||||
(*dst)[2] = (unsigned char)((src >> 8) & 0xff);
|
||||
(*dst)[3] = (unsigned char)((src)& 0xff);
|
||||
(*dst)[0] = (std::uint8_t)((src >> 24));
|
||||
(*dst)[1] = (std::uint8_t)((src >> 16) & 0xff);
|
||||
(*dst)[2] = (std::uint8_t)((src >> 8) & 0xff);
|
||||
(*dst)[3] = (std::uint8_t)((src)& 0xff);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int bn_long_set(bn_long * dst, std::uint64_t src)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (std::uint8_t)((src)& 0xff);
|
||||
(*dst)[1] = (std::uint8_t)((src >> 8) & 0xff);
|
||||
(*dst)[2] = (std::uint8_t)((src >> 16) & 0xff);
|
||||
(*dst)[3] = (std::uint8_t)((src >> 24) & 0xff);
|
||||
(*dst)[4] = (std::uint8_t)((src >> 32) & 0xff);
|
||||
(*dst)[5] = (std::uint8_t)((src >> 40) & 0xff);
|
||||
(*dst)[6] = (std::uint8_t)((src >> 48) & 0xff);
|
||||
(*dst)[7] = (std::uint8_t)((src >> 56));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_T_LONG
|
||||
extern int bn_long_set(bn_long * dst, t_uint64 src)
|
||||
extern int bn_long_nset(bn_long * dst, std::uint64_t src)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
|
@ -458,19 +473,38 @@ namespace pvpgn
|
|||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((src)& 0xff);
|
||||
(*dst)[1] = (unsigned char)((src >> 8) & 0xff);
|
||||
(*dst)[2] = (unsigned char)((src >> 16) & 0xff);
|
||||
(*dst)[3] = (unsigned char)((src >> 24) & 0xff);
|
||||
(*dst)[4] = (unsigned char)((src >> 32) & 0xff);
|
||||
(*dst)[5] = (unsigned char)((src >> 40) & 0xff);
|
||||
(*dst)[6] = (unsigned char)((src >> 48) & 0xff);
|
||||
(*dst)[7] = (unsigned char)((src >> 56));
|
||||
(*dst)[0] = (std::uint8_t)((src >> 56));
|
||||
(*dst)[1] = (std::uint8_t)((src >> 48) & 0xff);
|
||||
(*dst)[2] = (std::uint8_t)((src >> 40) & 0xff);
|
||||
(*dst)[3] = (std::uint8_t)((src >> 32) & 0xff);
|
||||
(*dst)[4] = (std::uint8_t)((src >> 24) & 0xff);
|
||||
(*dst)[5] = (std::uint8_t)((src >> 16) & 0xff);
|
||||
(*dst)[6] = (std::uint8_t)((src >> 8) & 0xff);
|
||||
(*dst)[7] = (std::uint8_t)((src)& 0xff);
|
||||
return 0;
|
||||
}
|
||||
|
||||
extern int bn_long_set_a_b(bn_long * dst, std::uint32_t srca, std::uint32_t srcb)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (std::uint8_t)((srcb)& 0xff);
|
||||
(*dst)[1] = (std::uint8_t)((srcb >> 8) & 0xff);
|
||||
(*dst)[2] = (std::uint8_t)((srcb >> 16) & 0xff);
|
||||
(*dst)[3] = (std::uint8_t)((srcb >> 24) & 0xff);
|
||||
(*dst)[4] = (std::uint8_t)((srca)& 0xff);
|
||||
(*dst)[5] = (std::uint8_t)((srca >> 8) & 0xff);
|
||||
(*dst)[6] = (std::uint8_t)((srca >> 16) & 0xff);
|
||||
(*dst)[7] = (std::uint8_t)((srca >> 24));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern int bn_long_nset(bn_long * dst, t_uint64 src)
|
||||
extern int bn_long_nset_a_b(bn_long * dst, std::uint32_t srca, std::uint32_t srcb)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
|
@ -478,55 +512,14 @@ namespace pvpgn
|
|||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((src >> 56));
|
||||
(*dst)[1] = (unsigned char)((src >> 48) & 0xff);
|
||||
(*dst)[2] = (unsigned char)((src >> 40) & 0xff);
|
||||
(*dst)[3] = (unsigned char)((src >> 32) & 0xff);
|
||||
(*dst)[4] = (unsigned char)((src >> 24) & 0xff);
|
||||
(*dst)[5] = (unsigned char)((src >> 16) & 0xff);
|
||||
(*dst)[6] = (unsigned char)((src >> 8) & 0xff);
|
||||
(*dst)[7] = (unsigned char)((src)& 0xff);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
extern int bn_long_set_a_b(bn_long * dst, t_uint32 srca, t_uint32 srcb)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((srcb)& 0xff);
|
||||
(*dst)[1] = (unsigned char)((srcb >> 8) & 0xff);
|
||||
(*dst)[2] = (unsigned char)((srcb >> 16) & 0xff);
|
||||
(*dst)[3] = (unsigned char)((srcb >> 24) & 0xff);
|
||||
(*dst)[4] = (unsigned char)((srca)& 0xff);
|
||||
(*dst)[5] = (unsigned char)((srca >> 8) & 0xff);
|
||||
(*dst)[6] = (unsigned char)((srca >> 16) & 0xff);
|
||||
(*dst)[7] = (unsigned char)((srca >> 24));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
extern int bn_long_nset_a_b(bn_long * dst, t_uint32 srca, t_uint32 srcb)
|
||||
{
|
||||
if (!dst)
|
||||
{
|
||||
eventlog(eventlog_level_error, __FUNCTION__, "got NULL dst");
|
||||
return -1;
|
||||
}
|
||||
|
||||
(*dst)[0] = (unsigned char)((srca >> 24));
|
||||
(*dst)[1] = (unsigned char)((srca >> 16) & 0xff);
|
||||
(*dst)[2] = (unsigned char)((srca >> 8) & 0xff);
|
||||
(*dst)[3] = (unsigned char)((srca)& 0xff);
|
||||
(*dst)[4] = (unsigned char)((srcb >> 24) & 0xff);
|
||||
(*dst)[5] = (unsigned char)((srcb >> 16) & 0xff);
|
||||
(*dst)[6] = (unsigned char)((srcb >> 8) & 0xff);
|
||||
(*dst)[7] = (unsigned char)((srcb)& 0xff);
|
||||
(*dst)[0] = (std::uint8_t)((srca >> 24));
|
||||
(*dst)[1] = (std::uint8_t)((srca >> 16) & 0xff);
|
||||
(*dst)[2] = (std::uint8_t)((srca >> 8) & 0xff);
|
||||
(*dst)[3] = (std::uint8_t)((srca)& 0xff);
|
||||
(*dst)[4] = (std::uint8_t)((srcb >> 24) & 0xff);
|
||||
(*dst)[5] = (std::uint8_t)((srcb >> 16) & 0xff);
|
||||
(*dst)[6] = (std::uint8_t)((srcb >> 8) & 0xff);
|
||||
(*dst)[7] = (std::uint8_t)((srcb)& 0xff);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -655,7 +648,7 @@ namespace pvpgn
|
|||
/************************************************************/
|
||||
|
||||
|
||||
extern int uint32_to_int(t_uint32 num)
|
||||
extern int uint32_to_int(std::uint32_t num)
|
||||
{
|
||||
if (num < (1UL << 30))
|
||||
return (int)num;
|
||||
|
|
|
@ -18,23 +18,15 @@
|
|||
#ifndef INCLUDED_BN_TYPE_TYPES
|
||||
#define INCLUDED_BN_TYPE_TYPES
|
||||
|
||||
#ifdef JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
#else
|
||||
# define JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
# undef JUST_NEED_TYPES
|
||||
#endif
|
||||
#include <cstdint>
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
typedef t_uint8 bn_basic;
|
||||
typedef bn_basic bn_byte[1];
|
||||
typedef bn_basic bn_short[2];
|
||||
typedef bn_basic bn_int[4];
|
||||
typedef bn_basic bn_long[8];
|
||||
|
||||
using bn_basic = std::uint8_t;
|
||||
using bn_byte = bn_basic[1];
|
||||
using bn_short = bn_basic[2];
|
||||
using bn_int = bn_basic[4];
|
||||
using bn_long = bn_basic[8];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -45,10 +37,6 @@ namespace pvpgn
|
|||
#ifndef INCLUDED_BN_TYPE_PROTOS
|
||||
#define INCLUDED_BN_TYPE_PROTOS
|
||||
|
||||
#define JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
#undef JUST_NEED_TYPES
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
|
@ -62,28 +50,24 @@ namespace pvpgn
|
|||
extern int bn_int_tag_set(bn_int * dst, char const * tag);
|
||||
extern int bn_long_tag_set(bn_long * dst, char const * tag);
|
||||
|
||||
extern t_uint8 bn_byte_get(bn_byte const src);
|
||||
extern t_uint16 bn_short_get(bn_short const src);
|
||||
extern t_uint16 bn_short_nget(bn_short const src);
|
||||
extern t_uint32 bn_int_get(bn_int const src);
|
||||
extern t_uint32 bn_int_nget(bn_int const src);
|
||||
#ifdef HAVE_T_UINT64
|
||||
extern t_uint64 bn_long_get(bn_long const src);
|
||||
#endif
|
||||
extern t_uint32 bn_long_get_a(bn_long const src);
|
||||
extern t_uint32 bn_long_get_b(bn_long const src);
|
||||
extern std::uint8_t bn_byte_get(bn_byte const src);
|
||||
extern std::uint16_t bn_short_get(bn_short const src);
|
||||
extern std::uint16_t bn_short_nget(bn_short const src);
|
||||
extern std::uint32_t bn_int_get(bn_int const src);
|
||||
extern std::uint32_t bn_int_nget(bn_int const src);
|
||||
extern std::uint64_t bn_long_get(bn_long const src);
|
||||
extern std::uint32_t bn_long_get_a(bn_long const src);
|
||||
extern std::uint32_t bn_long_get_b(bn_long const src);
|
||||
|
||||
extern int bn_byte_set(bn_byte * dst, t_uint8 src);
|
||||
extern int bn_short_set(bn_short * dst, t_uint16 src);
|
||||
extern int bn_short_nset(bn_short * dst, t_uint16 src);
|
||||
extern int bn_int_set(bn_int * dst, t_uint32 src);
|
||||
extern int bn_int_nset(bn_int * dst, t_uint32 src);
|
||||
#ifdef HAVE_T_UINT64
|
||||
extern int bn_long_set(bn_long * dst, t_uint64 src);
|
||||
extern int bn_long_nset(bn_long * dst, t_uint64 src);
|
||||
#endif
|
||||
extern int bn_long_set_a_b(bn_long * dst, t_uint32 srca, t_uint32 srcb);
|
||||
extern int bn_long_nset_a_b(bn_long * dst, t_uint32 srca, t_uint32 srcb);
|
||||
extern int bn_byte_set(bn_byte * dst, std::uint8_t src);
|
||||
extern int bn_short_set(bn_short * dst, std::uint16_t src);
|
||||
extern int bn_short_nset(bn_short * dst, std::uint16_t src);
|
||||
extern int bn_int_set(bn_int * dst, std::uint32_t src);
|
||||
extern int bn_int_nset(bn_int * dst, std::uint32_t src);
|
||||
extern int bn_long_set(bn_long * dst, std::uint64_t src);
|
||||
extern int bn_long_nset(bn_long * dst, std::uint64_t src);
|
||||
extern int bn_long_set_a_b(bn_long * dst, std::uint32_t srca, std::uint32_t srcb);
|
||||
extern int bn_long_nset_a_b(bn_long * dst, std::uint32_t srca, std::uint32_t srcb);
|
||||
|
||||
extern int bn_raw_set(void * dst, void const * src, unsigned int len);
|
||||
|
||||
|
@ -92,7 +76,7 @@ namespace pvpgn
|
|||
extern int bn_int_tag_eq(bn_int const src, char const * tag);
|
||||
extern int bn_long_tag_eq(bn_long const src, char const * tag);
|
||||
|
||||
extern int uint32_to_int(t_uint32 num);
|
||||
extern int uint32_to_int(std::uint32_t num);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -19,10 +19,10 @@
|
|||
#include "common/setup_before.h"
|
||||
#include "common/bnethash.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "compat/uint.h"
|
||||
#include "common/bn_type.h"
|
||||
#include "common/introtate.h"
|
||||
#include "common/eventlog.h"
|
||||
|
@ -36,10 +36,10 @@ namespace pvpgn
|
|||
do_blizzard_hash,
|
||||
do_sha1_hash
|
||||
} t_hash_variant;
|
||||
|
||||
|
||||
static void hash_init(t_hash * hash);
|
||||
static void do_hash(t_hash * hash, t_uint32 * tmp);
|
||||
static void hash_set_16(t_uint32 * dst, unsigned char const * src, unsigned int count, t_hash_variant hash_variant);
|
||||
static void do_hash(t_hash * hash, std::uint32_t * tmp);
|
||||
static void hash_set_16(std::uint32_t * dst, unsigned char const * src, unsigned int count, t_hash_variant hash_variant);
|
||||
|
||||
|
||||
static void hash_init(t_hash * hash)
|
||||
|
@ -52,10 +52,10 @@ namespace pvpgn
|
|||
}
|
||||
|
||||
|
||||
static void do_hash(t_hash * hash, t_uint32 * tmp, t_hash_variant hash_variant)
|
||||
static void do_hash(t_hash * hash, std::uint32_t * tmp, t_hash_variant hash_variant)
|
||||
{
|
||||
unsigned int i;
|
||||
t_uint32 a, b, c, d, e, g;
|
||||
std::uint32_t a, b, c, d, e, g;
|
||||
|
||||
for (i = 0; i < 64; i++)
|
||||
if (hash_variant == do_blizzard_hash)
|
||||
|
@ -123,7 +123,7 @@ namespace pvpgn
|
|||
* zeros. In case of SHA1 hash variant a binary 1 is appended after
|
||||
* the actual data.
|
||||
*/
|
||||
static void hash_set_16(t_uint32 * dst, unsigned char const * src, unsigned int count,
|
||||
static void hash_set_16(std::uint32_t * dst, unsigned char const * src, unsigned int count,
|
||||
t_hash_variant hash_variant)
|
||||
{
|
||||
unsigned int i;
|
||||
|
@ -135,49 +135,49 @@ namespace pvpgn
|
|||
|
||||
if (hash_variant == do_blizzard_hash) {
|
||||
if (pos < count)
|
||||
dst[i] |= ((t_uint32)src[pos]);
|
||||
dst[i] |= ((std::uint32_t)src[pos]);
|
||||
}
|
||||
else {
|
||||
if (pos < count)
|
||||
dst[i] |= ((t_uint32)src[pos]) << 24;
|
||||
dst[i] |= ((std::uint32_t)src[pos]) << 24;
|
||||
else if (pos == count)
|
||||
dst[i] |= ((t_uint32)0x80000000);
|
||||
dst[i] |= ((std::uint32_t)0x80000000);
|
||||
}
|
||||
pos++;
|
||||
|
||||
if (hash_variant == do_blizzard_hash) {
|
||||
if (pos < count)
|
||||
dst[i] |= ((t_uint32)src[pos]) << 8;
|
||||
dst[i] |= ((std::uint32_t)src[pos]) << 8;
|
||||
}
|
||||
else {
|
||||
if (pos < count)
|
||||
dst[i] |= ((t_uint32)src[pos]) << 16;
|
||||
dst[i] |= ((std::uint32_t)src[pos]) << 16;
|
||||
else if (pos == count)
|
||||
dst[i] |= ((t_uint32)0x800000);
|
||||
dst[i] |= ((std::uint32_t)0x800000);
|
||||
}
|
||||
pos++;
|
||||
|
||||
if (hash_variant == do_blizzard_hash) {
|
||||
if (pos < count)
|
||||
dst[i] |= ((t_uint32)src[pos]) << 16;
|
||||
dst[i] |= ((std::uint32_t)src[pos]) << 16;
|
||||
}
|
||||
else {
|
||||
if (pos < count)
|
||||
dst[i] |= ((t_uint32)src[pos]) << 8;
|
||||
dst[i] |= ((std::uint32_t)src[pos]) << 8;
|
||||
else if (pos == count)
|
||||
dst[i] |= ((t_uint32)0x8000);
|
||||
dst[i] |= ((std::uint32_t)0x8000);
|
||||
}
|
||||
pos++;
|
||||
|
||||
if (hash_variant == do_blizzard_hash) {
|
||||
if (pos < count)
|
||||
dst[i] |= ((t_uint32)src[pos]) << 24;
|
||||
dst[i] |= ((std::uint32_t)src[pos]) << 24;
|
||||
}
|
||||
else {
|
||||
if (pos < count)
|
||||
dst[i] |= ((t_uint32)src[pos]);
|
||||
dst[i] |= ((std::uint32_t)src[pos]);
|
||||
else if (pos == count)
|
||||
dst[i] |= ((t_uint32)0x80);
|
||||
dst[i] |= ((std::uint32_t)0x80);
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
|
@ -186,9 +186,9 @@ namespace pvpgn
|
|||
|
||||
extern int bnet_hash(t_hash * hashout, unsigned int size, void const * datain)
|
||||
{
|
||||
t_uint32 tmp[64 + 16];
|
||||
unsigned char const * data;
|
||||
unsigned int inc;
|
||||
std::uint32_t tmp[64 + 16];
|
||||
const unsigned char* data;
|
||||
unsigned int inc;
|
||||
|
||||
if (!hashout)
|
||||
{
|
||||
|
@ -221,9 +221,9 @@ namespace pvpgn
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void hash_set_length(t_uint32 * dst, unsigned int size){
|
||||
t_uint32 size_high = 0;
|
||||
t_uint32 size_low = 0;
|
||||
static void hash_set_length(std::uint32_t * dst, unsigned int size){
|
||||
std::uint32_t size_high = 0;
|
||||
std::uint32_t size_low = 0;
|
||||
unsigned int counter;
|
||||
for (counter = 0; counter < size; counter++){
|
||||
size_low += 8;
|
||||
|
@ -244,7 +244,7 @@ namespace pvpgn
|
|||
|
||||
extern int sha1_hash(t_hash * hashout, unsigned int size, void const * datain)
|
||||
{
|
||||
t_uint32 tmp[64 + 16];
|
||||
std::uint32_t tmp[64 + 16];
|
||||
unsigned char const * data;
|
||||
unsigned int inc;
|
||||
unsigned int orgSize;
|
||||
|
|
|
@ -19,19 +19,11 @@
|
|||
#ifndef INCLUDED_BNETHASH_TYPES
|
||||
#define INCLUDED_BNETHASH_TYPES
|
||||
|
||||
#ifdef JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
#else
|
||||
# define JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
# undef JUST_NEED_TYPES
|
||||
#endif
|
||||
#include <cstdint>
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
typedef t_uint32 t_hash[5];
|
||||
|
||||
using t_hash = std::uint32_t[5];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,23 +18,23 @@
|
|||
*/
|
||||
|
||||
#include "common/setup_before.h"
|
||||
#include "bnetsrp3.h"
|
||||
|
||||
#include <cassert>
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <cctype>
|
||||
#include <cassert>
|
||||
|
||||
#include "bnetsrp3.h"
|
||||
|
||||
#include "common/bigint.h"
|
||||
#include "common/bnethash.h"
|
||||
#include "common/eventlog.h"
|
||||
#include "common/util.h"
|
||||
#include "common/xalloc.h"
|
||||
#include "compat/uint.h"
|
||||
#include "common/xstring.h"
|
||||
|
||||
#include "common/setup_after.h"
|
||||
|
@ -42,7 +42,7 @@
|
|||
namespace pvpgn
|
||||
{
|
||||
|
||||
t_uint8 bnetsrp3_g = 0x2F;
|
||||
std::uint8_t bnetsrp3_g = 0x2F;
|
||||
|
||||
const unsigned char bnetsrp3_N[] = {
|
||||
0xF8, 0xFF, 0x1A, 0x8B, 0x61, 0x99, 0x18, 0x03,
|
||||
|
@ -172,12 +172,12 @@ namespace pvpgn
|
|||
BnetSRP3::getScrambler(BigInt& B) const
|
||||
{
|
||||
unsigned char raw_B[32];
|
||||
t_uint32 scrambler;
|
||||
std::uint32_t scrambler;
|
||||
t_hash hash;
|
||||
|
||||
B.getData(raw_B, 32, 4, false);
|
||||
sha1_hash(&hash, 32, raw_B);
|
||||
scrambler = *(t_uint32*)hash;
|
||||
scrambler = *(std::uint32_t*)hash;
|
||||
|
||||
return BigInt(scrambler);
|
||||
}
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#ifdef HAVE_EPOLL
|
||||
|
||||
#ifdef HAVE_SYS_EPOLL_H
|
||||
# include "compat/uint.h"
|
||||
# include <sys/epoll.h>
|
||||
#endif
|
||||
|
||||
|
|
|
@ -21,24 +21,15 @@
|
|||
#ifndef INCLUDED_TAG_TYPES
|
||||
#define INCLUDED_TAG_TYPES
|
||||
|
||||
#ifdef JUST_NEED_TYPES
|
||||
#include "compat/uint.h"
|
||||
#else
|
||||
#define JUST_NEED_TYPES
|
||||
#include "compat/uint.h"
|
||||
#undef JUST_NEED_TYPES
|
||||
#endif
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
typedef t_uint32 t_tag;
|
||||
typedef t_tag t_archtag;
|
||||
typedef t_tag t_clienttag;
|
||||
typedef t_tag t_gamelang;
|
||||
|
||||
using t_tag = std::uint32_t;
|
||||
using t_archtag = t_tag;
|
||||
using t_clienttag = t_tag;
|
||||
using t_gamelang = t_tag;
|
||||
}
|
||||
|
||||
typedef enum {
|
||||
|
|
|
@ -18,19 +18,9 @@
|
|||
#ifndef INCLUDED_WOLHASH_TYPES
|
||||
#define INCLUDED_WOLHASH_TYPES
|
||||
|
||||
#ifdef JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
#else
|
||||
# define JUST_NEED_TYPES
|
||||
# include "compat/uint.h"
|
||||
# undef JUST_NEED_TYPES
|
||||
#endif
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
typedef char t_wolhash[9];
|
||||
|
||||
using t_wolhash = char[9];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -5,4 +5,4 @@ add_library(compat
|
|||
rename.h send.h socket.h statmacros.h
|
||||
stdfileno.h strcasecmp.cpp strcasecmp.h strdup.cpp strdup.h
|
||||
strerror.cpp strerror.h strncasecmp.cpp strncasecmp.h strsep.cpp
|
||||
strsep.h termios.h uint.h uname.cpp uname.h)
|
||||
strsep.h termios.h uname.cpp uname.h)
|
|
@ -1,169 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2000 Ross Combs (rocombs@cs.nmsu.edu)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef INCLUDED_UINT_TYPES
|
||||
#define INCLUDED_UINT_TYPES
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
|
||||
# include <stdint.h>
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
typedef uint8_t t_uint8;
|
||||
typedef uint16_t t_uint16;
|
||||
typedef uint32_t t_uint32;
|
||||
typedef uint64_t t_uint64;
|
||||
|
||||
typedef int8_t t_int8;
|
||||
typedef int16_t t_int16;
|
||||
typedef int32_t t_int32;
|
||||
typedef int64_t t_int64;
|
||||
|
||||
}
|
||||
|
||||
# define HAVE_UINT64_T
|
||||
|
||||
#else
|
||||
#ifdef HAVE_MODE_ATTR
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
typedef unsigned int t_uint8 MODE_ATTR(__QI__);
|
||||
typedef unsigned int t_uint16 MODE_ATTR(__HI__);
|
||||
typedef unsigned int t_uint32 MODE_ATTR(__SI__);
|
||||
typedef unsigned int t_uint64 MODE_ATTR(__DI__); /* FIXME: I guess DI is always available... Is there a way to check? */
|
||||
typedef signed int t_int8 MODE_ATTR(__QI__);
|
||||
typedef signed int t_int16 MODE_ATTR(__HI__);
|
||||
typedef signed int t_int32 MODE_ATTR(__SI__);
|
||||
typedef signed int t_int64 MODE_ATTR(__DI__); /* FIXME: I guess DI is always available... Is there a way to check? */
|
||||
|
||||
}
|
||||
# define HAVE_UINT64_T
|
||||
|
||||
# else
|
||||
|
||||
# ifdef HAVE_LIMITS_H
|
||||
# include <limits.h>
|
||||
# endif
|
||||
# ifndef CHAR_BIT
|
||||
# define MY_CHAR_BIT 8 /* well, this is usually true :) */
|
||||
# else
|
||||
# define MY_CHAR_BIT CHAR_BIT
|
||||
# endif
|
||||
|
||||
namespace pvpgn
|
||||
{
|
||||
|
||||
# if SIZEOF_UNSIGNED_CHAR*MY_CHAR_BIT == 8
|
||||
typedef unsigned char t_uint8;
|
||||
# else
|
||||
# error "Unable to find 8-bit integer type"
|
||||
# endif
|
||||
|
||||
# if SIZEOF_SIGNED_CHAR*MY_CHAR_BIT == 8
|
||||
typedef signed char t_int8;
|
||||
# else
|
||||
# error "Unable to find 8-bit integer type"
|
||||
# endif
|
||||
|
||||
# if SIZEOF_UNSIGNED_SHORT*MY_CHAR_BIT == 16
|
||||
typedef unsigned short t_uint16;
|
||||
# else
|
||||
# if SIZEOF_UNSIGNED_INT*MY_CHAR_BIT == 16
|
||||
typedef unsigned int t_uint16;
|
||||
# else
|
||||
# error "Unable to find 16-bit integer type"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if SIZEOF_SIGNED_SHORT*MY_CHAR_BIT == 16
|
||||
typedef signed short t_int16;
|
||||
# else
|
||||
# if SIZEOF_SIGNED_INT*MY_CHAR_BIT == 16
|
||||
typedef signed int t_int16;
|
||||
# else
|
||||
# error "Unable to find 16-bit integer type"
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if SIZEOF_UNSIGNED_SHORT*MY_CHAR_BIT == 32
|
||||
typedef unsigned short t_uint32;
|
||||
# else
|
||||
# if SIZEOF_UNSIGNED_INT*MY_CHAR_BIT == 32
|
||||
typedef unsigned int t_uint32;
|
||||
# else
|
||||
# if SIZEOF_UNSIGNED_LONG*MY_CHAR_BIT == 32
|
||||
typedef unsigned long t_uint32;
|
||||
# else
|
||||
# error "Unable to find 32-bit integer type"
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if SIZEOF_SIGNED_SHORT*MY_CHAR_BIT == 32
|
||||
typedef signed short t_int32;
|
||||
# else
|
||||
# if SIZEOF_SIGNED_INT*MY_CHAR_BIT == 32
|
||||
typedef signed int t_int32;
|
||||
# else
|
||||
# if SIZEOF_SIGNED_LONG*MY_CHAR_BIT == 32
|
||||
typedef signed long t_int32;
|
||||
# else
|
||||
# error "Unable to find 32-bit integer type"
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if SIZEOF_UNSIGNED_INT*MY_CHAR_BIT == 64
|
||||
typedef unsigned int t_uint64;
|
||||
# define HAVE_UINT64_T
|
||||
# else
|
||||
# if SIZEOF_UNSIGNED_LONG*MY_CHAR_BIT == 64
|
||||
typedef unsigned long t_uint64;
|
||||
# define HAVE_UINT64_T
|
||||
# else
|
||||
# if SIZEOF_UNSIGNED_LONG_LONG*MY_CHAR_BIT == 64
|
||||
typedef unsigned long long t_uint64;
|
||||
# define HAVE_UINT64_T
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# if SIZEOF_SIGNED_INT*MY_CHAR_BIT == 64
|
||||
typedef signed int t_int64;
|
||||
# define HAVE_INT64_T
|
||||
# else
|
||||
# if SIZEOF_SIGNED_LONG*MY_CHAR_BIT == 64
|
||||
typedef signed long t_int64;
|
||||
# define HAVE_INT64_T
|
||||
# else
|
||||
# if SIZEOF_SIGNED_LONG_LONG*MY_CHAR_BIT == 64
|
||||
typedef signed long long t_int64;
|
||||
# define HAVE_INT64_T
|
||||
# endif
|
||||
# endif
|
||||
# endif
|
||||
|
||||
}
|
||||
|
||||
# undef MY_CHAR_BIT
|
||||
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -19,14 +19,13 @@
|
|||
|
||||
#include "common/bigint.h"
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "common/xalloc.h"
|
||||
|
||||
#include "compat/uint.h"
|
||||
|
||||
#include "common/setup_after.h"
|
||||
|
||||
using namespace pvpgn;
|
||||
|
@ -44,15 +43,15 @@ void constructorTests()
|
|||
assert(number->toHexString() == "00");
|
||||
delete number;
|
||||
|
||||
number = new BigInt((t_uint8)0xFF);
|
||||
number = new BigInt((std::uint8_t)0xFF);
|
||||
assert(number->toHexString() == "ff");
|
||||
delete number;
|
||||
|
||||
number = new BigInt((t_uint16)0xFFFF);
|
||||
number = new BigInt((std::uint16_t)0xFFFF);
|
||||
assert(number->toHexString() == "ffff");
|
||||
delete number;
|
||||
|
||||
number = new BigInt((t_uint32)0xFFFFFFFF);
|
||||
number = new BigInt((std::uint32_t)0xFFFFFFFF);
|
||||
assert(number->toHexString() == "ffffffff");
|
||||
delete number;
|
||||
|
||||
|
@ -79,45 +78,45 @@ void getDataTests()
|
|||
assert(data[i] = data4[i]);
|
||||
}
|
||||
xfree(data);
|
||||
data = BigInt((t_uint32)0x12345678).getData(3);
|
||||
assert(BigInt(data, 3) == BigInt((t_uint32)0x345678));
|
||||
data = BigInt((std::uint32_t)0x12345678).getData(3);
|
||||
assert(BigInt(data, 3) == BigInt((std::uint32_t)0x345678));
|
||||
xfree(data);
|
||||
data = BigInt((t_uint32)0x12345678).getData(2);
|
||||
assert(BigInt(data, 2) == BigInt((t_uint16)0x5678));
|
||||
data = BigInt((std::uint32_t)0x12345678).getData(2);
|
||||
assert(BigInt(data, 2) == BigInt((std::uint16_t)0x5678));
|
||||
xfree(data);
|
||||
data = BigInt((t_uint32)0x12345678).getData(1);
|
||||
assert(BigInt(data, 1) == BigInt((t_uint8)0x78));
|
||||
data = BigInt((std::uint32_t)0x12345678).getData(1);
|
||||
assert(BigInt(data, 1) == BigInt((std::uint8_t)0x78));
|
||||
xfree(data);
|
||||
}
|
||||
|
||||
void compareOperatorsTests()
|
||||
{
|
||||
// std::cout << __FUNCTION__ << "\n";
|
||||
assert(BigInt((t_uint32)0x12345678) == BigInt(data3, 4));
|
||||
assert(BigInt((t_uint16)0x27a2) < BigInt((t_uint16)0x9876));
|
||||
assert(BigInt() < BigInt((t_uint16)0x9876));
|
||||
assert(BigInt((t_uint16)0x9876) > BigInt());
|
||||
assert(BigInt((std::uint32_t)0x12345678) == BigInt(data3, 4));
|
||||
assert(BigInt((std::uint16_t)0x27a2) < BigInt((std::uint16_t)0x9876));
|
||||
assert(BigInt() < BigInt((std::uint16_t)0x9876));
|
||||
assert(BigInt((std::uint16_t)0x9876) > BigInt());
|
||||
}
|
||||
|
||||
void addTests()
|
||||
{
|
||||
// std::cout << __FUNCTION__ << "\n";
|
||||
assert(BigInt((t_uint32)0x12344321) + BigInt((t_uint32)0x43211234) == BigInt((t_uint32)0x55555555));
|
||||
assert(BigInt((t_uint16)0xFFFF) + BigInt((t_uint8)0x01) == BigInt((t_uint32)0x00010000));
|
||||
assert(BigInt((std::uint32_t)0x12344321) + BigInt((std::uint32_t)0x43211234) == BigInt((std::uint32_t)0x55555555));
|
||||
assert(BigInt((std::uint16_t)0xFFFF) + BigInt((std::uint8_t)0x01) == BigInt((std::uint32_t)0x00010000));
|
||||
}
|
||||
|
||||
void subTests()
|
||||
{
|
||||
// std::cout << __FUNCTION__ << "\n";
|
||||
assert(BigInt((t_uint32)0x00010000) - BigInt((t_uint8)0x01) == BigInt((t_uint16)0xFFFF));
|
||||
assert(BigInt((t_uint32)0x12345678) - BigInt((t_uint16)0x9876) == BigInt((t_uint32)0x1233BE02));
|
||||
assert(BigInt((t_uint8)0x10) - BigInt((t_uint8)0xFF) == BigInt((t_uint8)0x00));
|
||||
assert(BigInt((std::uint32_t)0x00010000) - BigInt((std::uint8_t)0x01) == BigInt((std::uint16_t)0xFFFF));
|
||||
assert(BigInt((std::uint32_t)0x12345678) - BigInt((std::uint16_t)0x9876) == BigInt((std::uint32_t)0x1233BE02));
|
||||
assert(BigInt((std::uint8_t)0x10) - BigInt((std::uint8_t)0xFF) == BigInt((std::uint8_t)0x00));
|
||||
}
|
||||
|
||||
void mulTests()
|
||||
{
|
||||
// std::cout << __FUNCTION__ << "\n";
|
||||
assert(BigInt((t_uint8)0x02) * BigInt((t_uint8)0xff) == BigInt((t_uint16)0x01fe));
|
||||
assert(BigInt((std::uint8_t)0x02) * BigInt((std::uint8_t)0xff) == BigInt((std::uint16_t)0x01fe));
|
||||
const unsigned char data4[] = { 0x01, 0x4b, 0x66, 0xdc, 0x1d, 0xf4, 0xd8, 0x40 };
|
||||
assert(BigInt(data3, 4) * BigInt(data3, 4) == BigInt(data4, 8));
|
||||
}
|
||||
|
@ -125,18 +124,18 @@ void mulTests()
|
|||
void divTests()
|
||||
{
|
||||
// std::cout << __FUNCTION__ << "\n";
|
||||
assert(BigInt((t_uint16)0x9876) / BigInt((t_uint32)0x98765432) == BigInt());
|
||||
assert(BigInt((t_uint32)0x1e0f7fbc) / BigInt((t_uint16)0x1e2f) == BigInt((t_uint16)0xfef4));
|
||||
assert(BigInt((t_uint32)0x01000000) / BigInt((t_uint32)0x00FFFFFF) == BigInt((t_uint8)0x01));
|
||||
assert(BigInt(data4, 16) / BigInt((t_uint8)0x02) > BigInt());
|
||||
assert(BigInt((std::uint16_t)0x9876) / BigInt((std::uint32_t)0x98765432) == BigInt());
|
||||
assert(BigInt((std::uint32_t)0x1e0f7fbc) / BigInt((std::uint16_t)0x1e2f) == BigInt((std::uint16_t)0xfef4));
|
||||
assert(BigInt((std::uint32_t)0x01000000) / BigInt((std::uint32_t)0x00FFFFFF) == BigInt((std::uint8_t)0x01));
|
||||
assert(BigInt(data4, 16) / BigInt((std::uint8_t)0x02) > BigInt());
|
||||
}
|
||||
|
||||
void modTests()
|
||||
{
|
||||
// std::cout << __FUNCTION__ << "\n";
|
||||
assert(BigInt((t_uint32)0x1e0f7fbc) % BigInt((t_uint16)0x1e2f) == BigInt((t_uint16)0x18f0));
|
||||
assert(BigInt((t_uint32)0x01000000) % BigInt((t_uint32)0x00FFFFFF) == BigInt((t_uint8)0x01));
|
||||
assert(BigInt((t_uint32)0x80000000) % BigInt((t_uint32)0xFFFFFFFF) == BigInt((t_uint32)0x80000000));
|
||||
assert(BigInt((std::uint32_t)0x1e0f7fbc) % BigInt((std::uint16_t)0x1e2f) == BigInt((std::uint16_t)0x18f0));
|
||||
assert(BigInt((std::uint32_t)0x01000000) % BigInt((std::uint32_t)0x00FFFFFF) == BigInt((std::uint8_t)0x01));
|
||||
assert(BigInt((std::uint32_t)0x80000000) % BigInt((std::uint32_t)0xFFFFFFFF) == BigInt((std::uint32_t)0x80000000));
|
||||
|
||||
}
|
||||
|
||||
|
@ -153,9 +152,9 @@ void randTests()
|
|||
void powmTests()
|
||||
{
|
||||
// std::cout << __FUNCTION__ << "\n";
|
||||
assert(BigInt((t_uint8)0x02).powm(BigInt((t_uint8)0x1F), BigInt((t_uint32)0xFFFFFFFF)) == BigInt((t_uint32)0x80000000));
|
||||
assert(BigInt((std::uint8_t)0x02).powm(BigInt((std::uint8_t)0x1F), BigInt((std::uint32_t)0xFFFFFFFF)) == BigInt((std::uint32_t)0x80000000));
|
||||
BigInt mod = BigInt::random(32);
|
||||
assert(BigInt((t_uint8)0x2f).powm(BigInt::random(32), mod) < mod);
|
||||
assert(BigInt((std::uint8_t)0x2f).powm(BigInt::random(32), mod) < mod);
|
||||
}
|
||||
|
||||
int main()
|
||||
|
|
Loading…
Add table
Reference in a new issue