mirror of
https://github.com/EQEmu/Server.git
synced 2025-12-12 01:11:29 +00:00
For windows compile, moved definve of va_copy
This commit is contained in:
parent
9a139a7604
commit
b19755a313
@ -1,19 +1,19 @@
|
|||||||
/* EQEMu: Everquest Server Emulator
|
/* EQEMu: Everquest Server Emulator
|
||||||
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
|
Copyright (C) 2001-2002 EQEMu Development Team (http://eqemu.org)
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation; version 2 of the License.
|
the Free Software Foundation; version 2 of the License.
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
but WITHOUT ANY WARRANTY except by those people which sell it, which
|
||||||
are required to give you total support for your newly bought product;
|
are required to give you total support for your newly bought product;
|
||||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||||
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
#include "../common/debug.h"
|
#include "../common/debug.h"
|
||||||
#include "MiscFunctions.h"
|
#include "MiscFunctions.h"
|
||||||
@ -47,8 +47,8 @@ using namespace std;
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#ifdef FREEBSD //Timothy Whitman - January 7, 2003
|
#ifdef FREEBSD //Timothy Whitman - January 7, 2003
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#endif
|
#endif
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -56,10 +56,6 @@ using namespace std;
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef va_copy
|
|
||||||
#define va_copy(d,s) ((d) = (s))
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static bool WELLRNG_init = false;
|
static bool WELLRNG_init = false;
|
||||||
static int state_i = 0;
|
static int state_i = 0;
|
||||||
static unsigned int STATE[R];
|
static unsigned int STATE[R];
|
||||||
@ -80,8 +76,8 @@ void CoutTimestamp(bool ms) {
|
|||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
gmt_t = gmtime(&rawtime);
|
gmt_t = gmtime(&rawtime);
|
||||||
|
|
||||||
struct timeval read_time;
|
struct timeval read_time;
|
||||||
gettimeofday(&read_time,0);
|
gettimeofday(&read_time,0);
|
||||||
|
|
||||||
cout << (gmt_t->tm_year + 1900) << "/" << setw(2) << setfill('0') << (gmt_t->tm_mon + 1) << "/" << setw(2) << setfill('0') << gmt_t->tm_mday << " " << setw(2) << setfill('0') << gmt_t->tm_hour << ":" << setw(2) << setfill('0') << gmt_t->tm_min << ":" << setw(2) << setfill('0') << gmt_t->tm_sec;
|
cout << (gmt_t->tm_year + 1900) << "/" << setw(2) << setfill('0') << (gmt_t->tm_mon + 1) << "/" << setw(2) << setfill('0') << gmt_t->tm_mday << " " << setw(2) << setfill('0') << gmt_t->tm_hour << ":" << setw(2) << setfill('0') << gmt_t->tm_min << ":" << setw(2) << setfill('0') << gmt_t->tm_sec;
|
||||||
if (ms)
|
if (ms)
|
||||||
@ -117,7 +113,7 @@ uint32 ResolveIP(const char* hostname, char* errbuf) {
|
|||||||
snprintf(errbuf, ERRBUF_SIZE, "ResolveIP(): hostname == 0");
|
snprintf(errbuf, ERRBUF_SIZE, "ResolveIP(): hostname == 0");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
struct sockaddr_in server_sin;
|
struct sockaddr_in server_sin;
|
||||||
#ifdef _WINDOWS
|
#ifdef _WINDOWS
|
||||||
PHOSTENT phostent = nullptr;
|
PHOSTENT phostent = nullptr;
|
||||||
#else
|
#else
|
||||||
@ -197,7 +193,7 @@ int MakeRandomInt(int low, int high)
|
|||||||
return(low);
|
return(low);
|
||||||
|
|
||||||
//return (rand()%(high-low+1) + (low));
|
//return (rand()%(high-low+1) + (low));
|
||||||
if(!WELLRNG_init) {
|
if(!WELLRNG_init) {
|
||||||
WELLRNG_init = true;
|
WELLRNG_init = true;
|
||||||
oneseed( rnd_hash( time(nullptr), clock() ) );
|
oneseed( rnd_hash( time(nullptr), clock() ) );
|
||||||
WELLRNG19937 = case_1;
|
WELLRNG19937 = case_1;
|
||||||
@ -215,7 +211,7 @@ double MakeRandomFloat(double low, double high)
|
|||||||
return(low);
|
return(low);
|
||||||
|
|
||||||
//return (rand() / (double)RAND_MAX * (high - low) + low);
|
//return (rand() / (double)RAND_MAX * (high - low) + low);
|
||||||
if(!WELLRNG_init) {
|
if(!WELLRNG_init) {
|
||||||
WELLRNG_init = true;
|
WELLRNG_init = true;
|
||||||
oneseed( rnd_hash( time(nullptr), clock() ) );
|
oneseed( rnd_hash( time(nullptr), clock() ) );
|
||||||
WELLRNG19937 = case_1;
|
WELLRNG19937 = case_1;
|
||||||
@ -225,41 +221,41 @@ double MakeRandomFloat(double low, double high)
|
|||||||
|
|
||||||
uint32 rnd_hash( time_t t, clock_t c )
|
uint32 rnd_hash( time_t t, clock_t c )
|
||||||
{
|
{
|
||||||
// Get a uint32 from t and c
|
// Get a uint32 from t and c
|
||||||
// Better than uint32(x) in case x is floating point in [0,1]
|
// Better than uint32(x) in case x is floating point in [0,1]
|
||||||
// Based on code by Lawrence Kirby (fred@genesis.demon.co.uk)
|
// Based on code by Lawrence Kirby (fred@genesis.demon.co.uk)
|
||||||
|
|
||||||
static uint32 differ = 0; // guarantee time-based seeds will change
|
static uint32 differ = 0; // guarantee time-based seeds will change
|
||||||
|
|
||||||
uint32 h1 = 0;
|
uint32 h1 = 0;
|
||||||
unsigned char *p = (unsigned char *) &t;
|
unsigned char *p = (unsigned char *) &t;
|
||||||
for( size_t i = 0; i < sizeof(t); ++i )
|
for( size_t i = 0; i < sizeof(t); ++i )
|
||||||
{
|
{
|
||||||
h1 *= 255 + 2U;
|
h1 *= 255 + 2U;
|
||||||
h1 += p[i];
|
h1 += p[i];
|
||||||
}
|
}
|
||||||
uint32 h2 = 0;
|
uint32 h2 = 0;
|
||||||
p = (unsigned char *) &c;
|
p = (unsigned char *) &c;
|
||||||
for( size_t j = 0; j < sizeof(c); ++j )
|
for( size_t j = 0; j < sizeof(c); ++j )
|
||||||
{
|
{
|
||||||
h2 *= 255 + 2U;
|
h2 *= 255 + 2U;
|
||||||
h2 += p[j];
|
h2 += p[j];
|
||||||
}
|
}
|
||||||
return ( h1 + differ++ ) ^ h2;
|
return ( h1 + differ++ ) ^ h2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void oneseed( const uint32 seed )
|
void oneseed( const uint32 seed )
|
||||||
{
|
{
|
||||||
// Initialize generator state with seed
|
// Initialize generator state with seed
|
||||||
// See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
|
// See Knuth TAOCP Vol 2, 3rd Ed, p.106 for multiplier.
|
||||||
// In previous versions, most significant bits (MSBs) of the seed affect
|
// In previous versions, most significant bits (MSBs) of the seed affect
|
||||||
// only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.
|
// only MSBs of the state array. Modified 9 Jan 2002 by Makoto Matsumoto.
|
||||||
register int j = 0;
|
register int j = 0;
|
||||||
STATE[j] = seed & 0xffffffffUL;
|
STATE[j] = seed & 0xffffffffUL;
|
||||||
for (j = 1; j < R; j++)
|
for (j = 1; j < R; j++)
|
||||||
{
|
{
|
||||||
STATE[j] = ( 1812433253UL * ( STATE[j-1] ^ (STATE[j-1] >> 30) ) + j ) & 0xffffffffUL;
|
STATE[j] = ( 1812433253UL * ( STATE[j-1] ^ (STATE[j-1] >> 30) ) + j ) & 0xffffffffUL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WELL RNG code
|
// WELL RNG code
|
||||||
@ -307,7 +303,7 @@ static unsigned int case_3 (void){
|
|||||||
newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1);
|
newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1);
|
||||||
state_i--;
|
state_i--;
|
||||||
if (state_i + M1 < R)
|
if (state_i + M1 < R)
|
||||||
WELLRNG19937 = case_5;
|
WELLRNG19937 = case_5;
|
||||||
return (STATE[state_i] ^ (newVM2Over & BITMASK));
|
return (STATE[state_i] ^ (newVM2Over & BITMASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,7 +316,7 @@ static unsigned int case_4 (void){
|
|||||||
newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1);
|
newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1);
|
||||||
state_i--;
|
state_i--;
|
||||||
if (state_i + M3 < R)
|
if (state_i + M3 < R)
|
||||||
WELLRNG19937 = case_6;
|
WELLRNG19937 = case_6;
|
||||||
return (STATE[state_i] ^ (newVM2 & BITMASK));
|
return (STATE[state_i] ^ (newVM2 & BITMASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +329,7 @@ static unsigned int case_5 (void){
|
|||||||
newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1);
|
newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1);
|
||||||
state_i--;
|
state_i--;
|
||||||
if (state_i + M2 < R)
|
if (state_i + M2 < R)
|
||||||
WELLRNG19937 = case_4;
|
WELLRNG19937 = case_4;
|
||||||
return (STATE[state_i] ^ (newVM2Over & BITMASK));
|
return (STATE[state_i] ^ (newVM2Over & BITMASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,7 +342,7 @@ static unsigned int case_6 (void){
|
|||||||
newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1);
|
newV0 = MAT1 (z0) ^ MAT0NEG (-9, z1) ^ MAT0NEG (-21, z2) ^ MAT0POS (21, newV1);
|
||||||
state_i--;
|
state_i--;
|
||||||
if (state_i == 1)
|
if (state_i == 1)
|
||||||
WELLRNG19937 = case_2;
|
WELLRNG19937 = case_2;
|
||||||
return (STATE[state_i] ^ (newVM2 & BITMASK));
|
return (STATE[state_i] ^ (newVM2 & BITMASK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,9 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef va_copy
|
||||||
|
#define va_copy(d,s) ((d) = (s))
|
||||||
|
#endif
|
||||||
|
|
||||||
// original source:
|
// original source:
|
||||||
// https://github.com/facebook/folly/blob/master/folly/String.cpp
|
// https://github.com/facebook/folly/blob/master/folly/String.cpp
|
||||||
@ -110,50 +113,50 @@ bool strn0cpyt(char* dest, const char* source, uint32 size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *MakeUpperString(const char *source) {
|
const char *MakeUpperString(const char *source) {
|
||||||
static char str[128];
|
static char str[128];
|
||||||
if (!source)
|
if (!source)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
MakeUpperString(source, str);
|
MakeUpperString(source, str);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakeUpperString(const char *source, char *target) {
|
void MakeUpperString(const char *source, char *target) {
|
||||||
if (!source || !target) {
|
if (!source || !target) {
|
||||||
*target=0;
|
*target=0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (*source)
|
while (*source)
|
||||||
{
|
{
|
||||||
*target = toupper(*source);
|
*target = toupper(*source);
|
||||||
target++;source++;
|
target++;source++;
|
||||||
}
|
}
|
||||||
*target = 0;
|
*target = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *MakeLowerString(const char *source) {
|
const char *MakeLowerString(const char *source) {
|
||||||
static char str[128];
|
static char str[128];
|
||||||
if (!source)
|
if (!source)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
MakeLowerString(source, str);
|
MakeLowerString(source, str);
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MakeLowerString(const char *source, char *target) {
|
void MakeLowerString(const char *source, char *target) {
|
||||||
if (!source || !target) {
|
if (!source || !target) {
|
||||||
*target=0;
|
*target=0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (*source)
|
while (*source)
|
||||||
{
|
{
|
||||||
*target = tolower(*source);
|
*target = tolower(*source);
|
||||||
target++;source++;
|
target++;source++;
|
||||||
}
|
}
|
||||||
*target = 0;
|
*target = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MakeAnyLenString(char** ret, const char* format, ...) {
|
int MakeAnyLenString(char** ret, const char* format, ...) {
|
||||||
int buf_len = 128;
|
int buf_len = 128;
|
||||||
int chars = -1;
|
int chars = -1;
|
||||||
va_list argptr, tmpargptr;
|
va_list argptr, tmpargptr;
|
||||||
va_start(argptr, format);
|
va_start(argptr, format);
|
||||||
while (chars == -1 || chars >= buf_len) {
|
while (chars == -1 || chars >= buf_len) {
|
||||||
@ -175,7 +178,7 @@ uint32 AppendAnyLenString(char** ret, uint32* bufsize, uint32* strlen, const cha
|
|||||||
*bufsize = 256;
|
*bufsize = 256;
|
||||||
if (*ret == 0)
|
if (*ret == 0)
|
||||||
*strlen = 0;
|
*strlen = 0;
|
||||||
int chars = -1;
|
int chars = -1;
|
||||||
char* oldret = 0;
|
char* oldret = 0;
|
||||||
va_list argptr, tmpargptr;
|
va_list argptr, tmpargptr;
|
||||||
va_start(argptr, format);
|
va_start(argptr, format);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user