开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 0 Fork 1

SpringJoy/server

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
development
分支 (6)
标签 (34)
development
release
spellextract
progression
autoptr_replace
Giperion
database-5
1.3.3.1
1.3.3
1.3.2
1.3.1
1.3
1.2.6.2
1.2.6.1
1.2.6
1.2.5.2
1.2.5.1
1.2.5
1.2.4.1
1.2.4
1.2.3
1.2.2
database-1.0
release-1.2.1.1
release-1.2.1
release-1.2
development
分支 (6)
标签 (34)
development
release
spellextract
progression
autoptr_replace
Giperion
database-5
1.3.3.1
1.3.3
1.3.2
1.3.1
1.3
1.2.6.2
1.2.6.1
1.2.6
1.2.5.2
1.2.5.1
1.2.5
1.2.4.1
1.2.4
1.2.3
1.2.2
database-1.0
release-1.2.1.1
release-1.2.1
release-1.2
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
development
分支 (6)
标签 (34)
development
release
spellextract
progression
autoptr_replace
Giperion
database-5
1.3.3.1
1.3.3
1.3.2
1.3.1
1.3
1.2.6.2
1.2.6.1
1.2.6
1.2.5.2
1.2.5.1
1.2.5
1.2.4.1
1.2.4
1.2.3
1.2.2
database-1.0
release-1.2.1.1
release-1.2.1
release-1.2
server
/
src
/
shared
/
Util.cpp
server
/
src
/
shared
/
Util.cpp
Util.cpp 13.37 KB
一键复制 编辑 原始数据 按行查看 历史
Staden 提交于 2017年05月12日 06:38 +08:00 . Revert "Fix ACE_TSS usage (#664)"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
/*
* Copyright (C) 2005-2011 MaNGOS <http://getmangos.com/>
* Copyright (C) 2009-2011 MaNGOSZero <https://github.com/mangos/zero>
* Copyright (C) 2011-2016 Nostalrius <https://nostalrius.org>
* Copyright (C) 2016-2017 Elysium Project <https://github.com/elysium-project>
*
* 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
*/
#include "Util.h"
#include "Timer.h"
#include "utf8cpp/utf8.h"
#include "mersennetwister/MersenneTwister.h"
#include <ace/TSS_T.h>
#include <ace/OS_NS_arpa_inet.h>
typedef ACE_TSS<MTRand> MTRandTSS;
static MTRandTSS mtRand;
Tokenizer::Tokenizer(const std::string &src, const char sep, uint32 vectorReserve)
{
m_str = new char[src.length() + 1];
memcpy(m_str, src.c_str(), src.length() + 1);
if (vectorReserve)
m_storage.reserve(vectorReserve);
char* posold = m_str;
char* posnew = m_str;
for (;;)
{
if (*posnew == sep)
{
m_storage.push_back(posold);
posold = posnew + 1;
*posnew = '0円';
}
else if (*posnew == '0円')
{
// Hack like, but the old code accepted these kind of broken strings,
// so changing it would break other things
if (posold != posnew)
m_storage.push_back(posold);
break;
}
++posnew;
}
}
static ACE_Time_Value g_SystemTickTime = ACE_OS::gettimeofday();
uint32 WorldTimer::m_iTime = 0;
uint32 WorldTimer::m_iPrevTime = 0;
uint32 WorldTimer::tickTime() { return m_iTime; }
uint32 WorldTimer::tickPrevTime() { return m_iPrevTime; }
uint32 WorldTimer::tick()
{
//save previous world tick time
m_iPrevTime = m_iTime;
//get the new one and don't forget to persist current system time in m_SystemTickTime
m_iTime = WorldTimer::getMSTime_internal(true);
//return tick diff
return getMSTimeDiff(m_iPrevTime, m_iTime);
}
uint32 WorldTimer::getMSTime()
{
return getMSTime_internal();
}
uint32 WorldTimer::getMSTime_internal(bool savetime /*= false*/)
{
//get current time
const ACE_Time_Value currTime = ACE_OS::gettimeofday();
//calculate time diff between two world ticks
//special case: curr_time < old_time - we suppose that our time has not ticked at all
//this should be constant value otherwise it is possible that our time can start ticking backwards until next world tick!!!
uint64 diff = 0;
(currTime - g_SystemTickTime).msec(diff);
//lets calculate current world time
uint32 iRes = uint32(diff % UI64LIT(0x00000000FFFFFFFF));
return iRes;
}
//////////////////////////////////////////////////////////////////////////
int32 irand (int32 min, int32 max)
{
return int32 (mtRand->randInt (max - min)) + min;
}
uint32 urand (uint32 min, uint32 max)
{
return mtRand->randInt (max - min) + min;
}
float frand (float min, float max)
{
return mtRand->randExc (max - min) + min;
}
int32 rand32 ()
{
return mtRand->randInt ();
}
double rand_norm(void)
{
return mtRand->randExc ();
}
float rand_norm_f(void)
{
return (float)mtRand->randExc ();
}
double rand_chance (void)
{
return mtRand->randExc (100.0);
}
float rand_chance_f(void)
{
return (float)mtRand->randExc (100.0);
}
Milliseconds randtime(Milliseconds const& min, Milliseconds const& max)
{
long long diff = max.count() - min.count();
MANGOS_ASSERT(diff >= 0);
MANGOS_ASSERT(diff <= (uint32)-1);
return min + Milliseconds(urand(0, diff));
}
Tokens StrSplit(const std::string &src, const std::string &sep)
{
Tokens r;
std::string s;
for (std::string::const_iterator i = src.begin(); i != src.end(); i++)
{
if (sep.find(*i) != std::string::npos)
{
if (s.length()) r.push_back(s);
s = "";
}
else
{
s += *i;
}
}
if (s.length()) r.push_back(s);
return r;
}
uint32 GetUInt32ValueFromArray(Tokens const& data, uint16 index)
{
if(index >= data.size())
return 0;
return (uint32)atoi(data[index].c_str());
}
float GetFloatValueFromArray(Tokens const& data, uint16 index)
{
float result;
uint32 temp = GetUInt32ValueFromArray(data,index);
memcpy(&result, &temp, sizeof(result));
return result;
}
void stripLineInvisibleChars(std::string &str)
{
static std::string invChars = " \t7円\n";
size_t wpos = 0;
bool space = false;
for(size_t pos = 0; pos < str.size(); ++pos)
{
if(invChars.find(str[pos])!=std::string::npos)
{
if(!space)
{
str[wpos++] = ' ';
space = true;
}
}
else
{
if(wpos!=pos)
str[wpos++] = str[pos];
else
++wpos;
space = false;
}
}
if(wpos < str.size())
str.erase(wpos,str.size());
}
std::string secsToTimeString(time_t timeInSecs, bool shortText, bool hoursOnly)
{
time_t secs = timeInSecs % MINUTE;
time_t minutes = timeInSecs % HOUR / MINUTE;
time_t hours = timeInSecs % DAY / HOUR;
time_t days = timeInSecs / DAY;
std::ostringstream ss;
if(days)
{
ss << days;
if (shortText)
ss << "d";
else if (days == 1)
ss << " Day ";
else
ss << " Days ";
}
if(hours || hoursOnly)
{
ss << hours;
if (shortText)
ss << "h";
else if (hours <= 1)
ss << " Hour ";
else
ss << " Hours ";
}
if(!hoursOnly)
{
if(minutes)
{
ss << minutes;
if (shortText)
ss << "m";
else if (minutes == 1)
ss << " Minute ";
else
ss << " Minutes ";
}
if (secs || (!days && !hours && !minutes))
{
ss << secs;
if (shortText)
ss << "s";
else if (secs <= 1)
ss << " Second.";
else
ss << " Seconds.";
}
}
return ss.str();
}
uint32 TimeStringToSecs(const std::string& timestring)
{
uint32 secs = 0;
uint32 buffer = 0;
uint32 multiplier = 0;
for(std::string::const_iterator itr = timestring.begin(); itr != timestring.end(); itr++ )
{
if(isdigit(*itr))
{
buffer*=10;
buffer+= (*itr)-'0';
}
else
{
switch(*itr)
{
case 'd': multiplier = DAY; break;
case 'h': multiplier = HOUR; break;
case 'm': multiplier = MINUTE; break;
case 's': multiplier = 1; break;
default : return 0; //bad format
}
buffer*=multiplier;
secs+=buffer;
buffer=0;
}
}
return secs;
}
std::string TimeToTimestampStr(time_t t)
{
tm* aTm = localtime(&t);
// YYYY year
// MM month (2 digits 01-12)
// DD day (2 digits 01-31)
// HH hour (2 digits 00-23)
// MM minutes (2 digits 00-59)
// SS seconds (2 digits 00-59)
char buf[20];
snprintf(buf,20,"%04d-%02d-%02d_%02d-%02d-%02d",aTm->tm_year+1900,aTm->tm_mon+1,aTm->tm_mday,aTm->tm_hour,aTm->tm_min,aTm->tm_sec);
return std::string(buf);
}
/// Check if the string is a valid ip address representation
bool IsIPAddress(char const* ipaddress)
{
if(!ipaddress)
return false;
// Let the big boys do it.
// Drawback: all valid ip address formats are recognized e.g.: 12.23,121234,0xABCD)
return ACE_OS::inet_addr(ipaddress) != INADDR_NONE;
}
/// create PID file
uint32 CreatePIDFile(const std::string& filename)
{
FILE * pid_file = fopen (filename.c_str(), "w" );
if (pid_file == NULL)
return 0;
#ifdef WIN32
DWORD pid = GetCurrentProcessId();
#else
pid_t pid = getpid();
#endif
fprintf(pid_file, "%d", pid );
fclose(pid_file);
return (uint32)pid;
}
size_t utf8length(std::string& utf8str)
{
try
{
return utf8::distance(utf8str.c_str(),utf8str.c_str()+utf8str.size());
}
catch(std::exception)
{
utf8str = "";
return 0;
}
}
void utf8truncate(std::string& utf8str,size_t len)
{
try
{
size_t wlen = utf8::distance(utf8str.c_str(),utf8str.c_str()+utf8str.size());
if(wlen <= len)
return;
std::wstring wstr;
wstr.resize(wlen);
utf8::utf8to16(utf8str.c_str(),utf8str.c_str()+utf8str.size(),&wstr[0]);
wstr.resize(len);
char* oend = utf8::utf16to8(wstr.c_str(),wstr.c_str()+wstr.size(),&utf8str[0]);
utf8str.resize(oend-(&utf8str[0])); // remove unused tail
}
catch(std::exception)
{
utf8str = "";
}
}
bool Utf8toWStr(char const* utf8str, size_t csize, wchar_t* wstr, size_t& wsize)
{
try
{
size_t len = utf8::distance(utf8str,utf8str+csize);
if(len > wsize)
{
if(wsize > 0)
wstr[0] = L'0円';
wsize = 0;
return false;
}
wsize = len;
utf8::utf8to16(utf8str,utf8str+csize,wstr);
wstr[len] = L'0円';
}
catch(std::exception)
{
if(wsize > 0)
wstr[0] = L'0円';
wsize = 0;
return false;
}
return true;
}
bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr)
{
try
{
size_t len = utf8::distance(utf8str.c_str(),utf8str.c_str()+utf8str.size());
wstr.resize(len);
if (len)
utf8::utf8to16(utf8str.c_str(),utf8str.c_str()+utf8str.size(),&wstr[0]);
}
catch(std::exception)
{
wstr = L"";
return false;
}
return true;
}
bool WStrToUtf8(wchar_t* wstr, size_t size, std::string& utf8str)
{
try
{
std::string utf8str2;
utf8str2.resize(size*4); // allocate for most long case
char* oend = utf8::utf16to8(wstr,wstr+size,&utf8str2[0]);
utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail
utf8str = utf8str2;
}
catch(std::exception)
{
utf8str = "";
return false;
}
return true;
}
bool WStrToUtf8(std::wstring wstr, std::string& utf8str)
{
try
{
std::string utf8str2;
utf8str2.resize(wstr.size()*4); // allocate for most long case
char* oend = utf8::utf16to8(wstr.c_str(),wstr.c_str()+wstr.size(),&utf8str2[0]);
utf8str2.resize(oend-(&utf8str2[0])); // remove unused tail
utf8str = utf8str2;
}
catch(std::exception)
{
utf8str = "";
return false;
}
return true;
}
typedef wchar_t const* const* wstrlist;
bool utf8ToConsole(const std::string& utf8str, std::string& conStr)
{
#if PLATFORM == PLATFORM_WINDOWS
std::wstring wstr;
if(!Utf8toWStr(utf8str,wstr))
return false;
conStr.resize(wstr.size());
CharToOemBuffW(&wstr[0],&conStr[0],wstr.size());
#else
// not implemented yet
conStr = utf8str;
#endif
return true;
}
bool consoleToUtf8(const std::string& conStr,std::string& utf8str)
{
#if PLATFORM == PLATFORM_WINDOWS
std::wstring wstr;
wstr.resize(conStr.size());
OemToCharBuffW(&conStr[0],&wstr[0],conStr.size());
return WStrToUtf8(wstr,utf8str);
#else
// not implemented yet
utf8str = conStr;
return true;
#endif
}
bool Utf8FitTo(const std::string& str, std::wstring search)
{
std::wstring temp;
if(!Utf8toWStr(str,temp))
return false;
// converting to lower case
wstrToLower( temp );
if(temp.find(search) == std::wstring::npos)
return false;
return true;
}
void utf8printf(FILE *out, const char *str, ...)
{
va_list ap;
va_start(ap, str);
vutf8printf(stdout, str, &ap);
va_end(ap);
}
void vutf8printf(FILE *out, const char *str, va_list* ap)
{
#if PLATFORM == PLATFORM_WINDOWS
char temp_buf[32*1024];
wchar_t wtemp_buf[32*1024];
size_t temp_len = vsnprintf(temp_buf, 32*1024, str, *ap);
size_t wtemp_len = 32*1024-1;
Utf8toWStr(temp_buf, temp_len, wtemp_buf, wtemp_len);
CharToOemBuffW(&wtemp_buf[0], &temp_buf[0], wtemp_len+1);
fprintf(out, "%s", temp_buf);
#else
vfprintf(out, str, *ap);
#endif
}
void hexEncodeByteArray(uint8* bytes, uint32 arrayLen, std::string& result)
{
std::ostringstream ss;
for(uint32 i=0; i<arrayLen; ++i)
{
for(uint8 j=0; j<2; ++j)
{
unsigned char nibble = 0x0F & (bytes[i]>>((1-j)*4));
char encodedNibble;
if(nibble < 0x0A)
encodedNibble = '0'+nibble;
else
encodedNibble = 'A'+nibble-0x0A;
ss << encodedNibble;
}
}
result = ss.str();
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

60N服LightsHope
暂无标签
GPL-2.0
使用 GPL-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/SpringJoy/server.git
git@gitee.com:SpringJoy/server.git
SpringJoy
server
server
development
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /