diff --git a/code/nel/include/nel/misc/string_common.h b/code/nel/include/nel/misc/string_common.h deleted file mode 100644 index 372ee4be5..000000000 --- a/code/nel/include/nel/misc/string_common.h +++ /dev/null @@ -1,396 +0,0 @@ -// NeL - MMORPG Framework -// Copyright (C) 2010 Winch Gate Property Limited -// -// This source file has been modified by the following contributors: -// Copyright (C) 2012 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2016-2019 Jan BOON (Kaetemi) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#ifndef NL_STRING_COMMON_H -#define NL_STRING_COMMON_H - -#include "types_nl.h" - -#include -#include -#include -#include - -namespace NLMISC -{ - -// get a string and add \r before \n if necessary -std::string addSlashR (const std::string &str); -std::string removeSlashR (const std::string &str); - -/** - * \def MaxCStringSize - * - * The maximum size allowed for C string (zero terminated string) buffer. - * This value is used when we have to create a standard C string buffer and we don't know exactly the final size of the string. - */ -const int MaxCStringSize = 2048; - - -/** - * \def NLMISC_CONVERT_VARGS(dest,format) - * - * This macro converts variable arguments into C string (zero terminated string). - * This function takes care to avoid buffer overflow. - * - * Example: - *\code - void MyFunction(const char *format, ...) - { - string str; - NLMISC_CONVERT_VARGS (str, format, NLMISC::MaxCStringSize); - // str contains the result of the conversion - } - *\endcode - * - * \param _dest \c string or \c char* that contains the result of the convertion - * \param _format format of the string, it must be the last argument before the \c '...' - * \param _size size of the buffer that will contain the C string - */ -#define NLMISC_CONVERT_VARGS(_dest,_format,_size) \ -char _cstring[_size]; \ -va_list _args; \ -va_start (_args, _format); \ -int _res = vsnprintf (_cstring, _size-1, _format, _args); \ -if (_res == -1 || _res == _size-1) \ -{ \ - _cstring[_size-1] = '\0'; \ -} \ -va_end (_args); \ -_dest = _cstring - - - -/** sMart sprintf function. This function do a sprintf and add a zero at the end of the buffer - * if there no enough room in the buffer. - * - * \param buffer a C string - * \param count Size of the buffer - * \param format of the string, it must be the last argument before the \c '...' - */ -sint smprintf( char *buffer, size_t count, const char *format, ... ); - - -#ifdef NL_OS_WINDOWS - -// -// These functions are needed by template system to failed the compilation if you pass bad type on nlinfo... -// - -inline void _check(int /* a */) { } -inline void _check(unsigned int /* a */) { } -inline void _check(char /* a */) { } -inline void _check(unsigned char /* a */) { } -inline void _check(long /* a */) { } -inline void _check(unsigned long /* a */) { } - -#ifdef NL_COMP_VC6 - inline void _check(uint8 /* a */) { } -#endif // NL_COMP_VC6 - -inline void _check(sint8 /* a */) { } -inline void _check(uint16 /* a */) { } -inline void _check(sint16 /* a */) { } - -#ifdef NL_COMP_VC6 - inline void _check(uint32 /* a */) { } - inline void _check(sint32 /* a */) { } -#endif // NL_COMP_VC6 - -inline void _check(uint64 /* a */) { } -inline void _check(sint64 /* a */) { } -inline void _check(float /* a */) { } -inline void _check(double /* a */) { } -inline void _check(const char * /* a */) { } -inline void _check(const void * /* a */) { } - -#define CHECK_TYPES(__a,__b) \ -inline __a(const char *fmt) { __b(fmt); } \ -template __a(const char *fmt, A a) { _check(a); __b(fmt, a); } \ -template __a(const char *fmt, A a, B b) { _check(a); _check(b); __b(fmt, a, b); } \ -template __a(const char *fmt, A a, B b, C c) { _check(a); _check(b); _check(c); __b(fmt, a, b, c); } \ -template __a(const char *fmt, A a, B b, C c, D d) { _check(a); _check(b); _check(c); _check(d); __b(fmt, a, b, c, d); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e) { _check(a); _check(b); _check(c); _check(d); _check(e); __b(fmt, a, b, c, d, e); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); __b(fmt, a, b, c, d, e, f); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); __b(fmt, a, b, c, d, e, f, g); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); __b(fmt, a, b, c, d, e, f, g, h); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); __b(fmt, a, b, c, d, e, f, g, h, i); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); __b(fmt, a, b, c, d, e, f, g, h, i, j); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); __b(fmt, a, b, c, d, e, f, g, h, i, j, k); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r, S s) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); _check(s); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r, S s, T t) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); _check(s); _check(t); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r, S s, T t, U u) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); _check(s); _check(t); _check(u); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r, S s, T t, U u, V v) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); _check(s); _check(t); _check(u); _check(v); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r, S s, T t, U u, V v, W w) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); _check(s); _check(t); _check(u); _check(v); _check(w); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r, S s, T t, U u, V v, W w, X x) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); _check(s); _check(t); _check(u); _check(v); _check(w); _check(x); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r, S s, T t, U u, V v, W w, X x, Y y) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); _check(s); _check(t); _check(u); _check(v); _check(w); _check(x); _check(y); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y); } \ -template __a(const char *fmt, A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l, M m, N n, O o, P p, Q q, R r, S s, T t, U u, V v, W w, X x, Y y, Z z) { _check(a); _check(b); _check(c); _check(d); _check(e); _check(f); _check(g); _check(h); _check(i); _check(j); _check(k); _check(l); _check(m); _check(n); _check(o); _check(p); _check(q); _check(r); _check(s); _check(t); _check(u); _check(v); _check(w); _check(x); _check(y); _check(z); __b(fmt, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z); } - -#endif - -#ifdef NL_OS_WINDOWS - inline std::string _toString(const char *format, ...) -#else - inline std::string toString(const char *format, ...) -#endif -{ - std::string Result; - NLMISC_CONVERT_VARGS(Result, format, NLMISC::MaxCStringSize); - return Result; -} - -#ifdef NL_OS_WINDOWS - CHECK_TYPES(std::string toString, return _toString) -#endif // NL_OS_WINDOWS - -template std::string toStringPtr(const T *val) { return toString("%p", val); } - -template std::string toStringEnum(const T &val) { return toString("%u", (uint32)val); } - -/** - * Template Object toString. - * \param obj any object providing a "std::string toString()" method. The object doesn't have to derive from anything. - * - * the VC++ error "error C2228: left of '.toString' must have class/struct/union type" means you don't provide - * a toString() method to your object. - */ -template std::string toString(const T &obj) -{ - return obj.toString(); -} - -//inline std::string toString(const char *val) { return toString("%s", val); } -inline std::string toString(const uint8 &val) { return toString("%hu", (uint16)val); } -inline std::string toString(const sint8 &val) { return toString("%hd", (sint16)val); } -inline std::string toString(const uint16 &val) { return toString("%hu", val); } -inline std::string toString(const sint16 &val) { return toString("%hd", val); } -inline std::string toString(const uint32 &val) { return toString("%u", val); } -inline std::string toString(const sint32 &val) { return toString("%d", val); } -inline std::string toString(const uint64 &val) { return toString("%" NL_I64 "u", val); } -inline std::string toString(const sint64 &val) { return toString("%" NL_I64 "d", val); } - -#ifdef NL_COMP_GCC -# if GCC_VERSION == 40102 - -// error fix for size_t? gcc 4.1.2 requested this type instead of size_t ... -inline std::string toString(const long unsigned int &val) -{ -#ifdef _LP64 - return toString((uint64)val); -#else - return toString((uint32)val); -#endif -} - -# endif -#endif - -#if (SIZEOF_SIZE_T) == 8 -inline std::string toString(const size_t &val) { return toString("%" NL_I64 "u", val); } -#else -#ifdef NL_OS_MAC -inline std::string toString(const size_t &val) { return toString("%u", val); } -#endif -#endif - -inline std::string toString(const float &val) { return toString("%f", val); } -inline std::string toString(const double &val) { return toString("%lf", val); } -inline std::string toString(const bool &val) { return val ? "1":"0"; } -inline std::string toString(const std::string &val) { return val; } - -// stl vectors of bool use bit reference and not real bools, so define the operator for bit reference - -#ifdef NL_COMP_VC6 -inline std::string toString(const uint &val) { return toString("%u", val); } -inline std::string toString(const sint &val) { return toString("%d", val); } -#endif // NL_COMP_VC6 - -template -bool fromString(const std::string &str, T &obj) -{ - return obj.fromString(str); -} - -inline bool fromString(const std::string &str, uint32 &val) { if (str.find('-') != std::string::npos) { val = 0; return false; } char *end; unsigned long v; errno = 0; v = strtoul(str.c_str(), &end, 10); if (errno || v > UINT_MAX || end == str.c_str()) { val = 0; return false; } else { val = (uint32)v; return true; } } -inline bool fromString(const std::string &str, sint32 &val) { char *end; long v; errno = 0; v = strtol(str.c_str(), &end, 10); if (errno || v > INT_MAX || v < INT_MIN || end == str.c_str()) { val = 0; return false; } else { val = (sint32)v; return true; } } -inline bool fromString(const std::string &str, uint8 &val) { char *end; long v; errno = 0; v = strtol(str.c_str(), &end, 10); if (errno || v > UCHAR_MAX || v < 0 || end == str.c_str()) { val = 0; return false; } else { val = (uint8)v; return true; } } -inline bool fromString(const std::string &str, sint8 &val) { char *end; long v; errno = 0; v = strtol(str.c_str(), &end, 10); if (errno || v > SCHAR_MAX || v < SCHAR_MIN || end == str.c_str()) { val = 0; return false; } else { val = (sint8)v; return true; } } -inline bool fromString(const std::string &str, uint16 &val) { char *end; long v; errno = 0; v = strtol(str.c_str(), &end, 10); if (errno || v > USHRT_MAX || v < 0 || end == str.c_str()) { val = 0; return false; } else { val = (uint16)v; return true; } } -inline bool fromString(const std::string &str, sint16 &val) { char *end; long v; errno = 0; v = strtol(str.c_str(), &end, 10); if (errno || v > SHRT_MAX || v < SHRT_MIN || end == str.c_str()) { val = 0; return false; } else { val = (sint16)v; return true; } } -inline bool fromString(const std::string &str, uint64 &val) { bool ret = sscanf(str.c_str(), "%" NL_I64 "u", &val) == 1; if (!ret) val = 0; return ret; } -inline bool fromString(const std::string &str, sint64 &val) { bool ret = sscanf(str.c_str(), "%" NL_I64 "d", &val) == 1; if (!ret) val = 0; return ret; } -inline bool fromString(const std::string &str, float &val) { bool ret = sscanf(str.c_str(), "%f", &val) == 1; if (!ret) val = 0.0f; return ret; } -inline bool fromString(const std::string &str, double &val) { bool ret = sscanf(str.c_str(), "%lf", &val) == 1; if (!ret) val = 0.0; return ret; } - -/// Fast string to bool, reliably defined for strings starting with 0, 1, t, T, f, F, y, Y, n, N, and empty strings, anything else is undefined. -/// - Kaetemi -inline bool toBool(const char *str) { return str[0] == '1' || (str[0] & 0xD2) == 0x50; } -inline bool toBool(const std::string &str) { return toBool(str.c_str()); } // Safe because first byte may be null - -bool fromString(const std::string &str, bool &val); - -inline bool fromString(const std::string &str, std::string &val) { val = str; return true; } - -// stl vectors of bool use bit reference and not real bools, so define the operator for bit reference - -#ifdef NL_COMP_VC6 -inline bool fromString(const std::string &str, uint &val) { return sscanf(str.c_str(), "%u", &val) == 1; } -inline bool fromString(const std::string &str, sint &val) { return sscanf(str.c_str(), "%d", &val) == 1; } -#endif // NL_COMP_VC6 - -inline bool startsWith(const char *str, const char *prefix) -{ - for (int i = 0;; ++i) - { - if (str[i] != prefix[i] || str[i] == '\0') - { - return prefix[i] == '\0'; - } - } -} - -inline bool startsWith(const std::string &str, const char *prefix) { return startsWith(str.c_str(), prefix); } -inline bool startsWith(const std::string &str, const std::string &prefix) { return startsWith(str.c_str(), prefix.c_str()); } - -inline bool endsWith(const char *str, size_t strLen, const char *suffix, size_t suffixLen) -{ - if (strLen < suffixLen) - return false; - int minLen = strLen < suffixLen ? strLen : suffixLen; - for (int i = 1; i <= minLen; ++i) - if (str[strLen - i] != suffix[suffixLen - i]) - return false; - return true; -} - -inline bool endsWith(const char *str, const char *suffix) { return endsWith(str, strlen(str), suffix, strlen(suffix)); } -inline bool endsWith(const std::string &str, const char *suffix) { return endsWith(str.c_str(), str.size(), suffix, strlen(suffix)); } -inline bool endsWith(const std::string &str, const std::string &suffix) { return endsWith(str.c_str(), str.size(), suffix.c_str(), suffix.size()); } - -// Convert local codepage to UTF-8 -// On Windows, the local codepage is undetermined -// On Linux, the local codepage is always UTF-8 (no-op) -std::string mbcsToUtf8(const char *str, size_t len = 0); -std::string mbcsToUtf8(const std::string &str); - -// Convert wide codepage to UTF-8 -// On Windows, the wide codepage is UTF-16 -// On Linux, the wide codepage is UTF-32 -std::string wideToUtf8(const wchar_t *str, size_t len = 0); -std::string wideToUtf8(const std::wstring &str); - -// Convert UTF-8 to wide character set -std::wstring utf8ToWide(const char *str, size_t len = 0); -std::wstring utf8ToWide(const std::string &str); - -// Convert UTF-8 to local multibyte character set -std::string utf8ToMbcs(const char *str, size_t len = 0); -std::string utf8ToMbcs(const std::string &str); - -// Convert wide to local multibyte character set -std::string wideToMbcs(const wchar_t *str, size_t len = 0); -std::string wideToMbcs(const std::wstring &str); - -// Convert local multibyte to wide character set -std::wstring mbcsToWide(const char *str, size_t len = 0); -std::wstring mbcsToWide(const std::string &str); - -inline const char *asCStr(const char *str) { return str; } -inline const char *asCStr(const std::string &str) { return str.c_str(); } -inline const wchar_t *asCStr(const wchar_t *str) { return str; } -inline const wchar_t *asCStr(const std::wstring &str) { return str.c_str(); } - -#if defined(NL_OS_WINDOWS) -#define nlUtf8ToMbcs(str) (NLMISC::utf8ToMbcs(str).c_str()) -#define nlMbcsToUtf8(str) (NLMISC::mbcsToUtf8(str).c_str()) -#else -#define nlUtf8ToMbcs(str) (NLMISC::asCStr(str)) -#define nlMbcsToUtf8(str) (NLMISC::asCStr(str)) -#endif -#define nlWideToUtf8(str) (NLMISC::wideToUtf8(str).c_str()) -#define nlUtf8ToWide(str) (NLMISC::utf8ToWide(str).c_str()) -#define nlWideToMbcs(str) (NLMISC::wideToMbcs(str).c_str()) -#define nlMbcsToWide(str) (NLMISC::mbcsToWide(str).c_str()) - -// On Windows, tstring is either local multibyte or utf-16 wide -// On Linux, tstring is always utf-8 - -#if defined(NL_OS_WINDOWS) && (defined(UNICODE) || defined(_UNICODE)) -typedef std::wstring tstring; -typedef wchar_t tchar; -inline std::string tStrToUtf8(const tchar *str) { return wideToUtf8((const wchar_t *)str); } -inline std::string tStrToUtf8(const tstring &str) { return wideToUtf8((const std::wstring &)str); } -inline std::wstring tStrToWide(const tchar *str) { return (const wchar_t *)str; } -inline std::wstring tStrToWide(const tstring &str) { return (const std::wstring &)str; } -inline std::string tStrToMbcs(const tchar *str) { return wideToMbcs((const wchar_t *)str); } -inline std::string tStrToMbcs(const tstring &str) { return wideToMbcs((const std::wstring &)str); } -#define nlTStrToUtf8(str) (NLMISC::tStrToUtf8(str).c_str()) -#define nlTStrToWide(str) ((const wchar_t *)NLMISC::asCStr(str)) -#define nlTStrToMbcs(str) (NLMISC::tStrToMbcs(str).c_str()) -inline tstring utf8ToTStr(const char *str) {return (const tstring &)utf8ToWide(str); } -inline tstring utf8ToTStr(const std::string &str) { return (const tstring &)utf8ToWide(str); } -inline tstring wideToTStr(const wchar_t *str) { return (const tchar *)str; } -inline tstring wideToTStr(const std::wstring &str) { return (const tstring &)str; } -inline tstring mbcsToTStr(const char *str) { return (const tstring &)mbcsToWide(str); } -inline tstring mbcsToTStr(const std::string &str) { return (const tstring &)mbcsToWide(str); } -#define nlUtf8ToTStr(str) (NLMISC::utf8ToTStr(str).c_str()) -#define nlWideToTStr(str) ((const tchar *)NLMISC::asCStr(str)) -#define nlMbcsToTStr(str) (NLMISC::mbcsToTStr(str).c_str()) -#else -typedef std::string tstring; -typedef char tchar; -inline std::string tStrToUtf8(const tchar *str) { return mbcsToUtf8((const char *)str); } -inline std::string tStrToUtf8(const tstring &str) { return mbcsToUtf8((const std::string &)str); } -inline std::wstring tStrToWide(const tchar *str) { return mbcsToWide((const char *)str); } -inline std::wstring tStrToWide(const tstring &str) { return mbcsToWide((const std::string &)str); } -inline std::string tStrToMbcs(const tchar *str) { return (const char *)str; } -inline std::string tStrToMbcs(const tstring &str) { return (const std::string &)str; } -#if defined(NL_OS_WINDOWS) -#define nlTStrToUtf8(str) (NLMISC::tStrToUtf8(str).c_str()) -#else -#define nlTStrToUtf8(str) ((const char *)NLMISC::asCStr(str)) -#endif -#define nlTStrToWide(str) (NLMISC::tStrToWide(str).c_str()) -#define nlTStrToMbcs(str) ((const char *)NLMISC::asCStr(str)) -inline tstring utf8ToTStr(const char *str) { return (const tstring &)utf8ToMbcs(str); } -inline tstring utf8ToTStr(const std::string &str) { return (const tstring &)utf8ToMbcs(str); } -inline tstring wideToTStr(const wchar_t *str) { return (const tstring &)wideToMbcs(str); } -inline tstring wideToTStr(const std::wstring &str) { return (const tstring &)wideToMbcs(str); } -inline tstring mbcsToTStr(const char *str) { return (const tchar *)str; } -inline tstring mbcsToTStr(const std::string &str) { return (const tstring &)str; } -#if defined(NL_OS_WINDOWS) -#define nlUtf8ToTStr(str) (NLMISC::utf8ToTStr(str).c_str()) -#else -#define nlUtf8ToTStr(str) ((const tchar *)NLMISC::asCStr(str)) -#endif -#define nlWideToTStr(str) (NLMISC::wideToTStr(str).c_str()) -#define nlMbcsToTStr(str) ((const tchar *)NLMISC::asCStr(str)) -#endif - -} // NLMISC - -#endif // NL_STRING_COMMON_H diff --git a/code/nel/tools/build_gamedata/0_setup.py b/code/nel/tools/build_gamedata/0_setup.py deleted file mode 100644 index 12441fb05..000000000 --- a/code/nel/tools/build_gamedata/0_setup.py +++ /dev/null @@ -1,594 +0,0 @@ -#!/usr/bin/python -# -# \file 0_setup.py -# \brief Run all setup processes -# \date 2009-02-18 15:28GMT -# \author Jan Boon (Kaetemi) -# Python port of game data build pipeline. -# Run all setup processes -# -# NeL - MMORPG Framework -# Copyright (C) 2009-2014 by authors -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -import time, sys, os, shutil, subprocess, distutils.dir_util, argparse -sys.path.append("configuration") - -parser = argparse.ArgumentParser(description='Ryzom Core - Build Gamedata - Setup') -parser.add_argument('--noconf', '-nc', action='store_true') -parser.add_argument('--noverify', '-nv', action='store_true') -parser.add_argument('--preset', '-p', action='store_true') -# parser.add_argument('--haltonerror', '-eh', action='store_true') -parser.add_argument('--includeproject', '-ipj', nargs='+') -parser.add_argument('--excludeproject', '-epj', nargs='+') -parser.add_argument('--includeprocess', '-ipc', nargs='+') -parser.add_argument('--excludeprocess', '-epc', nargs='+') -args = parser.parse_args() - -if not args.includeproject == None and not args.excludeproject == None: - print "ERROR --includeproject cannot be combined with --excludeproject, exit." - exit() - -if not args.includeprocess == None and not args.excludeprocess == None: - print "ERROR --includeprocess cannot be combined with --excludeprocess, exit." - exit() - -if os.path.isfile("log.log"): - os.remove("log.log") -log = open("log.log", "w") -from scripts import * -try: - from buildsite import * -except ImportError: - printLog(log, "*** FIRST RUN ***") - if args.noconf: - printLog(log, "ERROR --noconf is invalid on first run, exit.") - exit() -from tools import * - -if not args.noconf: - try: - BuildQuality - except NameError: - BuildQuality = 1 - try: - if args.preset: - DummyUnknownName - RemapLocalFrom - except NameError: - RemapLocalFrom = 'R:' - try: - if args.preset: - DummyUnknownName - RemapLocalTo - except NameError: - RemapLocalTo = os.getenv('RC_ROOT').replace('\\', '/') - if (not RemapLocalTo) or (not ':' in RemapLocalTo): - RemapLocalTo = 'R:' - try: - if args.preset: - DummyUnknownName - ToolDirectories - except NameError: - ToolDirectories = [ 'R:/distribution/nel_tools_win_x64', 'R:/distribution/ryzom_tools_win_x64' ] - try: - ToolSuffix - except NameError: - ToolSuffix = ".exe" - try: - if args.preset: - DummyUnknownName - ScriptDirectory - except NameError: - ScriptDirectory = "R:/code/nel/tools/build_gamedata" - try: - if args.preset: - DummyUnknownName - WorkspaceDirectory - except NameError: - WorkspaceDirectory = "R:/leveldesign/workspace" - try: - if args.preset: - DummyUnknownName - DatabaseDirectory - except NameError: - DatabaseDirectory = "R:/graphics" - try: - if args.preset: - DummyUnknownName - SoundDirectory - except NameError: - SoundDirectory = "R:/sound" - try: - if args.preset: - DummyUnknownName - SoundDfnDirectory - except NameError: - SoundDfnDirectory = "R:/sound/DFN" - try: - if args.preset: - DummyUnknownName - ExportBuildDirectory - except NameError: - ExportBuildDirectory = "R:/pipeline/export" - try: - if args.preset: - DummyUnknownName - InstallDirectory - except NameError: - InstallDirectory = "R:/pipeline/install" - try: - if args.preset: - DummyUnknownName - ClientDevDirectory - except NameError: - ClientDevDirectory = "R:/pipeline/client_dev" - try: - if args.preset: - DummyUnknownName - ClientDevLiveDirectory - except NameError: - ClientDevLiveDirectory = "R:/pipeline/client_dev_live" - try: - if args.preset: - DummyUnknownName - ClientPatchDirectory - except NameError: - ClientPatchDirectory = "R:/pipeline/client_patch" - try: - if args.preset: - DummyUnknownName - ClientInstallDirectory - except NameError: - ClientInstallDirectory = "R:/pipeline/client_install" - try: - if args.preset: - DummyUnknownName - ShardInstallDirectory - except NameError: - ShardInstallDirectory = "R:/pipeline/shard" - try: - if args.preset: - DummyUnknownName - ShardDevDirectory - except NameError: - ShardDevDirectory = "R:/pipeline/shard_dev" - try: - if args.preset: - DummyUnknownName - WorldEditInstallDirectory - except NameError: - WorldEditInstallDirectory = "R:/pipeline/worldedit" - try: - if args.preset: - DummyUnknownName - WorldEditorFilesDirectory - except NameError: - WorldEditorFilesDirectory = "R:/code/ryzom/common/data_leveldesign/leveldesign/world_editor_files" - try: - if args.preset: - DummyUnknownName - LeveldesignDirectory - except NameError: - LeveldesignDirectory = "R:/leveldesign" - try: - if args.preset: - DummyUnknownName - LeveldesignDfnDirectory - except NameError: - LeveldesignDfnDirectory = "R:/leveldesign/DFN" - try: - if args.preset: - DummyUnknownName - LeveldesignWorldDirectory - except NameError: - LeveldesignWorldDirectory = "R:/leveldesign/world" - try: - if args.preset: - DummyUnknownName - PrimitivesDirectory - except NameError: - PrimitivesDirectory = "R:/leveldesign/primitives" - try: - if args.preset: - DummyUnknownName - LeveldesignDataCommonDirectory - except NameError: - LeveldesignDataCommonDirectory = "R:/leveldesign/common" - try: - if args.preset: - DummyUnknownName - LeveldesignDataShardDirectory - except NameError: - LeveldesignDataShardDirectory = "R:/leveldesign/shard" - try: - if args.preset: - DummyUnknownName - TranslationDirectory - except NameError: - TranslationDirectory = "R:/leveldesign/translation" - try: - if args.preset: - DummyUnknownName - GamedevDirectory - except NameError: - GamedevDirectory = "R:/code/ryzom/client/data/gamedev" - try: - if args.preset: - DummyUnknownName - DataCommonDirectory - except NameError: - DataCommonDirectory = "R:/code/ryzom/common/data_common" - try: - if args.preset: - DummyUnknownName - DataShardDirectory - except NameError: - DataShardDirectory = "R:/code/ryzom/server/data_shard" - try: - if args.preset: - DummyUnknownName - WindowsExeDllCfgDirectories - except NameError: - # TODO: Separate 64bit and 32bit - WindowsExeDllCfgDirectories = [ '', 'R:/build/fv_x64/bin/Release', 'R:/distribution/external_x64', 'R:/code/ryzom/client', '', '', '' ] - try: - if args.preset: - DummyUnknownName - LinuxServiceExecutableDirectory - except NameError: - LinuxServiceExecutableDirectory = "R:/build/server_gcc/bin" - try: - if args.preset: - DummyUnknownName - LinuxClientExecutableDirectory - except NameError: - LinuxClientExecutableDirectory = "R:/build/client_gcc/bin" - try: - if args.preset: - DummyUnknownName - PatchmanDevDirectory - except NameError: - PatchmanDevDirectory = "R:/patchman/terminal_dev" - try: - if args.preset: - DummyUnknownName - PatchmanCfgAdminDirectory - except NameError: - PatchmanCfgAdminDirectory = "R:/patchman/admin_install" - try: - if args.preset: - DummyUnknownName - PatchmanCfgDefaultDirectory - except NameError: - PatchmanCfgDefaultDirectory = "R:/patchman/default" - try: - if args.preset: - DummyUnknownName - PatchmanBridgeServerDirectory - except NameError: - PatchmanBridgeServerDirectory = "R:/pipeline/bridge_server" - try: - SignToolExecutable - except NameError: - SignToolExecutable = "C:/Program Files/Microsoft SDKs/Windows/v6.0A/Bin/signtool.exe" - try: - SignToolSha1 - except NameError: - SignToolSha1 = "" - try: - SignToolTimestamp - except NameError: - SignToolTimestamp = "http://timestamp.comodoca.com/authenticode" - try: - MaxAvailable - except NameError: - MaxAvailable = 1 - try: - MaxDirectory - except NameError: - MaxDirectory = "C:/Program Files (x86)/Autodesk/3ds Max 2010" - try: - MaxUserDirectory - except NameError: - import os - try: - MaxUserDirectory = os.path.normpath(os.environ["LOCALAPPDATA"] + "/Autodesk/3dsMax/2010 - 32bit/enu") - except KeyError: - MaxAvailable = 0 - MaxUserDirectory = "C:/Users/Kaetemi/AppData/Local/Autodesk/3dsMax/2010 - 32bit/enu" - try: - MaxExecutable - except NameError: - MaxExecutable = "3dsmax.exe" - - printLog(log, "") - printLog(log, "-------") - printLog(log, "--- Setup build site") - printLog(log, "-------") - printLog(log, time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time()))) - printLog(log, "") - printLog(log, "This script will set up the buildsite configuration, and create needed directories.") - printLog(log, "To use the defaults, simply hit ENTER, else type in the new value.") - printLog(log, "Use -- if you need to insert an empty value.") - printLog(log, "") - BuildQuality = int(askVar(log, "Build Quality", str(BuildQuality))) - if not args.preset: - ToolDirectories[0] = askVar(log, "[IN] Primary Tool Directory", ToolDirectories[0]).replace("\\", "/") - ToolDirectories[1] = askVar(log, "[IN] Secondary Tool Directory", ToolDirectories[1]).replace("\\", "/") - ToolSuffix = askVar(log, "Tool Suffix", ToolSuffix) - ScriptDirectory = askVar(log, "[IN] Script Directory", os.getcwd().replace("\\", "/")).replace("\\", "/") - WorkspaceDirectory = askVar(log, "[IN] Workspace Directory", WorkspaceDirectory).replace("\\", "/") - DatabaseDirectory = askVar(log, "[IN] Database Directory", DatabaseDirectory).replace("\\", "/") - SoundDirectory = askVar(log, "[IN] Sound Directory", SoundDirectory).replace("\\", "/") - SoundDfnDirectory = askVar(log, "[IN] Sound DFN Directory", SoundDfnDirectory).replace("\\", "/") - ExportBuildDirectory = askVar(log, "[OUT] Export Build Directory", ExportBuildDirectory).replace("\\", "/") - InstallDirectory = askVar(log, "[OUT] Install Directory", InstallDirectory).replace("\\", "/") - ClientDevDirectory = askVar(log, "[OUT] Client Dev Directory", ClientDevDirectory).replace("\\", "/") - ClientDevLiveDirectory = askVar(log, "[OUT] Client Dev Live Directory", ClientDevLiveDirectory).replace("\\", "/") - ClientPatchDirectory = askVar(log, "[OUT] Client Patch Directory", ClientPatchDirectory).replace("\\", "/") - ClientInstallDirectory = askVar(log, "[OUT] Client Install Directory", ClientInstallDirectory).replace("\\", "/") - ShardInstallDirectory = askVar(log, "[OUT] Shard Data Install Directory", ShardInstallDirectory).replace("\\", "/") - ShardDevDirectory = askVar(log, "[OUT] Shard Dev Directory", ShardDevDirectory).replace("\\", "/") - WorldEditInstallDirectory = askVar(log, "[OUT] World Edit Data Install Directory", WorldEditInstallDirectory).replace("\\", "/") - LeveldesignDirectory = askVar(log, "[IN] Leveldesign Directory", LeveldesignDirectory).replace("\\", "/") - LeveldesignDfnDirectory = askVar(log, "[IN] Leveldesign DFN Directory", LeveldesignDfnDirectory).replace("\\", "/") - LeveldesignWorldDirectory = askVar(log, "[IN] Leveldesign World Directory", LeveldesignWorldDirectory).replace("\\", "/") - PrimitivesDirectory = askVar(log, "[IN] Primitives Directory", PrimitivesDirectory).replace("\\", "/") - GamedevDirectory = askVar(log, "[IN] Gamedev Directory", GamedevDirectory).replace("\\", "/") - DataShardDirectory = askVar(log, "[IN] Data Shard Directory", DataShardDirectory).replace("\\", "/") - DataCommonDirectory = askVar(log, "[IN] Data Common Directory", DataCommonDirectory).replace("\\", "/") - TranslationDirectory = askVar(log, "[IN] Translation Directory", TranslationDirectory).replace("\\", "/") - LeveldesignDataShardDirectory = askVar(log, "[IN] Leveldesign Data Shard Directory", LeveldesignDataShardDirectory).replace("\\", "/") - LeveldesignDataCommonDirectory = askVar(log, "[IN] Leveldesign Data Common Directory", LeveldesignDataCommonDirectory).replace("\\", "/") - WorldEditorFilesDirectory = askVar(log, "[IN] World Editor Files Directory", WorldEditorFilesDirectory).replace("\\", "/") - WindowsExeDllCfgDirectories[0] = askVar(log, "[IN] Primary Windows exe/dll/cfg Directory", WindowsExeDllCfgDirectories[0]).replace("\\", "/") - WindowsExeDllCfgDirectories[1] = askVar(log, "[IN] Secondary Windows exe/dll/cfg Directory", WindowsExeDllCfgDirectories[1]).replace("\\", "/") - WindowsExeDllCfgDirectories[2] = askVar(log, "[IN] Tertiary Windows exe/dll/cfg Directory", WindowsExeDllCfgDirectories[2]).replace("\\", "/") - WindowsExeDllCfgDirectories[3] = askVar(log, "[IN] Quaternary Windows exe/dll/cfg Directory", WindowsExeDllCfgDirectories[3]).replace("\\", "/") - WindowsExeDllCfgDirectories[4] = askVar(log, "[IN] Quinary Windows exe/dll/cfg Directory", WindowsExeDllCfgDirectories[4]).replace("\\", "/") - WindowsExeDllCfgDirectories[5] = askVar(log, "[IN] Senary Windows exe/dll/cfg Directory", WindowsExeDllCfgDirectories[5]).replace("\\", "/") - WindowsExeDllCfgDirectories[6] = askVar(log, "[IN] Septenary Windows exe/dll/cfg Directory", WindowsExeDllCfgDirectories[6]).replace("\\", "/") - LinuxServiceExecutableDirectory = askVar(log, "[IN] Linux Service Executable Directory", LinuxServiceExecutableDirectory).replace("\\", "/") - LinuxClientExecutableDirectory = askVar(log, "[IN] Linux Client Executable Directory", LinuxClientExecutableDirectory).replace("\\", "/") - PatchmanDevDirectory = askVar(log, "[IN] Patchman Directory", PatchmanDevDirectory).replace("\\", "/") - PatchmanCfgAdminDirectory = askVar(log, "[IN] Patchman Cfg Admin Directory", PatchmanCfgAdminDirectory).replace("\\", "/") - PatchmanCfgDefaultDirectory = askVar(log, "[IN] Patchman Cfg Default Directory", PatchmanCfgDefaultDirectory).replace("\\", "/") - PatchmanBridgeServerDirectory = askVar(log, "[OUT] Patchman Bridge Server Patch Directory", PatchmanBridgeServerDirectory).replace("\\", "/") - SignToolExecutable = askVar(log, "Sign Tool Executable", SignToolExecutable).replace("\\", "/") - SignToolSha1 = askVar(log, "Sign Tool Signature SHA1", SignToolSha1) - SignToolTimestamp = askVar(log, "Sign Tool Timestamp Authority", SignToolTimestamp) - MaxAvailable = int(askVar(log, "3dsMax Available", str(MaxAvailable))) - if MaxAvailable: - MaxDirectory = askVar(log, "3dsMax Directory", MaxDirectory).replace("\\", "/") - MaxUserDirectory = askVar(log, "3dsMax User Directory", MaxUserDirectory).replace("\\", "/") - MaxExecutable = askVar(log, "3dsMax Executable", MaxExecutable) - if os.path.isfile("configuration/buildsite.py"): - os.remove("configuration/buildsite.py") - sf = open("configuration/buildsite.py", "w") - sf.write("#!/usr/bin/python\n") - sf.write("# \n") - sf.write("# \\file site.py\n") - sf.write("# \\brief Site configuration\n") - sf.write("# \\date " + time.strftime("%Y-%m-%d-%H-%M-GMT", time.gmtime(time.time())) + "\n") - sf.write("# \\author Jan Boon (Kaetemi)\n") - sf.write("# Python port of game data build pipeline.\n") - sf.write("# Site configuration.\n") - sf.write("# \n") - sf.write("# NeL - MMORPG Framework \n") - sf.write("# Copyright (C) 2009-2014 by authors\n") - sf.write("# \n") - sf.write("# This program is free software: you can redistribute it and/or modify\n") - sf.write("# it under the terms of the GNU Affero General Public License as\n") - sf.write("# published by the Free Software Foundation, either version 3 of the\n") - sf.write("# License, or (at your option) any later version.\n") - sf.write("# \n") - sf.write("# This program is distributed in the hope that it will be useful,\n") - sf.write("# but WITHOUT ANY WARRANTY; without even the implied warranty of\n") - sf.write("# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n") - sf.write("# GNU Affero General Public License for more details.\n") - sf.write("# \n") - sf.write("# You should have received a copy of the GNU Affero General Public License\n") - sf.write("# along with this program. If not, see .\n") - sf.write("# \n") - sf.write("\n") - sf.write("\n") - sf.write("# *** SITE INSTALLATION ***\n") - sf.write("\n") - sf.write("# Use '/' in path name, not '\'\n") - sf.write("# Don't put '/' at the end of a directory name\n") - sf.write("\n") - sf.write("\n") - sf.write("# Quality option for this site (1 for BEST, 0 for DRAFT)\n") - sf.write("BuildQuality = " + str(BuildQuality) + "\n") - sf.write("\n") - sf.write("RemapLocalFrom = \"" + str(RemapLocalFrom) + "\"\n") - sf.write("RemapLocalTo = \"" + str(RemapLocalTo) + "\"\n") - sf.write("\n") - sf.write("ToolDirectories = " + str(ToolDirectories) + "\n") - sf.write("ToolSuffix = \"" + str(ToolSuffix) + "\"\n") - sf.write("\n") - sf.write("# Build script directory\n") - sf.write("ScriptDirectory = \"" + str(ScriptDirectory) + "\"\n") - sf.write("WorkspaceDirectory = \"" + str(WorkspaceDirectory) + "\"\n") - sf.write("\n") - sf.write("# Data build directories\n") - sf.write("DatabaseDirectory = \"" + str(DatabaseDirectory) + "\"\n") - sf.write("SoundDirectory = \"" + str(SoundDirectory) + "\"\n") - sf.write("SoundDfnDirectory = \"" + str(SoundDfnDirectory) + "\"\n") - sf.write("ExportBuildDirectory = \"" + str(ExportBuildDirectory) + "\"\n") - sf.write("\n") - sf.write("# Install directories\n") - sf.write("InstallDirectory = \"" + str(InstallDirectory) + "\"\n") - sf.write("ClientDevDirectory = \"" + str(ClientDevDirectory) + "\"\n") - sf.write("ClientDevLiveDirectory = \"" + str(ClientDevLiveDirectory) + "\"\n") - sf.write("ClientPatchDirectory = \"" + str(ClientPatchDirectory) + "\"\n") - sf.write("ClientInstallDirectory = \"" + str(ClientInstallDirectory) + "\"\n") - sf.write("ShardInstallDirectory = \"" + str(ShardInstallDirectory) + "\"\n") - sf.write("ShardDevDirectory = \"" + str(ShardDevDirectory) + "\"\n") - sf.write("WorldEditInstallDirectory = \"" + str(WorldEditInstallDirectory) + "\"\n") - sf.write("\n") - sf.write("# Utility directories\n") - sf.write("WorldEditorFilesDirectory = \"" + str(WorldEditorFilesDirectory) + "\"\n") - sf.write("\n") - sf.write("# Leveldesign directories\n") - sf.write("LeveldesignDirectory = \"" + str(LeveldesignDirectory) + "\"\n") - sf.write("LeveldesignDfnDirectory = \"" + str(LeveldesignDfnDirectory) + "\"\n") - sf.write("LeveldesignWorldDirectory = \"" + str(LeveldesignWorldDirectory) + "\"\n") - sf.write("PrimitivesDirectory = \"" + str(PrimitivesDirectory) + "\"\n") - sf.write("LeveldesignDataCommonDirectory = \"" + str(LeveldesignDataCommonDirectory) + "\"\n") - sf.write("LeveldesignDataShardDirectory = \"" + str(LeveldesignDataShardDirectory) + "\"\n") - sf.write("TranslationDirectory = \"" + str(TranslationDirectory) + "\"\n") - sf.write("\n") - sf.write("# Misc data directories\n") - sf.write("GamedevDirectory = \"" + str(GamedevDirectory) + "\"\n") - sf.write("DataCommonDirectory = \"" + str(DataCommonDirectory) + "\"\n") - sf.write("DataShardDirectory = \"" + str(DataShardDirectory) + "\"\n") - sf.write("WindowsExeDllCfgDirectories = " + str(WindowsExeDllCfgDirectories) + "\n") - sf.write("LinuxServiceExecutableDirectory = \"" + str(LinuxServiceExecutableDirectory) + "\"\n") - sf.write("LinuxClientExecutableDirectory = \"" + str(LinuxClientExecutableDirectory) + "\"\n") - sf.write("PatchmanDevDirectory = \"" + str(PatchmanDevDirectory) + "\"\n") - sf.write("PatchmanCfgAdminDirectory = \"" + str(PatchmanCfgAdminDirectory) + "\"\n") - sf.write("PatchmanCfgDefaultDirectory = \"" + str(PatchmanCfgDefaultDirectory) + "\"\n") - sf.write("PatchmanBridgeServerDirectory = \"" + str(PatchmanBridgeServerDirectory) + "\"\n") - sf.write("\n") - sf.write("# Sign tool\n") - sf.write("SignToolExecutable = \"" + str(SignToolExecutable) + "\"\n") - sf.write("SignToolSha1 = \"" + str(SignToolSha1) + "\"\n") - sf.write("SignToolTimestamp = \"" + str(SignToolTimestamp) + "\"\n") - sf.write("\n") - sf.write("# 3dsMax directives\n") - sf.write("MaxAvailable = " + str(MaxAvailable) + "\n") - sf.write("MaxDirectory = \"" + str(MaxDirectory) + "\"\n") - sf.write("MaxUserDirectory = \"" + str(MaxUserDirectory) + "\"\n") - sf.write("MaxExecutable = \"" + str(MaxExecutable) + "\"\n") - sf.write("\n") - sf.write("\n") - sf.write("# end of file\n") - sf.flush() - sf.close() - sf = open("configuration/buildsite_local.py", "w") - sfr = open("configuration/buildsite.py", "r") - for l in sfr: - sf.write(l.replace(RemapLocalFrom + '/', RemapLocalTo + '/')) - sf.flush() - sfr.close() - sf.close() - -from buildsite_local import * - -sys.path.append(WorkspaceDirectory) -from projects import * - -printLog(log, "") -printLog(log, "-------") -printLog(log, "--- Run the setup projects") -printLog(log, "-------") -printLog(log, time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time()))) -printLog(log, "") -# For each project -for projectName in ProjectsToProcess: - if ((args.includeproject == None or projectName in args.includeproject) and (args.excludeproject == None or not projectName in args.excludeproject)): - printLog(log, "PROJECT " + projectName) - os.putenv("NELBUILDACTIVEPROJECT", os.path.abspath(WorkspaceDirectory + "/" + projectName)) - os.chdir("processes") - try: - if not args.includeprocess == None: - subprocess.call([ "python", "0_setup.py", "--includeprocess" ] + args.includeprocess) - elif not args.excludeprocess == None: - subprocess.call([ "python", "0_setup.py", "--excludeprocess" ] + args.excludeprocess) - else: - subprocess.call([ "python", "0_setup.py" ]) - except Exception, e: - printLog(log, "<" + projectName + "> " + str(e)) - os.chdir("..") - try: - projectLog = open("processes/log.log", "r") - projectLogData = projectLog.read() - projectLog.close() - log.write(projectLogData) - except Exception, e: - printLog(log, "<" + projectName + "> " + str(e)) - else: - printLog(log, "IGNORE PROJECT " + projectName) -printLog(log, "") - -# Additional directories -printLog(log, ">>> Setup additional directories <<<") -mkPath(log, ClientDevDirectory) -mkPath(log, ClientDevLiveDirectory) -mkPath(log, ClientPatchDirectory) -mkPath(log, ClientInstallDirectory) - -if not args.noverify: - printLog(log, "") - printLog(log, "-------") - printLog(log, "--- Verify tool paths") - printLog(log, "-------") - printLog(log, time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time()))) - printLog(log, "") - if MaxAvailable: - findMax(log, MaxDirectory, MaxExecutable) - findTool(log, ToolDirectories, TgaToDdsTool, ToolSuffix) - findTool(log, ToolDirectories, BuildInterfaceTool, ToolSuffix) - findTool(log, ToolDirectories, ExecTimeoutTool, ToolSuffix) - findTool(log, ToolDirectories, BuildSmallbankTool, ToolSuffix) - findTool(log, ToolDirectories, BuildFarbankTool, ToolSuffix) - findTool(log, ToolDirectories, ZoneDependenciesTool, ToolSuffix) - findTool(log, ToolDirectories, ZoneWelderTool, ToolSuffix) - findTool(log, ToolDirectories, ZoneElevationTool, ToolSuffix) - findTool(log, ToolDirectories, BuildRbankTool, ToolSuffix) - findTool(log, ToolDirectories, BuildIndoorRbankTool, ToolSuffix) - findTool(log, ToolDirectories, BuildIgBoxesTool, ToolSuffix) - findTool(log, ToolDirectories, GetNeighborsTool, ToolSuffix) - findTool(log, ToolDirectories, ZoneLighterTool, ToolSuffix) - findTool(log, ToolDirectories, ZoneIgLighterTool, ToolSuffix) - findTool(log, ToolDirectories, IgLighterTool, ToolSuffix) - findTool(log, ToolDirectories, AnimBuilderTool, ToolSuffix) - findTool(log, ToolDirectories, TileEditTool, ToolSuffix) - # findTool(log, ToolDirectories, BuildImagesetTool, ToolSuffix) # kaetemi stuff, ignore this - findTool(log, ToolDirectories, MakeSheetIdTool, ToolSuffix) - # findTool(log, ToolDirectories, BuildSheetsTool, ToolSuffix) # kaetemi stuff, ignore this - # findTool(log, ToolDirectories, BuildSoundTool, ToolSuffix) # kaetemi stuff, ignore this - # findTool(log, ToolDirectories, BuildSoundTool, ToolSuffix) - findTool(log, ToolDirectories, BuildSoundbankTool, ToolSuffix) - findTool(log, ToolDirectories, BuildSamplebankTool, ToolSuffix) - findTool(log, ToolDirectories, BuildCoarseMeshTool, ToolSuffix) - findTool(log, ToolDirectories, LightmapOptimizerTool, ToolSuffix) - findTool(log, ToolDirectories, BuildClodtexTool, ToolSuffix) - findTool(log, ToolDirectories, BuildShadowSkinTool, ToolSuffix) - findTool(log, ToolDirectories, PanoplyMakerTool, ToolSuffix) - findTool(log, ToolDirectories, HlsBankMakerTool, ToolSuffix) - findTool(log, ToolDirectories, LandExportTool, ToolSuffix) - findTool(log, ToolDirectories, PrimExportTool, ToolSuffix) - findTool(log, ToolDirectories, IgElevationTool, ToolSuffix) - findTool(log, ToolDirectories, IgAddTool, ToolSuffix) - findTool(log, ToolDirectories, BuildClodBankTool, ToolSuffix) - findTool(log, ToolDirectories, SheetsPackerTool, ToolSuffix) - findTool(log, ToolDirectories, BnpMakeTool, ToolSuffix) - findTool(log, ToolDirectories, AiBuildWmapTool, ToolSuffix) - findTool(log, ToolDirectories, TgaCutTool, ToolSuffix) - findTool(log, ToolDirectories, PatchGenTool, ToolSuffix) - findTool(log, ToolDirectories, TranslationToolsTool, ToolSuffix) - findTool(log, ToolDirectories, BuildWorldPackedColTool, ToolSuffix) - findTool(log, ToolDirectories, R2IslandsTexturesTool, ToolSuffix) - findTool(log, ToolDirectories, PatchmanServiceTool, ToolSuffix) - -log.close() -if os.path.isfile("0_setup.log"): - os.remove("0_setup.log") -shutil.copy("log.log", time.strftime("%Y-%m-%d-%H-%M-GMT", time.gmtime(time.time())) + "_setup.log") -shutil.move("log.log", "0_setup.log") diff --git a/code/nel/tools/build_gamedata/translation/make_merge_all.py b/code/nel/tools/build_gamedata/translation/make_merge_all.py deleted file mode 100644 index 91fc4712b..000000000 --- a/code/nel/tools/build_gamedata/translation/make_merge_all.py +++ /dev/null @@ -1,70 +0,0 @@ -#!/usr/bin/python -# -# \author Jan Boon (Kaetemi) -# -# NeL - MMORPG Framework -# Copyright (C) 2014 by authors -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -import time, sys, os, shutil, subprocess, distutils.dir_util -sys.path.append("../configuration") -from scripts import * -from buildsite import * -from tools import * -os.chdir(TranslationDirectory) -if os.path.isfile("log.log"): - os.remove("log.log") -log = open("log.log", "w") - -printLog(log, "") -printLog(log, "-------") -printLog(log, "--- Make and merge all translations") -printLog(log, "-------") -printLog(log, time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time()))) -printLog(log, "") - - -TranslationTools = findTool(log, ToolDirectories, TranslationToolsTool, ToolSuffix) -try: - subprocess.call([ TranslationTools, "make_phrase_diff" ]) - subprocess.call([ TranslationTools, "merge_phrase_diff" ]) - subprocess.call([ TranslationTools, "make_clause_diff" ]) - subprocess.call([ TranslationTools, "merge_clause_diff" ]) - subprocess.call([ TranslationTools, "make_words_diff" ]) - subprocess.call([ TranslationTools, "merge_words_diff" ]) - subprocess.call([ TranslationTools, "make_string_diff" ]) - subprocess.call([ TranslationTools, "merge_string_diff" ]) - subprocess.call([ TranslationTools, "clean_string_diff" ]) - subprocess.call([ TranslationTools, "make_r2_string_diff" ]) - subprocess.call([ TranslationTools, "merge_r2_string_diff" ]) - subprocess.call([ TranslationTools, "clean_r2_string_diff" ]) - subprocess.call([ TranslationTools, "clean_words_diff" ]) - subprocess.call([ TranslationTools, "clean_clause_diff" ]) - subprocess.call([ TranslationTools, "clean_phrase_diff" ]) - subprocess.call([ TranslationTools, "make_worksheet_diff", "bot_names.txt" ]) - subprocess.call([ TranslationTools, "merge_worksheet_diff", "bot_names.txt" ]) -except Exception, e: - printLog(log, "<" + processName + "> " + str(e)) -printLog(log, "") - - -log.close() -if os.path.isfile("make_merge_all.log"): - os.remove("make_merge_all.log") -shutil.copy("log.log", "make_merge_all_" + time.strftime("%Y-%m-%d-%H-%M-GMT", time.gmtime(time.time())) + ".log") -shutil.move("log.log", "make_merge_all.log") - -raw_input("PRESS ANY KEY TO EXIT") diff --git a/code/nel/tools/build_gamedata/translation/make_merge_wk.py b/code/nel/tools/build_gamedata/translation/make_merge_wk.py deleted file mode 100644 index 43c1ac325..000000000 --- a/code/nel/tools/build_gamedata/translation/make_merge_wk.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/python -# -# \author Jan Boon (Kaetemi) -# -# NeL - MMORPG Framework -# Copyright (C) 2014 by authors -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as -# published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -# - -import time, sys, os, shutil, subprocess, distutils.dir_util -sys.path.append("../configuration") -from scripts import * -from buildsite import * -from tools import * -os.chdir(TranslationDirectory) -if os.path.isfile("log.log"): - os.remove("log.log") -log = open("log.log", "w") - -printLog(log, "") -printLog(log, "-------") -printLog(log, "--- Make, merge and clean work") -printLog(log, "-------") -printLog(log, time.strftime("%Y-%m-%d %H:%MGMT", time.gmtime(time.time()))) -printLog(log, "") - - -TranslationTools = findTool(log, ToolDirectories, TranslationToolsTool, ToolSuffix) -printLog(log, ">>> Override languages.txt <<<") -if not os.path.isfile("make_merge_wk_languages.txt"): - shutil.move("languages.txt", "make_merge_wk_languages.txt") -languagesTxt = open("languages.txt", "w") -languagesTxt.write("wk\n") -languagesTxt.close() - - -printLog(log, ">>> Merge diff <<<") # This is necessary, because when we crop lines, we should only do this from untranslated files -try: - subprocess.call([ TranslationTools, "merge_phrase_diff" ]) - subprocess.call([ TranslationTools, "merge_clause_diff" ]) - subprocess.call([ TranslationTools, "merge_words_diff" ]) - subprocess.call([ TranslationTools, "merge_string_diff" ]) - subprocess.call([ TranslationTools, "merge_r2_string_diff" ]) - subprocess.call([ TranslationTools, "merge_worksheet_diff", "bot_names.txt" ]) -except Exception, e: - printLog(log, "<" + processName + "> " + str(e)) -printLog(log, "") - - -printLog(log, ">>> Make diff <<<") -try: - subprocess.call([ TranslationTools, "make_phrase_diff" ]) - subprocess.call([ TranslationTools, "make_clause_diff" ]) - subprocess.call([ TranslationTools, "make_words_diff" ]) - subprocess.call([ TranslationTools, "make_string_diff" ]) - subprocess.call([ TranslationTools, "make_r2_string_diff" ]) - subprocess.call([ TranslationTools, "make_worksheet_diff", "bot_names.txt" ]) -except Exception, e: - printLog(log, "<" + processName + "> " + str(e)) - - -printLog(log, ">>> Mark diffs as translated <<<") -diffFiles = os.listdir("diff") -for diffFile in diffFiles: - if "wk_diff_" in diffFile: - printLog(log, "DIFF " + "diff/" + diffFile) - subprocess.call([ TranslationTools, "crop_lines", "diff/" + diffFile, "3" ]) - -#printLog(log, ">>> Clean diff <<<") -#try: -# subprocess.call([ TranslationTools, "clean_string_diff" ]) -# subprocess.call([ TranslationTools, "clean_phrase_diff" ]) -# subprocess.call([ TranslationTools, "clean_clause_diff" ]) -# subprocess.call([ TranslationTools, "clean_words_diff" ]) -#except Exception, e: -# printLog(log, "<" + processName + "> " + str(e)) -#printLog(log, "") - -printLog(log, ">>> Merge diff <<<") -try: - subprocess.call([ TranslationTools, "merge_phrase_diff" ]) - subprocess.call([ TranslationTools, "merge_clause_diff" ]) - subprocess.call([ TranslationTools, "merge_words_diff" ]) - subprocess.call([ TranslationTools, "merge_string_diff" ]) - subprocess.call([ TranslationTools, "merge_r2_string_diff" ]) - subprocess.call([ TranslationTools, "merge_worksheet_diff", "bot_names.txt" ]) -except Exception, e: - printLog(log, "<" + processName + "> " + str(e)) -printLog(log, "") - - -printLog(log, ">>> Restore languages.txt <<<") -os.remove("languages.txt") -shutil.move("make_merge_wk_languages.txt", "languages.txt") - - -log.close() -if os.path.isfile("make_merge_wk.log"): - os.remove("make_merge_wk.log") -shutil.copy("log.log", "make_merge_wk_" + time.strftime("%Y-%m-%d-%H-%M-GMT", time.gmtime(time.time())) + ".log") -shutil.move("log.log", "make_merge_wk.log") - -raw_input("PRESS ANY KEY TO EXIT") diff --git a/code/ryzom/client/src/client_cfg.cpp b/code/ryzom/client/src/client_cfg.cpp deleted file mode 100644 index 055260673..000000000 --- a/code/ryzom/client/src/client_cfg.cpp +++ /dev/null @@ -1,2362 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010-2019 Winch Gate Property Limited -// -// This source file has been modified by the following contributors: -// Copyright (C) 2010 Robert TIMM (rti) -// Copyright (C) 2010-2019 Jan BOON (Kaetemi) -// Copyright (C) 2011-2012 Matt RAYKOWSKI (sfb) -// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - - -///////////// -// INCLUDE // -///////////// -#include "stdpch.h" -// Misc. -#include "nel/misc/config_file.h" -#include "nel/misc/bit_mem_stream.h" -#include "nel/misc/i18n.h" -#include "nel/misc/cmd_args.h" -// Client. -#include "client_cfg.h" -#include "entities.h" -#include "cursor_functions.h" -#include "debug_client.h" -#include "view.h" // For the cameraDistance funtion -#include "user_entity.h" -#include "misc.h" -#include "user_agent.h" - -// 3D Interface. -#include "nel/3d/u_driver.h" -#include "nel/3d/u_scene.h" -// Game Share. -#include "game_share/time_weather_season/time_and_season.h" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#ifdef NL_OS_MAC -#include "app_bundle_utils.h" -#endif // NL_OS_MAC - -/////////// -// MACRO // -/////////// -//----------------------------------------------- -/// Macro to read a Bool from the CFG. -/// variableName : Variable Name to Read and Set. -//----------------------------------------------- -#define _READ_BOOL(variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#variableName); \ - /* Value found, set the Variable */ \ - if(varPtr) \ - ClientCfg.variableName = varPtr->asInt() ? true : false; \ - /* Use the Default Value */ \ - else \ - cfgWarning("CFG: Default value used for '"#variableName"' !!!"); \ - -//----------------------------------------------- -/// Macro to read an Int from the CFG. -/// variableName : Variable Name to Read and Set. -//----------------------------------------------- -#define _READ_INT(variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#variableName); \ - /* Value found, set the Variable */ \ - if(varPtr) \ - ClientCfg.variableName = varPtr->asInt(); \ - /* Use the Default Value */ \ - else \ - cfgWarning("CFG: Default value used for '"#variableName"' !!!"); \ - -//----------------------------------------------- -/// Macro to read a Float from the CFG. -/// variableName : Variable Name to Read and Set. -//----------------------------------------------- -#define _READ_FLOAT(variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#variableName); \ - /* Value found, set the Variable */ \ - if(varPtr) \ - ClientCfg.variableName = varPtr->asFloat(); \ - /* Use the Default Value */ \ - else \ - cfgWarning("CFG: Default value used for '"#variableName"' !!!"); \ - -//----------------------------------------------- -/// Macro to read a Float from the CFG. -/// cfgVariableName : Variable Name to Read. -/// variableName : Variable Name to Set. -//----------------------------------------------- -#define _READ_FLOAT2(cfgVariableName,variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#cfgVariableName); \ - /* Value found, set the Variable */ \ - if(varPtr) \ - ClientCfg.variableName = varPtr->asFloat(); \ - /* Use the Default Value */ \ - else \ - cfgWarning("CFG: Default value used for '"#cfgVariableName"' !!!"); \ - -//----------------------------------------------- -/// Macro to read a Double from the CFG. -/// variableName : Variable Name to Read and Set. -//----------------------------------------------- -#define _READ_DOUBLE(variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#variableName); \ - /* Value found, set the Variable */ \ - if(varPtr) \ - ClientCfg.variableName = varPtr->asDouble(); \ - /* Use the Default Value */ \ - else \ - cfgWarning("CFG: Default value used for '"#variableName"' !!!"); \ - -//----------------------------------------------- -/// Macro to read a String from the CFG. -/// variableName : Variable Name to Read and Set. -//----------------------------------------------- -#define _READ_STRING(variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#variableName); \ - /* Value found, set the Variable */ \ - if(varPtr) \ - ClientCfg.variableName = varPtr->asString(); \ - /* Use the Default Value */ \ - else \ - cfgWarning("CFG: Default value used for '"#variableName"' !!!"); \ - -//----------------------------------------------- -/// Macro to read a CVector from the CFG. -/// variableName : Variable Name to Read and Set. -//----------------------------------------------- -#define _READ_CVECTOR(variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#variableName); \ - if(varPtr) \ - { \ - /* Check params */ \ - if(varPtr->size()==3) \ - { \ - ClientCfg.variableName.x = varPtr->asFloat(0); \ - ClientCfg.variableName.y = varPtr->asFloat(1); \ - ClientCfg.variableName.z = varPtr->asFloat(2); \ - } \ - else \ - cfgWarning("CFG: Bad params for '"#variableName"' !!!"); \ - } \ - else \ - cfgWarning("CFG: Default value used for '"#variableName"' !!!"); \ - - -//----------------------------------------------- -/// Macro to read an Enum, as int from the CFG. -/// variableName : Variable Name to Read and Set. -//----------------------------------------------- -#define _READ_ENUM_ASINT(type, variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#variableName); \ - /* Value found, set the Variable */ \ - if(varPtr) \ - ClientCfg.variableName = (type)varPtr->asInt(); \ - /* Use the Default Value */ \ - else \ - cfgWarning("CFG: Default value used for '"#variableName"' !!!"); \ - -//----------------------------------------------- -/// Macro to read a String Vector from the CFG. -/// variableName : Variable Name to Read and Set. -//----------------------------------------------- -#define _READ_STRINGVECTOR(variableName) \ - /* Read the Variable Value From Script */ \ - varPtr = ClientCfg.ConfigFile.getVarPtr(#variableName); \ - /* Value found, set the Variable */ \ - if(varPtr) \ - { \ - ClientCfg.variableName.clear (); \ - int iSz = varPtr->size(); \ - ClientCfg.variableName.reserve(iSz); \ - for (int i = 0; i < iSz; i++) \ - ClientCfg.variableName.push_back(varPtr->asString(i)); \ - } \ - /* Use the Default Value */ \ - else \ - cfgWarning("CFG: Default value used for '"#variableName"' !!!"); \ - -//----------------------------------------------- -// Macro for the dev version -//----------------------------------------------- - -#if !FINAL_VERSION -#define READ_BOOL_DEV(variableName) _READ_BOOL(variableName) -#define READ_INT_DEV(variableName) _READ_INT(variableName) -#define READ_FLOAT_DEV(variableName) _READ_FLOAT(variableName) -#define READ_FLOAT2_DEV(cfgVariableName,variableName) _READ_FLOAT2(cfgVariableName,variableName) -#define READ_DOUBLE_DEV(variableName) _READ_DOUBLE(variableName) -#define READ_STRING_DEV(variableName) _READ_STRING(variableName) -#define READ_CVECTOR_DEV(variableName) _READ_CVECTOR(variableName) -#define READ_ENUM_ASINT_DEV(type, variableName) _READ_ENUM_ASINT(type, variableName) -#define READ_STRINGVECTOR_DEV(variableName) _READ_STRINGVECTOR(variableName) -#else // !FINAL_VERSION -#define READ_BOOL_DEV(variableName) -#define READ_INT_DEV(variableName) -#define READ_FLOAT_DEV(variableName) -#define READ_FLOAT2_DEV(cfgVariableName,variableName) -#define READ_DOUBLE_DEV(variableName) -#define READ_STRING_DEV(variableName) -#define READ_CVECTOR_DEV(variableName) -#define READ_ENUM_ASINT_DEV(type, variableName) -#define READ_STRINGVECTOR_DEV(variableName) -#endif // !FINAL_VERSION - -//----------------------------------------------- -// Macro for the dev & final version -//----------------------------------------------- - -#define READ_BOOL_FV(variableName) _READ_BOOL(variableName) -#define READ_INT_FV(variableName) _READ_INT(variableName) -#define READ_FLOAT_FV(variableName) _READ_FLOAT(variableName) -#define READ_FLOAT2_FV(cfgVariableName,variableName) _READ_FLOAT2(cfgVariableName,variableName) -#define READ_DOUBLE_FV(variableName) _READ_DOUBLE(variableName) -#define READ_STRING_FV(variableName) _READ_STRING(variableName) -#define READ_CVECTOR_FV(variableName) _READ_CVECTOR(variableName) -#define READ_ENUM_ASINT_FV(type, variableName) _READ_ENUM_ASINT(type, variableName) -#define READ_STRINGVECTOR_FV(variableName) _READ_STRINGVECTOR(variableName) - -/////////// -// USING // -/////////// -using namespace NLMISC; -using namespace NL3D; - - -//////////// -// GLOBAL // -//////////// -CClientConfig LastClientCfg; -CClientConfig ClientCfg; -const string ConfigFileName = "client.cfg"; - - -//////////// -// EXTERN // -//////////// -#ifndef RZ_NO_CLIENT -extern NL3D::UScene *Scene; -extern NL3D::UDriver *Driver; -extern CRyzomTime RT; -extern string Cookie; -extern string FSAddr; -#endif - -extern NLMISC::CCmdArgs Args; - -///////////// -// METHODS // -///////////// - -// diplay only one time warning "Default values...." -static bool DisplayCFGWarning= false; -static void cfgWarning(const char *s) -{ - if(DisplayCFGWarning) - nlwarning(s); -} - -//--------------------------------------------------- -// CClientConfig : -// Constructor. -//--------------------------------------------------- -CClientConfig::CClientConfig() -{ - IsInvalidated = false; - - TestBrowser = false; - Light = false; // Default is no client light version - SaveConfig = false; - - PositionX = 0; - PositionY = 0; - Frequency = 60; - - SkipIntro = false; - SelectCharacter = -1; // Default is no auto select - SelectedSlot = 0; // Default is slot 0 - - Windowed = false; // Default is windowed mode. - Width = 0; // Default Width for the window (0 = current screen resolution). - Height = 0; // Default Height for the window (0 = current screen resolution). - Depth = 32; // Default Bit per Pixel. - Driver3D = DrvAuto; // Select best driver depending on hardware. - Contrast = 0.f; // Default Monitor Contrast. - Luminosity = 0.f; // Default Monitor Luminosity. - Gamma = 0.f; // Default Monitor Gamma. - - InterfaceScale = 1.0f; // Resize UI - InterfaceScale_min = 0.8f; - InterfaceScale_max = 2.0f; - InterfaceScale_step = 0.05; - BilinearUI = true; - - WindowSnapInvert = false; - WindowSnapDistance = 10; - - VREnable = false; - VRDisplayDevice = "Auto"; - VRDisplayDeviceId = ""; - - Local = false; // Default is Net Mode. - FSHost = ""; // Default Host. - - TexturesInterface.push_back("texture_interfaces_v3_2x"); - TexturesInterfaceDXTC.push_back("texture_interfaces_dxtc_2x"); - - TexturesOutGameInterface.push_back("texture_interfaces_v3_outgame_ui"); - - TexturesLoginInterface.push_back("texture_interfaces_v3_login"); - - DisplayAccountButtons = true; - CreateAccountURL = RYZOM_CLIENT_CREATE_ACCOUNT_URL; // "https://open.ryzom.dev/ams/"; - EditAccountURL = RYZOM_CLIENT_EDIT_ACCOUNT_URL; // "https://open.ryzom.dev/ams/"; - ForgetPwdURL = RYZOM_CLIENT_FORGET_PASSWORD_URL; // "https://open.ryzom.dev/ams/"; - Position = CVector(0.f, 0.f, 0.f); // Default Position. - Heading = CVector(0.f, 1.f, 0.f); // Default Heading. - EyesHeight = 1.5f; // Default User Eyes Height. - Walk = 1.66f; // Default Velocity for the Walk. - Run = 6.0f; // Default Velocity for the Run. - Fly = 25.0f; // Default Velocity for the Fly. - DmWalk = 6.0f; // Default Velocity for the Walk in Ring/DM or Ring/Editor. - DmRun = 20.0f; // Default Velocity for the Run in Ring/DM or Ring/Editor. - - FlyAccel = 1000.f; // Default Acceleration for the fly, in m.s-2 - - AllowDebugCommands = false; // Add debug commands at startup - - ForceDeltaTime = 0; // Default ForceDeltaTime, disabled by default - - HardwareCursor = true; // Default HardwareCursor - HardwareCursorScale = 0.85f; - CursorSpeed = 1.f; // Default CursorSpeed - CursorAcceleration = 0; // Default CursorAcceleration - FreeLookSpeed = 0.001f; // Default FreeLookSpeed - FreeLookAcceleration = 0; // Default FreeLookAcceleration - FreeLookSmoothingPeriod = 0.f; // when in absolute mode, free look factor is used instead of speed, the mouse gives the absolute angle - FreeLookInverted = false; - FreeLookTablet = false; // Mouse reports absolute coordinates, so avoid mouse recentering - AutomaticCamera = true; - DblClickMode = true; // when in dbl click mode, a double click is needed to execute default contextual action - AutoEquipTool = true; // when true player will auto-equip last used weapon or forage tool when doing an action - - BGColor = CRGBA(100,100,255); // Default Background Color. - LandscapeTileNear = 50.0f; // Default Landscape Tile Near. - LandscapeThreshold = 1000.0f; // Default Landscape Threshold. - Vision = 500.f; // Player vision. - Vision_min = 200.f; // Player vision min. - Vision_max = 800.f; // Player vision max. - SkinNbMaxPoly = 40000; - FxNbMaxPoly = 10000; - Cloud = true; - CloudQuality = 160.0f; - CloudUpdate = 1; - NbMaxSkeletonNotCLod= 20; - CharacterFarClip = 200.f; - ScreenAspectRatio = 0.f; // Default commmon Screen Aspect Ratio (no relation with the resolution) - 0.f = auto - FoV = 75.f; // Default value for the FoV. - ForceDXTC = false; // Default is no DXTC Compression. - AnisotropicFilter = 0; // Default is disabled (-1 = maximum value, 0 = disabled, 1+ = enabled) - DivideTextureSizeBy2= false; // Divide texture by 2 - DisableVtxProgram = false; // Disable Hardware Vertex Program. - DisableVtxAGP = false; // Disable Hardware Vertex AGP. - DisableTextureShdr = false; // Disable Hardware Texture Shader. - MicroVeget = true; // Default is with MicroVeget. - MicroVegetDensity = 100.0f; - HDEntityTexture = false; - HDTextureInstalled = false; - Fog = true; // Fog is on by default - WaitVBL = false; - VideoMemory = 0; - - FXAA = true; - - Bloom = true; - SquareBloom = true; - DensityBloom = 255.f; - - GlobalWindPower = 0.10f; // Default is 0.25 - GlobalWindDirection = CVector(1,0,0); // Default direction is X>0 - - MovieShooterMemory = 0; // MovieShooter disabled - MovieShooterFramePeriod = 0.040f; // default is 25 fps - MovieShooterBlend = false; - MovieShooterFrameSkip = 0; // default not skip frame - MovieShooterPrefix = "shot_"; - - CameraRecorderPrefix = "cam_rec"; - CameraRecorderBlend = true; - - ScreenShotWidth = 0; - ScreenShotHeight = 0; - ScreenShotFullDetail = true; - ScreenShotZBuffer = false; - - MaxNumberOfTimedFXInstances = 20; - SelectionFX = "sfx_selection_mouseover.ps"; - MouseOverFX = "sfx_selection_mouseover.ps"; - SelectionFXSize = 0.8f; - -#if RZ_USE_PATCH - PatchWanted = true; -#else - PatchWanted = false; -#endif - - PatchUrl.clear(); - PatchletUrl.clear(); - PatchVersion.clear(); - - WebIgMainDomain = RYZOM_WEBIG_MAIN_URL; // https://open.ryzom.dev/" - WebIgTrustedDomains.push_back(RYZOM_WEBIG_TRUSTED_DOMAIN); // open.ryzom.dev - WebIgNotifInterval = 10; // time in minutes - - CurlMaxConnections = 5; - CurlCABundle.clear(); - - RingReleaseNotePath = WebIgMainDomain + "/app_releasenotes/index.php"; - ReleaseNotePath = WebIgMainDomain + "/app_releasenotes/index.php"; - - - /////////////// - // ANIMATION // - // With a bigger angle, rotation is animated. - AnimatedAngleThreshold = 25.0; // - BlendFrameNumber = 5; // - DestThreshold = 0.01; // Destination Threshold - PositionLimiterRadius = 0.1; - SignificantDist = 0.0001; // Significant Distance - /////////// - // SOUND // - SoundOn = true; // Default is with sound. - DriverSound = SoundDrvAuto; - SoundForceSoftwareBuffer = true; - SoundOutGameMusic = "main menu loop.ogg"; - SoundSFXVolume = 1.f; - SoundGameMusicVolume = 1.f; - SoundTPFade = 500; - EnableBackgroundMusicTimeConstraint = true; - - SoundPackedSheetPath= "data/sound/"; // Default path for sound packed sheets - SampleBankDir = "data/sound/samplebanks"; // Default path for samples - UserEntitySoundLevel = 0.5f; // Default volume for sound in 1st person - UseEax = true; // Default to use EAX; - UseADPCM = false; // Defualt to PCM sample, NO ADPCM - MaxTrack = 32; // DEfault to 32 track - - ColorShout = CRGBA(150,0,0,255); // Default Shout color. - ColorTalk = CRGBA(255,255,255,255); // Default Talk color. - - StreamedPackagePath = "stream"; - - // MP3 player - MediaPlayerDirectory = "music"; - MediaPlayerAutoPlay = false; - -// PreDataPath.push_back("data/gamedev/language/"); // Default Path for the language data - -// DataPath.push_back("data/"); // Default Path for the Data. -// DataPath.push_back("data_leveldesign/"); // Default Path for the Level Design Directory. -// DataPath.push_back("data_common/"); // Default Path for the Level Design Directory. - - DataPathNoRecurse.push_back("data_leveldesign/leveldesign/Game_Elem"); - - UpdatePackedSheetPath.push_back("data_leveldesign"); - - UpdatePackedSheet = false; // Update packed sheet if needed - - EndScreenTimeOut = 0.f; // Default time out for the screen at the end of the application. - Loading_BG = "loading_bg.tga"; // Default name for the loading background file. - LoadingFreeTrial_BG = "loading_free_trial_bg.tga"; // Default name for the loading background file in FreeTrial mode. - Launch_BG = "launcher_bg.tga"; // Default name for the launch background file. - TeleportKami_BG = "teleport_kami_bg.tga"; - TeleportKaravan_BG = "teleport_caravan_bg.tga"; - Elevator_BG = "elevator_bg.tga"; // Default name for the loading background file. - ResurectKami_BG = "resurect_kami_bg.tga"; - ResurectKaravan_BG = "resurect_caravane_bg.tga"; - End_BG = "end_bg.tga"; // Default name for the last background file. - IntroNevrax_BG = "launcher_nevrax.tga"; - IntroNVidia_BG = "launcher_nvidia.tga"; - - TipsY = 0.07f; - TeleportInfoY = 0.23f; - - SceneName = ""; - IdFilePath = "sheet_id.bin"; - PacsPrimDir.push_back("data/3d/"); - - Shadows = true; // Draw Shadows by default. - ShadowsClipFar = 10.f; // Shadows are disabled after this distance. - ShadowsLodDist = 3.f; // Shadows draw with just 1 part after this distance. - ShadowZDirClampLandscape = -0.5f; // On landscape, allow a minimum Phi angle of -30 degrees - ShadowZDirClampInterior = -0.86f; // On Interior, allow a minimum Phi angle of -60 degrees - ShadowZDirClampSmoothSpeed = 0.5f; - ShadowMaxDepthLandscape = 8.f; - ShadowMaxDepthInterior = 2.f; - ShadowMaxDepthSmoothSpeed = 6.f; - - - Names = false; // Don't draw Names by default. - - Sleep = -1; // Default : client does not sleep. - ProcessPriority = 0; // Default : NORMAL - CPUMask = 0; // Default : auto detection - ShowPath = false; // Default : do not display the path. - DrawBoxes = false; // Default : Do not draw the selection. - - UserSheet = "fyros.race_stats"; // Default sheet used. - Sex = GSGENDER::male; // Default : male. - - PrimitiveHeightAddition = 2.f; // Default : 2.f - - AttackDist = 0.5f; - RyzomDay = 0; - RyzomTime = 0.0f; - - ManualWeatherSetup = false; - - ChaseReactionTime = 0.4f; // Reaction time before chasing someone. - - TimeToAdjustCamera = 1000.0; - ChangeDirAngle = 1.70f; // Default Angle. - - GuildSymbolSize = 0.3f; // Default Guild Symbol Size. - SelectionDist = 150.f; // Default dist in meter. - SelectionOutBBoxWeight = 16.f; // Default factor - LootDist = 4.f; // Default loot/harvest distance (in meter). - SpaceSelectionDist = 50.f; - SpaceSelectionMaxCycle = 1; - - ForceLanguage = false; - LanguageCode = "en"; // Default to english - DebugStringManager = false; // Default to no debug - - // TUNING - WaterOffset = -1.085f; - FyrosWaterOffset = -1.0f; - MatisWaterOffset = -1.08f; - TrykerWaterOffset = -0.88f; - ZoraiWaterOffset = -1.25f; - WaterOffsetCreature = -1.6f; - TimeToRemoveCol = 1000; - MoveToTimeToStopStall = 500; - TPVMinPitch = -1.5f; - TPVMaxPitch = 1.5f; - MaxHeadTargetDist = 30.0f; - DeadFXName = "misc_dead.ps"; - ImpactFXName = "impact.ps"; - SkillUpFXName = "misc_levelup.ps"; - MinDistFactor = 0.5; - NameScale = 1.0f; // Default Scale to display Names. - NamePos = 0.02f; - NameFontSize = 20; - MaxNameDist = 50.0f; - ConstNameSizeDist = 20.0f; - StaticNameHeight = true; - BarsHeight = 0.002f; - BarsWidth = 0.05f; - FightAreaSize = 1.5; - BubbleZBias = -3.f; - ForageInterfaceZBias= -10.f; - FyrosScale = 1.0f; - MatisScale = 1.08f; - TrykerScale = 0.88f; - ZoraiScale = 1.25f; - EnableRacialAnimation = true; - - // OPTIONS - RunAtTheBeginning = true; - SelectWithRClick = false; // Default right click cannot select. - RotKeySpeedMax = 3.0f; - RotKeySpeedMin = 1.0f; - RotAccel = 0.001f; - PutBackItems = false; - ShowNameUnderCursor = true; - ShowNameSelected = true; - ShowNameBelowDistanceSqr = 20.f * 20.f; - ForceIndoorFPV = false; - FollowOnAtk = true; - AtkOnSelect = false; - TransparentUnderCursor = false; - ItemGroupAllowGuild = false; - // PREFERENCES - FPV = false; - CameraHeight = 2.5f; - CameraDistance = 3.0f; - CameraDistStep = 1.0f; - CameraDistMin = 1.0f; - CameraDistMax = 100.0f; - DmCameraDistMax = 25.0f; - CameraAccel = 0.2f; - CameraSpeedMin = 0.2f; - CameraSpeedMax = 1.0f; - CameraResetSpeed = 2.0f; - - MaxMapScale = 2.0f; - R2EDMaxMapScale = 8.0f; - - TargetChangeCompass = true; - - // VERBOSES - VerboseVP = false; - VerboseAnimUser = false; - VerboseAnimSelection = false; - VerboseAllTraffic = false; - - // DEBUG - DisplayMissingAnimFile = false; - DefaultEntity = "ccafb1.creature"; - RestrainPI = true; - DumpVSIndex = false; - HelpFontSize = 12; - HelpFontColor = CRGBA(255,255,255); - HelpLineStep = 0.025f; - DebugFontSize = 16; - DebugFontColor = CRGBA(250, 250, 250); - DebugLineStep = 0.02f; - HeadOffset = CVector(0.f, 0.f, 0.f); - Check = false; - BlendForward = true; - // - FPExceptions = false; // Disable Floating Point Exceptions. - DisplayWeapons = false; // Do not dusplay weapons in first person. - NeedComputeVS = false; // Do not need to compute Visual Slots. - // - GroundFXMaxDist = 40.f; - GroundFXMaxNB = 10; - GroundFXCacheSize = 10; - // - AutoReloadFiles = false; - BlendShapePatched = true; - ExtendedCommands = false; - - WaterEnvMapUpdateTime = 1.f; - - NumFrameForProfile = 0; - SimulateServerTick = false; - TimerMode= 0; - - KlientChatPort= ""; - - PreCacheShapes = true; - ResetShapeBankOnRetCharSelect = false; - LandscapeEnabled = true; - VillagesEnabled = true; - EAMEnabled = true; - CacheUIParsing = false; - MicroLifeEnabled = true; - - SkipEULA = false; - - StageLCTUsage= StageUsePosOnlyLCT; - - SimulatePacketLossRatio= 0; - - CheckMemoryEveryNFrame= -1; - LogMemoryAllocation=false; - LogMemoryAllocationSize=8; - - DamageShieldEnabled = false; - - LevelDesignEnabled = false; - - R2Mode = true; - R2EDEnabled = false; - R2EDExtendedDebug = false; - R2EDVerboseParseTime = false; - R2EDDontReparseUnchangedUIFiles = false; - R2EDLightPalette = false; - R2EDAutoSaveWait = 60*5; - R2EDAutoSaveSlot = 9; - R2EDMustVerifyRingAccessWhileLoadingAnimation = false; - R2EDUseVerboseRingAccess = false; - R2EDDssNetwork = 3; - - DamageShieldEnabled = false; - - AllowDebugLua = false; - DisplayLuaDebugInfo = false; - BeepWhenLaunched = false; - - - - LoadingStringCount = 0; - - LuaDebugInfoGotoButtonEnabled = false; - - FogDistAndDepthLookupBias = 0.f; - - R2EDLoadDynamicFeatures = 0; - - CheckR2ScenarioMD5 = true; - - DisplayTPReason = false; - - //TPCancelButtonX = 988; - //TPCancelButtonY = 138; - //TPQuitButtonX = 8; - //TPQuitButtonY = 138; - TPButtonW = 32; - TPButtonH = 32; - - //SAVE - ScenarioSavePath = "./my_scenarios/"; - - R2EDClippedEntityBlendTime = 0.18f; - - BackgroundDownloader = false; - -}// CClientConfig // - - -//--------------------------------------------------- -// load : -// Load the client config file. -//--------------------------------------------------- -void CClientConfig::setValuesOnFileChange() -{ - // ClientCfg.ConfigFile.print (InfoLog); - - // display an info only when the file change - nlinfo ("reloading the config file!"); - - setValues(); -} - -//--------------------------------------------------- -// load : -// Load the client config file. -//--------------------------------------------------- -void CClientConfig::setValues() -{ - CConfigFile::CVar *varPtr = 0; - static bool firstTimeSetValues= true; - - ////////////////////// - // INTERFACE CONFIG // - // input files - READ_STRING_FV(XMLInputFile) - - - READ_BOOL_FV(SkipIntro); - READ_BOOL_DEV(SkipEULA); - READ_INT_DEV(SelectCharacter); - - READ_INT_FV(SelectedSlot); - if( ClientCfg.SelectedSlot>4 ) - { - ClientCfg.SelectedSlot = 0; - } - - // interface textures login menus - READ_STRINGVECTOR_FV(TexturesLoginInterface); - READ_STRINGVECTOR_FV(TexturesLoginInterfaceDXTC); - - // interface textures outgame menus - READ_STRINGVECTOR_FV(TexturesOutGameInterface); - READ_STRINGVECTOR_FV(TexturesOutGameInterfaceDXTC); - - // interface textures ingame and r2 - //READ_STRINGVECTOR_FV(TexturesInterface); - //READ_STRINGVECTOR_FV(TexturesInterfaceDXTC); - - // interface files login menus - READ_STRINGVECTOR_FV(XMLLoginInterfaceFiles); - - // interface files outgame menus - READ_STRINGVECTOR_FV(XMLOutGameInterfaceFiles); - - // interface files - READ_STRINGVECTOR_FV(XMLInterfaceFiles); - - // r2ed interfaces - READ_STRINGVECTOR_FV(XMLR2EDInterfaceFiles); - - // logos - READ_STRINGVECTOR_FV(Logos); - - // browser test mode - READ_BOOL_DEV(TestBrowser); - READ_STRING_DEV(TestBrowserUrl); - - // ClientLight -#if !FINAL_VERSION - varPtr = ClientCfg.ConfigFile.getVarPtr ("ClientLight"); - if (varPtr) - ClientCfg.Light = varPtr->asInt() ? true : false; -#endif // !FINAL_VERSION - - - READ_BOOL_DEV(LandscapeEnabled) - READ_BOOL_DEV(VillagesEnabled) - READ_BOOL_DEV(EAMEnabled) - READ_BOOL_DEV(CacheUIParsing) - READ_BOOL_DEV(MicroLifeEnabled) - - READ_BOOL_DEV(LevelDesignEnabled) - - /////////////////// - // WINDOW CONFIG // - // Mode. - - // SaveConfig - READ_BOOL_FV(SaveConfig) - - // Window Positon - READ_INT_FV(PositionX) - READ_INT_FV(PositionY) - - // Window frequency - READ_INT_FV(Frequency) - - CConfigFile::CVar *pcvFullScreen = ClientCfg.ConfigFile.getVarPtr("FullScreen"); - if( pcvFullScreen ) - { - ClientCfg.Windowed = pcvFullScreen->asInt() ? false : true; - } - else - cfgWarning("Default value used for 'Fullscreen'"); - // Width - READ_INT_FV(Width) - // Height - READ_INT_FV(Height) - // Depth : Bit Per Pixel - READ_INT_FV(Depth) - // Contrast - READ_FLOAT_FV(Contrast) - // Luminosity - READ_FLOAT_FV(Luminosity) - // Gamma - READ_FLOAT_FV(Gamma) - // UI scaling - READ_FLOAT_FV(InterfaceScale); - READ_FLOAT_FV(InterfaceScale_min); - READ_FLOAT_FV(InterfaceScale_max); - READ_FLOAT_FV(InterfaceScale_step); - clamp(ClientCfg.InterfaceScale, ClientCfg.InterfaceScale_min, ClientCfg.InterfaceScale_max); - READ_BOOL_FV(BilinearUI); - READ_BOOL_FV(WindowSnapInvert); - READ_INT_FV(WindowSnapDistance); - // 3D Driver - varPtr = ClientCfg.ConfigFile.getVarPtr ("Driver3D"); - if (varPtr) - { - if (nlstricmp(varPtr->asString(), "Auto") == 0 || nlstricmp(varPtr->asString(), "0") == 0) ClientCfg.Driver3D = CClientConfig::DrvAuto; - else if (nlstricmp(varPtr->asString(), "OpenGL") == 0 || nlstricmp(varPtr->asString(), "1") == 0) ClientCfg.Driver3D = CClientConfig::OpenGL; - else if (nlstricmp(varPtr->asString(), "Direct3D") == 0 || nlstricmp(varPtr->asString(), "2") == 0) ClientCfg.Driver3D = CClientConfig::Direct3D; - else if (nlstricmp(varPtr->asString(), "OpenGLES") == 0 || nlstricmp(varPtr->asString(), "3") == 0) ClientCfg.Driver3D = CClientConfig::OpenGLES; - } - else - cfgWarning ("Default value used for 'Driver3D' !!!"); - - READ_BOOL_FV(VREnable) - READ_STRING_FV(VRDisplayDevice) - READ_STRING_FV(VRDisplayDeviceId) - - //////////// - // INPUTS // - READ_BOOL_FV(HardwareCursor) - READ_FLOAT_FV(HardwareCursorScale) - READ_FLOAT_FV(CursorSpeed) - READ_INT_FV(CursorAcceleration) - READ_FLOAT_FV(FreeLookSpeed) - READ_INT_FV(FreeLookAcceleration) - READ_FLOAT_FV(FreeLookSmoothingPeriod) - READ_BOOL_FV(FreeLookInverted) - READ_BOOL_FV(FreeLookTablet) - READ_BOOL_FV(AutomaticCamera) - READ_BOOL_FV(DblClickMode) - READ_BOOL_FV(AutoEquipTool) - - ///////// - // NET // -#if !FINAL_VERSION - // Local : local mode or network mode - READ_BOOL_DEV(Local) -#endif // FINAL_VERSION - // FSHost - READ_STRING_FV(FSHost) - - READ_BOOL_DEV(DisplayAccountButtons) - - - READ_STRING_FV(CreateAccountURL) - READ_STRING_FV(EditAccountURL) - READ_STRING_FV(ForgetPwdURL) - - READ_STRING_DEV(BetaAccountURL) - READ_STRING_DEV(FreeTrialURL) - - // defined in client_default.cfg - READ_STRING_FV(LoginSupportURL) - - // read NamingPolicyURL from client_default.cfg - //READ_STRING_FV(NamingPolicyURL) - - std::string languageCo = "wk"; - CConfigFile::CVar *languageCodeVarPtr = ClientCfg.ConfigFile.getVarPtr("LanguageCode"); - - if (languageCodeVarPtr) - { - languageCo = languageCodeVarPtr->asString(); - } - - CConfigFile::CVar *policyurl = ClientCfg.ConfigFile.getVarPtr("NamingPolicyURL"); - - if (policyurl) - { - for (uint i = 0; i < policyurl->size(); ++i) - { - std::string entry = policyurl->asString(i); - if (entry.size() >= languageCo.size()) - { - if (nlstricmp(entry.substr(0, languageCo.size()), languageCo) == 0) - { - std::string::size_type pos = entry.find("="); - - if (pos != std::string::npos) - { - ClientCfg.NamingPolicyURL = entry.substr(pos + 1); - } - } - } - } - } - - // read NamingPolicyURL from client_default.cfg - //READ_STRING_FV(ConditionsTermsURL) - CConfigFile::CVar *coturl = ClientCfg.ConfigFile.getVarPtr("ConditionsTermsURL"); - - if (coturl) - { - for (uint i = 0; i < coturl->size(); ++i) - { - std::string entry = coturl->asString(i); - - if (entry.size() >= languageCo.size()) - { - if (nlstricmp(entry.substr(0, languageCo.size()), languageCo) == 0) - { - std::string::size_type pos = entry.find("="); - - if (pos != std::string::npos) - { - ClientCfg.ConditionsTermsURL = entry.substr(pos + 1); - } - } - } - } - } - - -#ifndef RZ_NO_CLIENT - // if cookie is not empty, it means that the client was launch - // by the nel_launcher, so it can't be local - if(!Cookie.empty()) - { - nlassert (!FSAddr.empty()); - ClientCfg.Local = false; - } - else - { - nlassert (FSAddr.empty()); - } -#endif - - ///////////////// - // USER ENTITY // - READ_CVECTOR_DEV(Position) - READ_CVECTOR_DEV(Heading) - // EyesHeight - READ_FLOAT_DEV(EyesHeight) - - // Walk - READ_FLOAT_DEV(Walk) - // Run - READ_FLOAT_DEV(Run) - - //When editing or Dm ing a session in ring mode the player move quicker - // DM Walk - READ_FLOAT_DEV(DmWalk) - // DM Run - READ_FLOAT_DEV(DmRun) - - - - // Fly - READ_FLOAT_DEV(Fly) - READ_FLOAT_DEV(FlyAccel) - - READ_BOOL_FV(AllowDebugCommands) - - // ForceDeltaTime - READ_INT_DEV(ForceDeltaTime) - - //////////// - // RENDER // - // Background Color -#if !FINAL_VERSION - CConfigFile::CVar *pcvBackColor = ClientCfg.ConfigFile.getVarPtr("Background"); - if( pcvBackColor && (pcvBackColor->size()==3) ) - { - ClientCfg.BGColor.R = pcvBackColor->asInt(0); - ClientCfg.BGColor.G = pcvBackColor->asInt(1); - ClientCfg.BGColor.B = pcvBackColor->asInt(2); - ClientCfg.BGColor.A = 255; - } - else - cfgWarning("Default value used for 'Background'"); -#endif // !FINAL_VERSION - // LandscapeTileNear - READ_FLOAT_FV(LandscapeTileNear) - // LandscapeThreshold - READ_FLOAT_FV(LandscapeThreshold) - // to be backward compatible, suppose a value<1 is for the old System!!! => invert it! - if( ClientCfg.LandscapeThreshold<1) - { - ClientCfg.LandscapeThreshold= 1.f/ ClientCfg.LandscapeThreshold; - // must re-write in the CFG database, to be ok with the in-game configurator - varPtr = ClientCfg.ConfigFile.getVarPtr("LandscapeThreshold"); - if(varPtr) - varPtr->forceAsDouble(ClientCfg.LandscapeThreshold); - } - // Vision - READ_FLOAT_FV(Vision) - READ_FLOAT_FV(Vision_min) - READ_FLOAT_FV(Vision_max) - // SkinNbMaxPoly - READ_INT_FV(SkinNbMaxPoly) - // FxNbMaxPoly - READ_INT_FV(FxNbMaxPoly) - READ_BOOL_FV(Cloud) - READ_FLOAT_FV(CloudQuality) - READ_INT_FV(CloudUpdate) - // NbMaxSkeletonNotCLod - READ_INT_FV(NbMaxSkeletonNotCLod) - // CharacterFarClip - READ_FLOAT_FV(CharacterFarClip) - - // Bloom - READ_BOOL_FV(Bloom) - READ_BOOL_FV(SquareBloom) - READ_FLOAT_FV(DensityBloom) - - // FXAA - READ_BOOL_FV(FXAA) - - // ScreenAspectRatio. - READ_FLOAT_FV(ScreenAspectRatio) - // FoV. - READ_FLOAT_FV(FoV) - // ForceDXTC - READ_BOOL_FV(ForceDXTC) - // AnisotropicFilter - READ_INT_FV(AnisotropicFilter) - // DivideTextureSizeBy2 - READ_BOOL_FV(DivideTextureSizeBy2) - // DisableVtxProgram - READ_BOOL_FV(DisableVtxProgram) - // DisableVtxAGP - READ_BOOL_FV(DisableVtxAGP) - // DisableTextureShdr - READ_BOOL_FV(DisableTextureShdr) - // MicroVeget - READ_BOOL_FV(MicroVeget) - // MicroVeget Density - READ_FLOAT_FV(MicroVegetDensity) - // GlobalWindPower: Global Wind Power - READ_FLOAT_DEV(GlobalWindPower) - // Global Wind Direction - READ_CVECTOR_DEV(GlobalWindDirection) - // HDEntityTexture - READ_BOOL_FV(HDEntityTexture) - // HDTextureInstalled - READ_BOOL_FV(HDTextureInstalled) - - // Fog - READ_BOOL_DEV(Fog) - - // WaitVBL - READ_BOOL_FV(WaitVBL) - // VideoMemory - READ_INT_FV(VideoMemory); - - READ_INT_DEV(TimerMode) - - // MovieShooterMemory - CConfigFile::CVar *pcv = ClientCfg.ConfigFile.getVarPtr("MovieShooterMemory"); - if( pcv ) - { - ClientCfg.MovieShooterMemory = pcv->asInt(); - // Transform to octet - ClientCfg.MovieShooterMemory *= 1024*1024; - } - else - cfgWarning("'MovieShooterMemory' not found => MovieShooter Disabled"); - // MovieShooterPath - READ_STRING_FV(MovieShooterPath) - // MovieShooterFramePeriod - READ_FLOAT_FV(MovieShooterFramePeriod) - // MovieShooterBlend - READ_BOOL_FV(MovieShooterBlend) - // MovieShooterFrameSkip - READ_INT_FV(MovieShooterFrameSkip) - - // Camera Recorder - READ_STRING_FV(CameraRecorderPath) - READ_STRING_FV(CameraRecorderPrefix) - READ_BOOL_FV(CameraRecorderBlend) - - // Screenshot - READ_INT_FV(ScreenShotWidth) - READ_INT_FV(ScreenShotHeight) - READ_BOOL_FV(ScreenShotFullDetail) - READ_BOOL_FV(ScreenShotZBuffer) - - ///////////////////////// - // NEW PATCHING SYSTEM // - READ_BOOL_FV(PatchWanted) - -#ifdef RZ_USE_CUSTOM_PATCH_SERVER - READ_STRING_FV(PatchUrl) - READ_STRING_FV(PatchVersion) - READ_STRING_FV(RingReleaseNotePath) - READ_STRING_FV(ReleaseNotePath) -#else - READ_STRING_DEV(PatchUrl) - READ_STRING_DEV(PatchVersion) - READ_STRING_DEV(RingReleaseNotePath) - READ_STRING_DEV(ReleaseNotePath) -#endif - - ///////////////////////// - // NEW PATCHLET SYSTEM // - READ_STRING_FV(PatchletUrl) - - /////////// - // WEBIG // - READ_STRING_FV(WebIgMainDomain); - if (ClientCfg.WebIgMainDomain.find("http://") == std::string::npos - || ClientCfg.WebIgMainDomain.find("https://") == std::string::npos) - ClientCfg.WebIgMainDomain = "http://" + ClientCfg.WebIgMainDomain; - READ_STRINGVECTOR_FV(WebIgTrustedDomains); - READ_INT_FV(WebIgNotifInterval); - READ_INT_FV(CurlMaxConnections); - if (ClientCfg.CurlMaxConnections < 0) - ClientCfg.CurlMaxConnections = 2; - - READ_STRING_FV(CurlCABundle); - if (!ClientCfg.CurlCABundle.empty() && ClientCfg.CurlCABundle[0] == '%') // Path is relative to client_default.cfg path (used by ryzom patch) - { - string defaultConfigFileName; - if (ClientCfg.getDefaultConfigLocation(defaultConfigFileName)) - ClientCfg.CurlCABundle = CFile::getPath(defaultConfigFileName)+ClientCfg.CurlCABundle.substr(1); - } - - /////////////// - // ANIMATION // - // AnimatedAngleThreshold - READ_DOUBLE_DEV(AnimatedAngleThreshold) - // BlendFrameNumber - READ_INT_DEV(BlendFrameNumber) - // DestThreshold - READ_DOUBLE_DEV(DestThreshold) - // PositionLimiterRadius - READ_DOUBLE_DEV(PositionLimiterRadius) - // SignificantDist - READ_DOUBLE_DEV(SignificantDist) - // Stage LCT usage - READ_ENUM_ASINT_DEV(TStageLCTUsage, StageLCTUsage) - - //////////// - // TUNING // - // Water Offset - READ_FLOAT_DEV(WaterOffset) - -#if !FINAL_VERSION - READ_FLOAT_DEV(FyrosWaterOffset) - READ_FLOAT_DEV(MatisWaterOffset) - READ_FLOAT_DEV(TrykerWaterOffset) - READ_FLOAT_DEV(ZoraiWaterOffset) -#endif // FINAL_VERSION - - // Water Offset for creature - READ_FLOAT_DEV(WaterOffsetCreature) - // TimeToRemoveCol - READ_INT_DEV(TimeToRemoveCol) - // MoveToTimeToStopStall - READ_INT_DEV(MoveToTimeToStopStall) - // TimeToAdjustCamera - READ_DOUBLE_DEV(TimeToAdjustCamera) - // ChangeDirAngle - READ_DOUBLE_DEV(ChangeDirAngle) - // GuildSymbolSize - READ_FLOAT_DEV(GuildSymbolSize) - // SelectionDist - READ_FLOAT_DEV(SelectionDist) - // SelectionOutBBoxWeight - READ_FLOAT_DEV(SelectionOutBBoxWeight) - // LootDist - READ_FLOAT_DEV(LootDist) - // SpaceSelectionDist - READ_FLOAT_DEV(SpaceSelectionDist) - // SpaceSelectionMaxCycle - READ_INT_DEV(SpaceSelectionMaxCycle) - // Third Person View Min Pitch. - READ_FLOAT_DEV(TPVMinPitch) - // Third Person View Max Pitch. - READ_FLOAT_DEV(TPVMaxPitch) - // The character look at the target before this distance. - READ_FLOAT_DEV(MaxHeadTargetDist) - // FX played when dead - READ_STRING_DEV(DeadFXName) - // FX played for each impact - READ_STRING_DEV(ImpactFXName) - // FX Played at skill up - READ_STRING_DEV(SkillUpFXName) - // MinDistFactor - READ_DOUBLE_DEV(MinDistFactor) - // NameScale - READ_FLOAT_DEV(NameScale) - // NamePos - READ_FLOAT_DEV(NamePos) - // NameFontSize - READ_INT_DEV(NameFontSize) - // MaxNameDist - READ_FLOAT_DEV(MaxNameDist) - // ConstNameSizeDist - READ_FLOAT_DEV(ConstNameSizeDist) - // StaticNameHeight - READ_BOOL_FV(StaticNameHeight) - // BarsHeight - READ_FLOAT_DEV(BarsHeight) - // BarsWidth - READ_FLOAT_DEV(BarsWidth) - // DisplayWeapons - READ_BOOL_FV(DisplayWeapons) - // FightAreaSize - READ_DOUBLE_DEV(FightAreaSize) - // AttackDist - READ_FLOAT_DEV(AttackDist) - // BubbleZBias - READ_FLOAT_DEV(BubbleZBias); - // ForageInterfaceZBias - READ_FLOAT_DEV(ForageInterfaceZBias); - - // EnableRacialAnimation - READ_BOOL_FV(EnableRacialAnimation); - -#if !FINAL_VERSION - READ_FLOAT_DEV(FyrosScale); - READ_FLOAT_DEV(MatisScale); - READ_FLOAT_DEV(TrykerScale); - READ_FLOAT_DEV(ZoraiScale); - -#endif // FINAL_VERSION - - ////////////////// - // SOUND CONFIG // - // SoundOn - READ_BOOL_FV(SoundOn) - // Sound Driver - varPtr = ClientCfg.ConfigFile.getVarPtr ("DriverSound"); - if (varPtr) - { - if (nlstricmp(varPtr->asString(), "Auto") == 0) ClientCfg.DriverSound = CClientConfig::SoundDrvAuto; - else if (nlstricmp(varPtr->asString(), "FMod") == 0) ClientCfg.DriverSound = CClientConfig::SoundDrvFMod; - else if (nlstricmp(varPtr->asString(), "OpenAL") == 0) ClientCfg.DriverSound = CClientConfig::SoundDrvOpenAL; - else if (nlstricmp(varPtr->asString(), "DirectSound") == 0) ClientCfg.DriverSound = CClientConfig::SoundDrvDirectSound; - else if (nlstricmp(varPtr->asString(), "XAudio2") == 0) ClientCfg.DriverSound = CClientConfig::SoundDrvXAudio2; - } - else - cfgWarning ("Default value used for 'DriverSound' !!!"); - // SoundForceSoftwareBuffer - READ_BOOL_FV(SoundForceSoftwareBuffer); - // SoundOutGameMusic - READ_STRING_DEV(SoundOutGameMusic) - // SoundSFXVolume - READ_FLOAT_FV(SoundSFXVolume); - // SoundGameMusicVolume - READ_FLOAT_FV(SoundGameMusicVolume); - // SoundTPFade - READ_INT_DEV(SoundTPFade); - // EnableBackgroundMusicTimeConstraint - READ_BOOL_DEV(EnableBackgroundMusicTimeConstraint); - // SoundPackedSheetPath - READ_STRING_DEV(SoundPackedSheetPath) - // SampleBankDir - READ_STRING_DEV(SampleBankDir) - // UserEntitySoundLevel : UserEntity sound level - READ_FLOAT_FV(UserEntitySoundLevel) - // Use EAX - READ_BOOL_FV(UseEax) - // UseADPCM - READ_BOOL_DEV(UseADPCM) - // Max track - READ_INT_FV(MaxTrack) - - // MP3 Player - READ_STRING_FV(MediaPlayerDirectory); - READ_BOOL_FV(MediaPlayerAutoPlay); - - ///////////////// - // USER COLORS // - // Shout Color - CConfigFile::CVar *pcvColorShout = ClientCfg.ConfigFile.getVarPtr("ColorShout"); - if( pcvColorShout && (pcvColorShout->size() == 3) ) - { - ClientCfg.ColorShout.R = pcvColorShout->asInt(0); - ClientCfg.ColorShout.G = pcvColorShout->asInt(1); - ClientCfg.ColorShout.B = pcvColorShout->asInt(2); - ClientCfg.ColorShout.A = 255; - } - else - cfgWarning("Default value used for 'ColorShout'"); - - // Talk Color - CConfigFile::CVar *pcvColorTalk = ClientCfg.ConfigFile.getVarPtr("ColorTalk"); - if( pcvColorTalk && (pcvColorTalk->size() == 3) ) - { - ClientCfg.ColorTalk.R = pcvColorTalk->asInt(0); - ClientCfg.ColorTalk.G = pcvColorTalk->asInt(1); - ClientCfg.ColorTalk.B = pcvColorTalk->asInt(2); - ClientCfg.ColorTalk.A = 255; - } - else - cfgWarning("Default value used for 'ColorTalk'"); - - ////////// - // MISC // - - // Pre Data Path. - READ_STRINGVECTOR_FV(PreDataPath); - - // Data Path. - READ_STRINGVECTOR_FV(DataPath); - - // Data Path no recurse. - READ_STRINGVECTOR_FV(DataPathNoRecurse); - - // Streamed package path - READ_STRING_FV(StreamedPackagePath); - - // Streamed package hosts - READ_STRINGVECTOR_FV(StreamedPackageHosts); - - // List of files that trigger R2ED reload when touched - READ_STRINGVECTOR_FV(R2EDReloadFiles); - - // Update packed sheet Path - READ_STRINGVECTOR_FV(UpdatePackedSheetPath); - - // UpdatePackedSheet - READ_BOOL_DEV(UpdatePackedSheet) - - // EndScreenTimeOut - READ_FLOAT_DEV(EndScreenTimeOut) - // Backgrounds - READ_STRING_FV(Loading_BG) - READ_STRING_FV(LoadingFreeTrial_BG) - READ_STRING_FV(Launch_BG) - READ_STRING_FV(TeleportKami_BG) - READ_STRING_FV(TeleportKaravan_BG) - READ_STRING_FV(Elevator_BG) - READ_STRING_FV(ResurectKami_BG) - READ_STRING_FV(ResurectKaravan_BG) - READ_STRING_FV(End_BG) - READ_STRING_FV(IntroNevrax_BG) - READ_STRING_FV(IntroNVidia_BG) - - READ_FLOAT_DEV(TipsY) - READ_FLOAT_DEV(TeleportInfoY) - // SceneName - READ_STRING_DEV(SceneName) - // IdFile Path - READ_STRING_DEV(IdFilePath) - - // PacsPrimDir - READ_STRINGVECTOR_DEV(PacsPrimDir); - - ///////////// - // FILTERS // - createDebug (); - CConfigFile::CVar *pcvTmp = ClientCfg.ConfigFile.getVarPtr("NegFiltersDebug"); - if( pcvTmp ) - { - int iSz = pcvTmp->size(); - for(int k = 0; k < iSz; ++k) - { - DebugLog->addNegativeFilter (pcvTmp->asString(k).c_str()); - } - } - else - cfgWarning("Default value used for 'NegFiltersDebug'"); - - pcvTmp = ClientCfg.ConfigFile.getVarPtr("NegFiltersInfo"); - if( pcvTmp ) - { - int iSz = pcvTmp->size(); - for(int k = 0; k < iSz; ++k) - { - InfoLog->addNegativeFilter (pcvTmp->asString(k).c_str()); - } - } - else - cfgWarning("Default value used for 'NegFiltersInfo'"); - - pcvTmp = ClientCfg.ConfigFile.getVarPtr("NegFiltersWarning"); - if( pcvTmp ) - { - int iSz = pcvTmp->size(); - for(int k = 0; k < iSz; ++k) - { - WarningLog->addNegativeFilter (pcvTmp->asString(k).c_str()); - } - } - else - cfgWarning("Default value used for 'NegFiltersWarning'"); - - // Script Files - READ_STRINGVECTOR_FV(StartCommands); - - ///////////// - // OPTIONS // - // Colors for system infos - ClientCfg.SystemInfoParams.clear(); - CConfigFile::CVar *sic = ClientCfg.ConfigFile.getVarPtr("SystemInfoColors"); - if (!sic) - { - cfgWarning("Can't read SystemInfoColors, all colors defaulting to white"); - } - else - { - if (sic->size() & 1) - { - cfgWarning("Expecting odd size for SystemInfoColors. Last entry ignored."); - } - uint numCol = sic->size() >> 1; - for(uint k = 0; k < numCol; ++k) - { - uint r, g, b, a; - char mode[64]; - char fx[64]; - fx[0]='\0'; - if (sscanf(sic->asString((2 * k) + 1).c_str(), "%d %d %d %d %s %s", &r, &g, &b, &a, mode, fx) < 5) - { - if(DisplayCFGWarning) - nlwarning("Can't parse color for entry %s", sic->asString(2 * k).c_str()); - } - else - { - SSysInfoParam p; - - p.Color = CRGBA(r, g, b, a); - p.Mode = SSysInfoParam::Normal; - p.SysInfoFxName = string(fx); - if (stricmp(mode, "over") == 0) p.Mode = SSysInfoParam::Over; - else if (stricmp(mode, "overonly") == 0) p.Mode = SSysInfoParam::OverOnly; - else if (stricmp(mode, "center") == 0) p.Mode = SSysInfoParam::Center; - else if (stricmp(mode, "centeraround") == 0) p.Mode = SSysInfoParam::CenterAround; - else if (stricmp(mode, "around") == 0) p.Mode = SSysInfoParam::Around; - - ClientCfg.SystemInfoParams[toLower(sic->asString(2 * k))] = p; - } - } - } - -#ifndef RZ_NO_CLIENT - // printf commands in loading screens - ClientCfg.loadingTexts.clear(); - CConfigFile::CVar *pc = ClientCfg.ConfigFile.getVarPtr("loadingTexts"); - if (pc) - { - if( pc->size()%5 == 0 && pc->size() >= 5) - { - for (uint i = 0; i < pc->size(); i+=5) - { - SPrintfCommand pcom; - pcom.X = pc->asInt(i); - pcom.Y = pc->asInt(i+1); - pcom.Color = CRGBA::stringToRGBA( pc->asString(i+2).c_str() ); - pcom.FontSize = pc->asInt(i+3); - pcom.Text = pc->asString(i+4); - - ClientCfg.loadingTexts.push_back( pcom ); - } - } - else - { - cfgWarning("Missing or too many parameters in loadingTexts"); - } - } -#endif - - READ_INT_FV(LoadingStringCount) - - // DEBUG MEMORY - READ_INT_DEV(CheckMemoryEveryNFrame) - READ_BOOL_DEV(LogMemoryAllocation) - READ_INT_DEV(LogMemoryAllocationSize) - - // SelectWithRClick - READ_BOOL_FV(SelectWithRClick) - READ_BOOL_DEV(RunAtTheBeginning) - READ_FLOAT_FV(RotKeySpeedMax) - READ_FLOAT_FV(RotKeySpeedMin) - READ_FLOAT_FV(RotAccel) - READ_BOOL_DEV(PutBackItems) - READ_BOOL_DEV(ShowNameUnderCursor) - READ_BOOL_DEV(ShowNameSelected) - READ_FLOAT_DEV(ShowNameBelowDistanceSqr) - READ_BOOL_DEV(ForceIndoorFPV) - READ_BOOL_FV(FollowOnAtk); - READ_BOOL_FV(AtkOnSelect); - READ_BOOL_DEV(TransparentUnderCursor); - // - READ_BOOL_FV(ItemGroupAllowGuild); - - - ///////////////// - // PREFERENCES // - // Read the view mode at load time only, cause prefer keep ingame player setup - if(firstTimeSetValues) - { - READ_BOOL_FV(FPV) - } - READ_FLOAT_FV(CameraDistStep) - READ_FLOAT_FV(CameraDistMin) - READ_FLOAT_FV(CameraDistMax) - READ_FLOAT_FV(DmCameraDistMax) - READ_FLOAT_FV(CameraAccel) - READ_FLOAT_FV(CameraSpeedMin) - READ_FLOAT_FV(CameraSpeedMax) - READ_FLOAT_FV(CameraResetSpeed) - // Read the camera height and distance at load time only, cause prefer keep ingame player setup - if(firstTimeSetValues) - { - READ_FLOAT_FV(CameraHeight) - READ_FLOAT_FV(CameraDistance) - } - - // Default values for CGroupMap - READ_FLOAT_FV(MaxMapScale); - READ_FLOAT_FV(R2EDMaxMapScale); - - // /tar to update compass or not - READ_BOOL_FV(TargetChangeCompass); - - ///////////// - // SHADOWS // - // Shadows : Get Shadows state - READ_BOOL_FV(Shadows) - // ShadowsClipFar : Get Shadows Clip Far. - READ_FLOAT_DEV(ShadowsClipFar) - // ShadowsLodDist : Get Shadows Lod Distance. - READ_FLOAT_DEV(ShadowsLodDist) - // ZClamp - READ_FLOAT_DEV(ShadowZDirClampLandscape); - READ_FLOAT_DEV(ShadowZDirClampInterior); - READ_FLOAT_DEV(ShadowZDirClampSmoothSpeed); - // MaxDepth - READ_FLOAT_DEV(ShadowMaxDepthLandscape); - READ_FLOAT_DEV(ShadowMaxDepthInterior); - READ_FLOAT_DEV(ShadowMaxDepthSmoothSpeed); - - - //////////////// - // GROUND FXS // - //////////////// - READ_FLOAT_DEV(GroundFXMaxDist) - READ_INT_DEV(GroundFXMaxNB) - READ_INT_DEV(GroundFXCacheSize) - - // Names : Get Names state - READ_BOOL_FV(Names) - // Sleep - READ_INT_FV(Sleep) - // ProcessPriority - READ_INT_FV(ProcessPriority) - // CPUMask - READ_INT_FV(CPUMask) - // ShowPath : Get the ShowPath value. - READ_BOOL_DEV(ShowPath) - // UserSheet : Get the sheet to used for the use rin Local mode. - READ_STRING_DEV(UserSheet) -#if !FINAL_VERSION - // Sex - varPtr = ClientCfg.ConfigFile.getVarPtr("Sex"); - if(varPtr) - ClientCfg.Sex = (GSGENDER::EGender)varPtr->asInt(); - else - cfgWarning("Default value used for 'Sex' !!!"); -#endif // FINAL_VERSION - // PrimitiveHeightAddition - READ_BOOL_DEV(PrimitiveHeightAddition) - // DrawBoxes - READ_BOOL_DEV(DrawBoxes) - - - // ChaseReactionTime - READ_FLOAT_DEV(ChaseReactionTime) - // RyzomTime - READ_FLOAT_DEV(RyzomTime) - // RyzomDay - READ_INT_DEV(RyzomDay) - // ManualWeatherSetup - READ_BOOL_DEV(ManualWeatherSetup) - // LanguageCode - READ_BOOL_DEV(ForceLanguage) - if (!ClientCfg.ForceLanguage) - { - READ_STRING_FV(LanguageCode) - } - // DebugStringManager - READ_BOOL_DEV(DebugStringManager) - - // LastLogin - READ_STRING_FV(LastLogin) - - ////////////// - // VERBOSES // - READ_BOOL_DEV(VerboseVP) - READ_BOOL_DEV(VerboseAnimUser) - READ_BOOL_DEV(VerboseAnimSelection) - READ_BOOL_DEV(VerboseAllTraffic) - - READ_STRING_DEV(LigoPrimitiveClass); - - /////////// - // DEBUG // - READ_INT_DEV(SimulatePacketLossRatio) - READ_BOOL_DEV(PreCacheShapes) - READ_BOOL_FV(ResetShapeBankOnRetCharSelect) - READ_BOOL_DEV(DisplayMissingAnimFile) - READ_STRING_DEV(DefaultEntity) - READ_BOOL_DEV(RestrainPI) - READ_BOOL_DEV(DumpVSIndex) - READ_INT_DEV(HelpFontSize) -#if !FINAL_VERSION - // HelpFontColor - { - CConfigFile::CVar *cvHelpFontColor = ClientCfg.ConfigFile.getVarPtr("HelpFontColor"); - if(cvHelpFontColor && cvHelpFontColor->size() == 3) - { - ClientCfg.HelpFontColor.R = cvHelpFontColor->asInt(0); - ClientCfg.HelpFontColor.G = cvHelpFontColor->asInt(1); - ClientCfg.HelpFontColor.B = cvHelpFontColor->asInt(2); - ClientCfg.HelpFontColor.A = 255; - } - else - cfgWarning("Default value used for 'HelpFontColor' !!!"); - } -#endif // !FINAL_VERSION - // HelpLineStep - READ_FLOAT_DEV(HelpLineStep) - - READ_INT_DEV(DebugFontSize) -#if !FINAL_VERSION - // DebugFontColor - CConfigFile::CVar *pcvDebugFontColor = ClientCfg.ConfigFile.getVarPtr("DebugFontColor"); - if( pcvDebugFontColor && (pcvDebugFontColor->size() == 3) ) - { - ClientCfg.DebugFontColor.R = pcvDebugFontColor->asInt(0); - ClientCfg.DebugFontColor.G = pcvDebugFontColor->asInt(1); - ClientCfg.DebugFontColor.B = pcvDebugFontColor->asInt(2); - ClientCfg.DebugFontColor.A = 255; - } - else - cfgWarning("Default value used for 'DebugFontColor'"); -#endif // !FINAL_VERSION - READ_FLOAT_DEV(DebugLineStep) - - // HeadOffset - READ_CVECTOR_DEV(HeadOffset) - READ_BOOL_DEV(FPExceptions) - READ_BOOL_DEV(NeedComputeVS) - READ_BOOL_DEV(Check) - READ_BOOL_DEV(UsePACSForAll) - READ_FLOAT_DEV(WaterEnvMapUpdateTime) - READ_BOOL_DEV(BlendForward) - - ClientCfg.ZCPacsPrim = "gen_bt_col_ext.pacs_prim"; - READ_STRING_DEV(ZCPacsPrim) - - READ_BOOL_FV(AutoReloadFiles) - READ_BOOL_DEV(BlendShapePatched) - - READ_INT_DEV(MaxNumberOfTimedFXInstances); - - READ_STRING_DEV(SelectionFX); - READ_STRING_DEV(MouseOverFX); - READ_FLOAT_DEV(SelectionFXSize); - - if(ClientCfg.ConfigFile.exists("ExtendedCommands") && ClientCfg.ConfigFile.getVar("ExtendedCommands").asString() == "Enable") - ClientCfg.ExtendedCommands = true; - - - READ_BOOL_DEV(R2Mode); - if (ClientCfg.Local) // R2EDEnabled is now set by the server - { - READ_BOOL_DEV(R2EDEnabled) - } - READ_INT_FV(R2EDDssNetwork) - - - if (ClientCfg.Local) - { - ClientCfg.R2EDDssNetwork = 1; - } - - READ_BOOL_DEV(R2EDExtendedDebug) - #if FINAL_VERSION - { - CConfigFile::CVar *var = ClientCfg.ConfigFile.getVarPtr("R2EDExtendedDebug"); - if (var) - { - var->setAsInt(0); - } - // else no-op -> will resolve to 'nil' into lua - } - #endif - - - READ_BOOL_DEV(R2EDVerboseParseTime) - READ_BOOL_DEV(R2EDDontReparseUnchangedUIFiles) - READ_BOOL_DEV(R2EDLightPalette) - READ_INT_FV(R2EDAutoSaveWait) - READ_INT_FV(R2EDAutoSaveSlot) - READ_BOOL_DEV(R2EDMustVerifyRingAccessWhileLoadingAnimation) - READ_BOOL_FV(R2EDUseVerboseRingAccess) - - - - ////////// - // TEMP // - // Array with the name of all offensive impact FXs. - READ_STRINGVECTOR_DEV(OffImpactFX); - -#ifndef RZ_NO_CLIENT - - ////////// - // INIT // - // FPU -#ifdef NL_OS_WINDOWS - if(ClientCfg.FPExceptions) - _control87(_EM_DENORMAL/*|_EM_INVALID|_EM_ZERODIVIDE|_EM_OVERFLOW*/|_EM_UNDERFLOW|_EM_INEXACT, _MCW_EM); - else - _control87(_EM_INVALID|_EM_DENORMAL|_EM_ZERODIVIDE|_EM_OVERFLOW|_EM_UNDERFLOW|_EM_INEXACT, _MCW_EM); - - // Set the process priority - static DWORD priority[6]= - { - 0x40, // IDLE_PRIORITY_CLASS - 0x4000, // BELOW_NORMAL_PRIORITY_CLASS - 0x20, // NORMAL_PRIORITY_CLASS - 0x8000, // ABOVE_NORMAL_PRIORITY_CLASS - 0x80, // HIGH_PRIORITY_CLASS - 0x100, // REALTIME_PRIORITY_CLASS - }; - - int index = ClientCfg.ProcessPriority+2; - clamp(index, 0, 6); - SetPriorityClass (GetCurrentProcess(), priority[index]); -#endif // NL_OS_WINDOWS - - // Init Verbose Modes (at the beginning to be able to display them as soon as possible). - ::VerboseVP = ClientCfg.VerboseVP; - ::VerboseAnimUser = ClientCfg.VerboseAnimUser; - ::VerboseAnimSelection = ClientCfg.VerboseAnimSelection; -#ifdef LOG_ALL_TRAFFIC - NLMISC::VerboseAllTraffic = ClientCfg.VerboseAllTraffic; -#endif - - // (re-)Initialize contextual cursors. - if (!ClientCfg.R2EDEnabled) - { - initContextualCursor(); - } - - // Prim files - READ_STRINGVECTOR_DEV(PrimFiles); - - // Reset GlobalWind Setup - if(Scene) - { - Scene->setGlobalWindPower(ClientCfg.GlobalWindPower); - Scene->setGlobalWindDirection(ClientCfg.GlobalWindDirection); - } - - if (Driver) - { - // Set the monitor color properties - CMonitorColorProperties monitorColor; - for(uint i=0; i<3; i++) - { - monitorColor.Contrast[i] = ClientCfg.Contrast; - monitorColor.Luminosity[i] = ClientCfg.Luminosity; - monitorColor.Gamma[i] = ClientCfg.Gamma; - } - if(!Driver->setMonitorColorProperties(monitorColor)) - cfgWarning("reloadCFG: setMonitorColorProperties fails"); - } - - - // Show/hide all or parts of the user body. - if (UserEntity) - { - UserEntity->eyesHeight(ClientCfg.EyesHeight); - UserEntity->updateVisualDisplay(); - - // Run speed and camera dist max are set according to R2 char mode - UserEntity->flushR2CharMode(); - } - - // Initialize the camera distance (after camera dist max) - View.setCameraDistanceMaxForPlayer(); - - // draw in client light? - if(ClientCfg.Light) - { - ClientCfg.DrawBoxes = true; - ClientCfg.Names = true; - } - - // Set Day / Time - if (ClientCfg.Local) - { - uint32 tickOffset = (uint32)(ClientCfg.RyzomDay * RYZOM_HOURS_IN_TICKS * 24 + ClientCfg.RyzomTime * RYZOM_HOURS_IN_TICKS); - RT.resetTickOffset(); - RT.increaseTickOffset( tickOffset ); - } -#endif - - // for reset effect of variable in mainLoop(), set true - ClientCfg.IsInvalidated= true; - - // Allow warning display only first time. - DisplayCFGWarning= false; - - // If it is the load time, backup the ClientCfg into LastClientCfg - if(firstTimeSetValues) - LastClientCfg = ClientCfg; - - // no more true. - firstTimeSetValues= false; - - READ_INT_DEV(NumFrameForProfile); - READ_STRING_FV(KlientChatPort); - READ_BOOL_DEV(SimulateServerTick); - - READ_BOOL_DEV(DamageShieldEnabled) - - READ_BOOL_FV(AllowDebugLua) - READ_BOOL_FV(DisplayLuaDebugInfo) - - READ_BOOL_DEV(LuaDebugInfoGotoButtonEnabled) - READ_STRING_DEV(LuaDebugInfoGotoButtonTemplate) - READ_STRING_DEV(LuaDebugInfoGotoButtonCaption) - READ_STRING_DEV(LuaDebugInfoGotoButtonFunction) - - - READ_BOOL_DEV(BeepWhenLaunched) - - READ_STRING_DEV(R2ClientGw) - - READ_FLOAT_FV(FogDistAndDepthLookupBias) - - READ_INT_DEV(R2EDLoadDynamicFeatures) - - READ_BOOL_DEV(CheckR2ScenarioMD5); - - CConfigFile::CVar *pcvHardwareCursors = ClientCfg.ConfigFile.getVarPtr("HardwareCursors"); - if(pcvHardwareCursors) - { - ClientCfg.HardwareCursors.clear (); - int iSz = pcvHardwareCursors->size(); - for (int i = 0; i < iSz; i++) - ClientCfg.HardwareCursors.insert(toLower(pcvHardwareCursors->asString(i))); - } - else - { - cfgWarning("Default value used for 'HardwareCursors'"); - // default list of harware cursors - ClientCfg.HardwareCursors.insert("curs_can_pan.tga"); - ClientCfg.HardwareCursors.insert("curs_can_pan_dup.tga"); - ClientCfg.HardwareCursors.insert("curs_create.tga"); - ClientCfg.HardwareCursors.insert("curs_create_multi.tga"); - ClientCfg.HardwareCursors.insert("curs_create_vertex_invalid.tga"); - ClientCfg.HardwareCursors.insert("curs_default.tga"); - ClientCfg.HardwareCursors.insert("curs_dup.tga"); - ClientCfg.HardwareCursors.insert("curs_L.tga"); - ClientCfg.HardwareCursors.insert("curs_M.tga"); - ClientCfg.HardwareCursors.insert("curs_pan.tga"); - ClientCfg.HardwareCursors.insert("curs_pan_dup.tga"); - ClientCfg.HardwareCursors.insert("curs_pick.tga"); - ClientCfg.HardwareCursors.insert("curs_pick_dup.tga"); - ClientCfg.HardwareCursors.insert("curs_R.tga"); - ClientCfg.HardwareCursors.insert("curs_resize_BL_TR.tga"); - ClientCfg.HardwareCursors.insert("curs_resize_BR_TL.tga"); - ClientCfg.HardwareCursors.insert("curs_resize_LR.tga"); - ClientCfg.HardwareCursors.insert("curs_resize_TB.tga"); - ClientCfg.HardwareCursors.insert("curs_rotate.tga"); - ClientCfg.HardwareCursors.insert("curs_scale.tga"); - ClientCfg.HardwareCursors.insert("curs_stop.tga"); - ClientCfg.HardwareCursors.insert("text_cursor.tga"); - ClientCfg.HardwareCursors.insert("r2_hand_can_pan.tga"); - ClientCfg.HardwareCursors.insert("r2_hand_pan.tga"); - ClientCfg.HardwareCursors.insert("r2ed_tool_can_pick.tga"); - ClientCfg.HardwareCursors.insert("r2ed_tool_can_rotate.tga"); - ClientCfg.HardwareCursors.insert("r2ed_tool_pick.tga"); - ClientCfg.HardwareCursors.insert("r2ed_tool_rotate.tga"); - ClientCfg.HardwareCursors.insert("r2ed_tool_rotating.tga"); - } - - // languages and types of Ring Scenarii - READ_STRINGVECTOR_FV(ScenarioLanguages); - READ_STRINGVECTOR_FV(ScenarioTypes); - - // build name - READ_STRING_FV(BuildName) - - READ_BOOL_DEV(DisplayTPReason) - - //READ_INT_FV(TPQuitButtonX) - //READ_INT_FV(TPQuitButtonY) - //READ_INT_FV(TPCancelButtonX) - //READ_INT_FV(TPCancelButtonY) - READ_INT_FV(TPButtonW) - READ_INT_FV(TPButtonH) - - READ_STRING_FV(ScenarioSavePath) - - - ClientCfg.R2EDClippedEntityBlendTime = 0.18f; - READ_FLOAT_FV(R2EDClippedEntityBlendTime) - - // vl: BackgroundDownloader is hardcoded to false and we don't want to run it, even if the cfg wants it - //READ_BOOL_FV(BackgroundDownloader) - -}// load // - - -//----------------------------------------------- -// serial : -// Serialize CFG. -//----------------------------------------------- -void CClientConfig::serial(NLMISC::IStream &f) -{ - // Start the opening of a new node named ClientCFG. - f.xmlPush("ClientCFG"); - - f.xmlPushBegin("Light"); - f.xmlPushEnd(); - f.serial(Light); - f.xmlPop(); - - f.xmlPushBegin("Windowed"); - f.xmlPushEnd(); - f.serial(Windowed); - f.xmlPop(); - - f.xmlPushBegin("Width"); - f.xmlPushEnd(); - f.serial(Width); - f.xmlPop(); - - f.xmlPushBegin("Height"); - f.xmlPushEnd(); - f.serial(Height); - f.xmlPop(); - - f.xmlPushBegin("Depth"); - f.xmlPushEnd(); - f.serial(Depth); - f.xmlPop(); - - f.xmlPushBegin("Contrast"); - f.xmlPushEnd(); - f.serial(Contrast); - f.xmlPop(); - - f.xmlPushBegin("Luminosity"); - f.xmlPushEnd(); - f.serial(Luminosity); - f.xmlPop(); - - f.xmlPushBegin("Gamma"); - f.xmlPushEnd(); - f.serial(Gamma); - f.xmlPop(); - - - f.xmlPushBegin("AttackDist"); - f.xmlPushEnd(); - f.serial(AttackDist); - f.xmlPop(); - - // SelectWithRClick - f.xmlPushBegin("SelectWithRClick"); - f.xmlPushEnd(); - f.serial(SelectWithRClick); - f.xmlPop(); - - // Close the serial for the Client CFG. - f.xmlPop(); -}// serial // - - -//----------------------------------------------- -// init : -//----------------------------------------------- -void CClientConfig::init(const string &configFileName) -{ - // if the users client config does not exist - if(!CFile::fileExists(configFileName)) - { - // create the basic .cfg - FILE *fp = nlfopen(configFileName, "w"); - - if (fp == NULL) - nlerror("CFG::init: Can't create config file '%s'", configFileName.c_str()); - else - nlwarning("CFG::init: creating '%s' with default values", configFileName.c_str ()); - - // get current locale - std::string lang = CI18N::getSystemLanguageCode(); - - const std::vector &languages = CI18N::getLanguageCodes(); - - // search if current locale is defined in language codes - for(uint i = 0; i < languages.size(); ++i) - { - if (lang == languages[i]) - { - // store the language code in the config file - fprintf(fp, "LanguageCode = \"%s\";\n", lang.c_str()); - break; - } - } - - fclose(fp); - } - - // read the exising config file (don't parse it yet!) - ucstring content; - NLMISC::CI18N::readTextFile(configFileName, content); - std::string contentUtf8 = content.toUtf8(); - - // while there are "RootConfigFilename" values, remove them - size_t pos = 0; - while((pos = contentUtf8.find("RootConfigFilename")) != configFileName.npos) - { - size_t endOfLine = contentUtf8.find("\n", pos); - contentUtf8.erase(pos, (endOfLine - pos) + 1); - } - - // get current location of the root config file (client_default.cfg) - std::string defaultConfigLocation; - if(!getDefaultConfigLocation(defaultConfigLocation)) - nlerror("cannot find client_default.cfg"); - - // and store it in the RootConfigFilename value in the very first line - contentUtf8.insert(0, std::string("RootConfigFilename = \"") + - defaultConfigLocation + "\";\n"); - - // save the updated config file - NLMISC::COFile configFile(configFileName, false, true, false); - configFile.serialBuffer((uint8*)contentUtf8.c_str(), (uint)contentUtf8.size()); - configFile.close(); - - // now we can continue loading and parsing the config file - - // if the config file will be modified, it calls automatically the function setValuesOnFileChange() - ClientCfg.ConfigFile.setCallback (CClientConfig::setValuesOnFileChange); - - // load the config files - ClientCfg.ConfigFile.load (configFileName); - - CConfigFile::CVar *pCV; - // check language code is supported - pCV = ClientCfg.ConfigFile.getVarPtr("LanguageCode"); - if (pCV) - { - std::string lang = pCV->asString(); - if (!CI18N::isLanguageCodeSupported(lang)) - { - nlinfo("Unsupported language code \"%s\" fallback on default", lang.c_str()); - // fallback to default language - ClientCfg.LanguageCode = CI18N::getSystemLanguageCode(); - // update ConfigFile variable - pCV->setAsString(ClientCfg.LanguageCode); - ClientCfg.ConfigFile.save(); - } - } - - // update the ConfigFile variable in the config file - pCV = ClientCfg.ConfigFile.getVarPtr("ClientVersion"); - if (pCV) - { - std::string str = pCV->asString (); - if (str != getVersion() && ClientCfg.SaveConfig) - { - nlinfo ("Update and save the ClientVersion variable in config file %s -> %s", str.c_str(), getVersion().c_str()); - pCV->setAsString(getVersion()); - ClientCfg.ConfigFile.save(); - } - } - else - nlwarning ("There's no ClientVersion variable in the config file!"); - -}// init // - - -//----------------------------------------------- -// init : -//----------------------------------------------- -void CClientConfig::release () -{ -#ifndef RZ_NO_CLIENT - // Do we have to save the cfg file ? - if (ClientCfg.SaveConfig) - { - // Save values - try - { - CConfigFile::CVar *varPtr = NULL; - - // Driver still alive ? - if (Driver && Driver->isActive ()) - { - sint32 x, y; - uint32 width, height; - - Driver->getWindowPos(x, y); - Driver->getWindowSize(width, height); - - // Are we in window mode ? - if (ClientCfg.Windowed /* && !isWindowMaximized() */) - { - // Save windows position. width/height are saved when leaving ingame. - writeInt("PositionX", x); - writeInt("PositionY", y); - } - } - - // Save if in FPV or TPV. - writeBool("FPV", ClientCfg.FPV); - - // Save the camera distance - writeDouble("CameraDistance", ClientCfg.CameraDistance); - } - catch (const Exception &e) - { - nlwarning ("Error while set config file variables : %s", e.what ()); - } - - // Save it - ClientCfg.ConfigFile.save (); - } -#endif -} - -bool CClientConfig::readBool (const std::string &varName) -{ - bool bVal = false; - CConfigFile::CVar *varPtr = ConfigFile.getVarPtr(varName); - if(varPtr) - bVal = varPtr->asInt() ? true : false; - else - nlwarning("CFG: Default value used for '%s' !!!",varName.c_str()); - return bVal; -} - -void CClientConfig::writeBool (const std::string &varName, bool bVal, bool bForce) -{ - CConfigFile::CVar *varPtr = bForce ? ConfigFile.insertVar(varName, CConfigFile::CVar()):ConfigFile.getVarPtr(varName); - if(varPtr) - varPtr->forceAsInt(bVal ? 1:0); - else - nlwarning("CFG: Default value used for '%s' !!!",varName.c_str()); -} - -sint32 CClientConfig::readInt (const std::string &varName) -{ - sint32 bVal = 0; - CConfigFile::CVar *varPtr = ConfigFile.getVarPtr(varName); - if(varPtr) - bVal = varPtr->asInt(); - else - nlwarning("CFG: Default value used for '%s' !!!",varName.c_str()); - return bVal; -} - -void CClientConfig::writeInt (const std::string &varName, sint32 bVal, bool bForce) -{ - CConfigFile::CVar *varPtr = bForce ? ConfigFile.insertVar(varName, CConfigFile::CVar()):ConfigFile.getVarPtr(varName); - if(varPtr) - varPtr->forceAsInt(bVal); - else - nlwarning("CFG: Default value used for '%s' !!!",varName.c_str()); -} - -double CClientConfig::readDouble (const std::string &varName) -{ - double bVal = 0; - CConfigFile::CVar *varPtr = ConfigFile.getVarPtr(varName); - if(varPtr) - bVal = varPtr->asDouble(); - else - nlwarning("CFG: Default value used for '%s' !!!",varName.c_str()); - return bVal; -} - -void CClientConfig::writeDouble (const std::string &varName, double dVal, bool bForce) -{ - CConfigFile::CVar *varPtr = bForce ? ConfigFile.insertVar(varName, CConfigFile::CVar()):ConfigFile.getVarPtr(varName); - if(varPtr) - varPtr->forceAsDouble(dVal); - else - nlwarning("CFG: Default value used for '%s' !!!",varName.c_str()); -} - -string CClientConfig::readString (const std::string &varName) -{ - string sVal; - CConfigFile::CVar *varPtr = ConfigFile.getVarPtr(varName); - if(varPtr) - sVal = varPtr->asString(); - else - nlwarning("CFG: Default value used for '%s' !!!",varName.c_str()); - return sVal; -} - -void CClientConfig::writeString (const std::string &varName, const std::string &strVal, bool bForce) -{ - CConfigFile::CVar *varPtr = bForce ? ConfigFile.insertVar(varName, CConfigFile::CVar()):ConfigFile.getVarPtr(varName); - if(varPtr) - varPtr->forceAsString(strVal); - else - nlwarning("CFG: Default value used for '%s' !!!",varName.c_str()); -} - -// *************************************************************************** -bool CClientConfig::readBoolNoWarning(const std::string &varName) -{ - bool bVal = false; - CConfigFile::CVar *varPtr = ConfigFile.getVarPtr(varName); - if(varPtr) - bVal = varPtr->asInt() ? true : false; - return bVal; -} - -sint32 CClientConfig::readIntNoWarning(const std::string &varName) -{ - sint32 bVal = 0; - CConfigFile::CVar *varPtr = ConfigFile.getVarPtr(varName); - if(varPtr) - bVal = varPtr->asInt(); - return bVal; -} - -double CClientConfig::readDoubleNoWarning(const std::string &varName) -{ - double bVal = 0; - CConfigFile::CVar *varPtr = ConfigFile.getVarPtr(varName); - if(varPtr) - bVal = varPtr->asDouble(); - return bVal; -} - -// *************************************************************************** -float CClientConfig::getActualLandscapeThreshold() const -{ - // The threshold to set in landscape is the inverse of the CFG one - return 1.0f/LandscapeThreshold; -} - -// *************************************************************************** -string CClientConfig::getHtmlLanguageCode() const -{ - if(LanguageCode=="wk") - return "en"; - else - return LanguageCode; -} - -// *************************************************************************** -ucstring CClientConfig::buildLoadingString( const ucstring& ucstr ) const -{ - if( LoadingStringCount > 0 ) - { - uint index = rand()%LoadingStringCount; - string tipId = "uiLoadingString"+toString(index); - ucstring randomUCStr = CI18N::get(tipId); - return randomUCStr; - } - else - return ucstr; -} - -// *************************************************************************** -bool CClientConfig::getDefaultConfigLocation(std::string& p_name) const -{ - std::string defaultConfigFileName = "client_default.cfg"; - std::string defaultConfigPath; - - p_name.clear(); - -#ifdef NL_OS_MAC - // on mac, client_default.cfg should be searched in .app/Contents/Resources/ - defaultConfigPath = getAppBundlePath() + "/Contents/Resources/"; -#else - // unders Windows or Linux, search client_default.cfg is same directory as executable - defaultConfigPath = Args.getProgramPath(); -#endif - - std::string currentPath = CPath::standardizePath(CPath::getCurrentPath()); - std::string etcPath = CPath::standardizePath(getRyzomEtcPrefix()); - - // look in the current working directory first - if (CFile::isExists(currentPath + defaultConfigFileName)) - p_name = currentPath + defaultConfigFileName; - - // look in startup directory - else if (CFile::isExists(Args.getStartupPath() + defaultConfigFileName)) - p_name = Args.getStartupPath() + defaultConfigFileName; - - // look in application directory - else if (CFile::isExists(defaultConfigPath + defaultConfigFileName)) - p_name = defaultConfigPath + defaultConfigFileName; - - // look in etc prefix path - else if (!etcPath.empty() && CFile::isExists(etcPath + defaultConfigFileName)) - p_name = etcPath + defaultConfigFileName; - - // if some client_default.cfg was found return true - return !p_name.empty(); -} diff --git a/code/ryzom/client/src/connection.cpp b/code/ryzom/client/src/connection.cpp deleted file mode 100644 index f57238991..000000000 --- a/code/ryzom/client/src/connection.cpp +++ /dev/null @@ -1,3693 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010-2019 Winch Gate Property Limited -// -// This source file has been modified by the following contributors: -// Copyright (C) 2012 Matt RAYKOWSKI (sfb) -// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014-2019 Jan BOON (Kaetemi) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - - -////////////// -// Includes // -////////////// -#include "stdpch.h" - -// Misc. -#include "nel/misc/i18n.h" -#include "nel/misc/path.h" -#include "nel/misc/time_nl.h" -#include "nel/misc/algo.h" -#include "nel/misc/system_utils.h" -#include "nel/misc/stream.h" -// 3D Interface. -#include "nel/3d/u_driver.h" -#include "nel/3d/u_text_context.h" -#include "nel/3d/stereo_display.h" -// Game Share -//#include "game_share/gd_time.h" // \todo GUIGUI : TO DELETE/CHANGE -#include "game_share/gender.h" -#include "game_share/character_summary.h" -#include "game_share/roles.h" -#include "game_share/character_title.h" -#include "game_share/shard_names.h" -#include "game_share/utils.h" -#include "game_share/bg_downloader_msg.h" - -// Std. -#include -// Client -#include "connection.h" -#include "nel/gui/action_handler.h" -#include "sound_manager.h" -#include "input.h" -#include "login.h" -#include "login_progress_post_thread.h" - -#include "client_cfg.h" -#include "actions_client.h" -#include "user_entity.h" -#include "time_client.h" -#include "net_manager.h" -#include "string_manager_client.h" -#include "far_tp.h" -#include "movie_shooter.h" - -// Interface part -#include "interface_v3/interface_manager.h" -#include "interface_v3/character_3d.h" -#include "nel/gui/ctrl_button.h" -#include "interface_v3/input_handler_manager.h" -#include "nel/gui/group_editbox.h" -#include "nel/gui/interface_expr.h" -#include "init_main_loop.h" -#include "continent_manager.h" -#include "interface_v3/group_quick_help.h" -#include "nel/gui/dbgroup_combo_box.h" - -#include "r2/dmc/client_edition_module.h" -#include "r2/editor.h" -#include "game_share/scenario.h" -#include "session_browser_impl.h" - -#include "bg_downloader_access.h" -#include "main_loop.h" - -#include "misc.h" - - -//////////////// -// Namespaces // -//////////////// -using namespace NLMISC; -using namespace NL3D; -using namespace NLNET; -using namespace std; -using namespace RSMGR; -using namespace R2; - - - -///////////// -// Externs // -///////////// -extern uint32 Version; // Client Version. -extern UDriver *Driver; -extern UTextContext *TextContext; -extern bool game_exit; - -extern CSoundManager *SoundMngr; - -extern bool serverReceivedReady; -extern CContinentManager ContinentMngr; - -extern bool MovieShooterSaving; -extern void endMovieShooting(); -extern void replayMovieShooting(); -extern void saveMovieShooting(); -extern void displaySpecialTextProgress(const char *text); -extern bool InitMouseWithCursor(bool hardware); - -extern bool SetMousePosFirstTime; - -///////////// -// Globals // initialization occurs in the function : connection -///////////// -bool userChar; -bool noUserChar; -bool ConnectInterf; -bool CreateInterf; -bool CharacterInterf; -TTime UniversalTime; -std::vector CharacterSummaries; -std::string UsedFSAddr; -std::string UserPrivileges; -uint8 ServerPeopleActive = 255; -uint8 ServerCareerActive = 255; - -bool WaitServerAnswer; -bool CharNameValidArrived; -bool CharNameValid; -string CharNameValidDBLink; -uint8 PlayerSelectedSlot = 0; -string PlayerSelectedFileName; -TSessionId PlayerSelectedMainland= (TSessionId)0; // This is the mainland selected at the SELECT perso!! -ucstring PlayerSelectedHomeShardName; -ucstring PlayerSelectedHomeShardNameWithParenthesis; -extern std::string CurrentCookie; - - -ucstring NewKeysCharNameWanted; // name of the character for which a new keyset must be created -ucstring NewKeysCharNameValidated; -std::string GameKeySet = "keys.xml"; -std::string RingEditorKeySet = "keys_r2ed.xml"; - -string ScenarioFileName; -sint LoginCharsel = -1; - -std::string ImportCharacter; - -static const char *KeySetVarName = "BuiltInKeySets"; - -#define GROUP_LIST_CHARACTER "ui:outgame:charsel_import:import_list" -#define GROUP_LIST_MAINLAND "ui:outgame:appear_mainland:mainland_list" -#define GROUP_LIST_KEYSET "ui:outgame:appear_keyset:keyset_list" -vector Mainlands; -TSessionId MainlandSelected = (TSessionId)0; // This is the mainland selected at the CREATE perso!! - -// This is the home session (mainland) of the selected character -TSessionId CharacterHomeSessionId = (TSessionId)0; - - -bool PatchBegun = false; - -// \todo GUIGUI : USE TRANSPORT CLASS. -// SVersionAnswer versionAnswer; - - -// Finite State Machine : all the states before entering the game -// ------------------------------------------------------------------------------------------------ -TInterfaceState globalMenu(); - - -bool hasPrivilegeDEV() { return (UserPrivileges.find(":DEV:") != std::string::npos); } -bool hasPrivilegeSGM() { return (UserPrivileges.find(":SGM:") != std::string::npos); } -bool hasPrivilegeGM() { return (UserPrivileges.find(":GM:") != std::string::npos); } -bool hasPrivilegeVG() { return (UserPrivileges.find(":VG:") != std::string::npos); } -bool hasPrivilegeSG() { return (UserPrivileges.find(":SG:") != std::string::npos); } -bool hasPrivilegeG() { return (UserPrivileges.find(":G:") != std::string::npos); } -bool hasPrivilegeEM() { return (UserPrivileges.find(":EM:") != std::string::npos); } -bool hasPrivilegeEG() { return (UserPrivileges.find(":EG:") != std::string::npos); } -bool hasPrivilegeOBSERVER() { return (UserPrivileges.find(":OBSERVER:") != std::string::npos); } -bool hasPrivilegeTESTER() { return (UserPrivileges.find(":TESTER:") != std::string::npos); } - - -// Restore the video mode (fullscreen for example) after the connection (done in a window) -void connectionRestoreVideoMode () -{ - // Setup full screen if we have to - UDriver::CMode mode; - Driver->getCurrentScreenMode(mode); - - if (mode.Windowed) - { - uint32 width, height; - Driver->getWindowSize(width, height); - mode.Width = width; - mode.Height = height; - } - - // don't allow sizes smaller than 1024x768 - if (ClientCfg.Width < 1024) ClientCfg.Width = 1024; - if (ClientCfg.Height < 768) ClientCfg.Height = 768; - - if (StereoDisplay) - StereoDisplayAttached = StereoDisplay->attachToDisplay(); - - if (!StereoDisplayAttached && ( - (ClientCfg.Windowed != mode.Windowed) || - (ClientCfg.Width != mode.Width) || - (ClientCfg.Height != mode.Height))) - { - mode.Windowed = ClientCfg.Windowed; - mode.Depth = uint8(ClientCfg.Depth); - mode.Width = ClientCfg.Width; - mode.Height = ClientCfg.Height; - mode.Frequency = ClientCfg.Frequency; - setVideoMode(mode); - } - - // And setup hardware mouse if we have to - InitMouseWithCursor (ClientCfg.HardwareCursor && !StereoDisplayAttached); - SetMouseFreeLook (); - SetMouseCursor (); - SetMouseSpeed (ClientCfg.CursorSpeed); - SetMouseAcceleration (ClientCfg.CursorAcceleration); - - // Restore user UI scaling - CViewRenderer::getInstance()->setInterfaceScale(ClientCfg.InterfaceScale); -} - - -#define UI_VARIABLES_SCREEN_WEBSTART 8 - - -// *************************************************************************** -// Called to reload the start test page in test browser mode -class CAHOnReloadTestPage: public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - // need to reset password and current screen - CGroupHTML *pGH = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_BROWSER)); - - pGH->browse(ClientCfg.TestBrowserUrl.c_str()); - - } -}; -REGISTER_ACTION_HANDLER (CAHOnReloadTestPage, "on_reload_test_page"); - - -// ------------------------------------------------------------------------------------------------ -void setOutGameFullScreen() -{ - if (!ClientCfg.Local && ClientCfg.SelectCharacter == -1) - { - if (StereoDisplayAttached) - StereoDisplay->detachFromDisplay(); - StereoDisplayAttached = false; - - InitMouseWithCursor(ClientCfg.HardwareCursor && !StereoDisplayAttached); - } - - // Enable auto scaling in login window - CViewRenderer::getInstance()->setInterfaceScale(1.0f, 1024, 768); -} - - -// New version of the menu after the server connection -// -// If you add something in this function, check CFarTP, -// some kind of reinitialization might be useful over there. -// ------------------------------------------------------------------------------------------------ -bool connection (const string &cookie, const string &fsaddr) -{ - - NLMISC::TTime connStart = ryzomGetLocalTime(); - NLMISC::TTime connLast = connStart; - NLMISC::TTime connCurrent = connLast; - - game_exit = false; - - // set resolution from cfg after login - connectionRestoreVideoMode (); - - // Preload continents - { - const ucstring nmsg("Loading continents..."); - ProgressBar.newMessage (ClientCfg.buildLoadingString(nmsg) ); - ContinentMngr.preloadSheets(); - - connLast = connCurrent; - connCurrent = ryzomGetLocalTime(); - nlinfo ("PROFILE: %d seconds (%d total) for Loading continents", (uint32)(connCurrent-connLast)/1000, (uint32)(connCurrent-connStart)/1000); - } - - if (!fsaddr.empty () && !cookie.empty ()) - { - // it means that we have a nel_launcher values, so we are online - ClientCfg.Local = 0; - nlinfo ("Using the nel launcher parameters '%s' '%s'", cookie.c_str (), fsaddr.c_str ()); - } - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - // If the Client is in in Local Mode -> init the Time and return. - if (ClientCfg.Local) - { -#ifdef ENABLE_INCOMING_MSG_RECORDER - NetMngr.init("", ""); - // Set the impulse callback. - NetMngr.setImpulseCallback (impulseCallBack); - // Set the database. - NetMngr.setDataBase (IngameDbMngr.getNodePtr()); - // init the string manager cache. - STRING_MANAGER::CStringManagerClient::instance()->initCache("", ClientCfg.LanguageCode); // VOIR BORIS -#endif - return true; - } - - ProgressBar.setFontFactor(1.0f); - - // Init out game - setOutGameFullScreen(); - - ucstring nmsg("Initializing outgame..."); - ProgressBar.newMessage (ClientCfg.buildLoadingString(nmsg) ); - pIM->initOutGame(); - - connLast = connCurrent; - connCurrent = ryzomGetLocalTime(); - nlinfo ("PROFILE: %d seconds (%d total) for Initializing outgame", (uint32)(connCurrent-connLast)/1000, (uint32)(connCurrent-connStart)/1000); - - // Init user interface - nmsg = "Initializing user interface..."; - ProgressBar.newMessage (ClientCfg.buildLoadingString(nmsg) ); - - // Hide cursor for interface - //Driver->showCursor (false); - - // Init global variables - userChar = false; - noUserChar = false; - ConnectInterf = true; - CreateInterf = true; - CharacterInterf = true; - WaitServerAnswer= false; - - FarTP.setOutgame(); - - // Start the finite state machine - static bool firstConnection = true; - TInterfaceState InterfaceState = AUTO_LOGIN; - // TInterfaceState InterfaceState = firstConnection ? AUTO_LOGIN : GLOBAL_MENU; - /*if (!firstConnection) - { - noUserChar = userChar = false; - WaitServerAnswer = true; - }*/ - - NLGUI::CDBManager::getInstance()->getDbProp ("UI:CURRENT_SCREEN")->setValue32(ClientCfg.Local ? 6 : -1); // TMP TMP - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - // Active inputs - Actions.enable(true); - EditActions.enable(true); - - if (ClientCfg.SelectCharacter == -1) - { - // not initialized at login and remain hardware until here ... - - // Re-initialise the mouse (will be now in hardware mode, if required) - //InitMouseWithCursor (ClientCfg.HardwareCursor && !StereoDisplayAttached); // the return value of enableLowLevelMouse() has already been tested at startup - - // no ui init if character selection is automatic - //SetMouseFreeLook (); - //SetMouseCursor (); - SetMouseSpeed (ClientCfg.CursorSpeed); - SetMouseAcceleration (ClientCfg.CursorAcceleration); - - NLGUI::CDBManager::getInstance()->getDbProp("UI:SELECTED_SLOT")->setValue32(ClientCfg.SelectedSlot); - PlayerSelectedSlot = ClientCfg.SelectedSlot; - } - - connLast = connCurrent; - connCurrent = ryzomGetLocalTime(); - nlinfo ("PROFILE: %d seconds (%d total) for Initializing user interface", (uint32)(connCurrent-connLast)/1000, (uint32)(connCurrent-connStart)/1000); - - nlinfo ("PROFILE: %d seconds for connection", (uint32)(ryzomGetLocalTime ()-connStart)/1000); - - // Init web box - - // TMP TMP - if (ClientCfg.Local) - { - InterfaceState = GLOBAL_MENU; - } - - // Create the loading texture. We can't do that before because we need to add search path first. - beginLoading (LoadBackground); - UseEscapeDuringLoading = USE_ESCAPE_DURING_LOADING; - - while ((InterfaceState != GOGOGO_IN_THE_GAME) && (InterfaceState != QUIT_THE_GAME)) - { - switch (InterfaceState) - { - case AUTO_LOGIN: - InterfaceState = autoLogin (cookie, fsaddr, firstConnection); - break; - - case GLOBAL_MENU: - if (!ClientCfg.Local) - { - if (ClientCfg.SelectCharacter == -1) - { - NLGUI::CDBManager::getInstance()->getDbProp ("UI:CURRENT_SCREEN")->setValue32(0); // 0 == select - } - } - InterfaceState = globalMenu(); - break; - case GOGOGO_IN_THE_GAME: - break; - case QUIT_THE_GAME: - break; - } - } - - firstConnection = false; - - // Restore user UI scaling - CViewRenderer::getInstance()->setInterfaceScale(ClientCfg.InterfaceScale); - - // Disable inputs - Actions.enable(false); - EditActions.enable(false); - -// resetTextContext ("ingame.ttf", true); - resetTextContext ("ryzom.ttf", true); - - if (InterfaceState == GOGOGO_IN_THE_GAME) - { - // set background downloader to 'paused' to ease loading of client - pauseBGDownloader(); - return true; - } - - if (InterfaceState == QUIT_THE_GAME) - return false; - nlassert ((InterfaceState == GOGOGO_IN_THE_GAME) || (InterfaceState == QUIT_THE_GAME)); - return true; -} - - -// - -// Allow user to reselect character after the server reconnection -// ------------------------------------------------------------------------------------------------ -bool reconnection() -{ - - game_exit = false; - - setOutGameFullScreen(); - - // Preload continents - { - const ucstring nmsg ("Loading continents..."); - ProgressBar.newMessage (ClientCfg.buildLoadingString(nmsg) ); - ContinentMngr.preloadSheets(); - } -/* - if (!fsaddr.empty () && !cookie.empty ()) - { - // it means that we have a nel_launcher values, so we are online - ClientCfg.Local = 0; - nlinfo ("Using the nel launcher parameters '%s' '%s'", cookie.c_str (), fsaddr.c_str ()); - } - - // If the Client is in in Local Mode -> init the Time and return. - if (ClientCfg.Local) - { -#ifdef ENABLE_INCOMING_MSG_RECORDER - NetMngr.init("", ""); - // Set the impulse callback. - NetMngr.setImpulseCallback (impulseCallBack); - // Set the database. - NetMngr.setDataBase (IngameDbMngr.getNodePtr()); - // init the string manager cache. - STRING_MANAGER::CStringManagerClient::instance()->initCache("", ClientCfg.LanguageCode); // VOIR BORIS -#endif - connectionRestoreVideoMode (); - return true; - } -*/ - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - ProgressBar.setFontFactor(1.0f); - - // Init out game - pIM->initOutGame(); - - // Hide cursor for interface - Driver->showCursor (false); - - // Init global variables - userChar = false; - noUserChar = false; - ConnectInterf = true; - CreateInterf = true; - CharacterInterf = true; - WaitServerAnswer= false; - - FarTP.setOutgame(); - - // these two globals sequence GlobalMenu to display the character select dialog - WaitServerAnswer = true; - userChar = true; - - // Start the finite state machine - TInterfaceState InterfaceState = GLOBAL_MENU; - - NLGUI::CDBManager::getInstance()->getDbProp ("UI:CURRENT_SCREEN")->setValue32(-1); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - // Active inputs - Actions.enable(true); - EditActions.enable(true); - - if (ClientCfg.SelectCharacter == -1) - { - // Re-initialise the mouse (will be now in hardware mode, if required) - SetMousePosFirstTime = true; - InitMouseWithCursor (ClientCfg.HardwareCursor && !StereoDisplayAttached); // the return value of enableLowLevelMouse() has already been tested at startup - - // no ui init if character selection is automatic - SetMouseFreeLook (); - SetMouseCursor (); - SetMouseSpeed (ClientCfg.CursorSpeed); - SetMouseAcceleration (ClientCfg.CursorAcceleration); - NLGUI::CDBManager::getInstance()->getDbProp("UI:SELECTED_SLOT")->setValue32(ClientCfg.SelectedSlot); - PlayerSelectedSlot = ClientCfg.SelectedSlot; - } - - // we want the teleport graphics to display (not like in Server Hop mode) - // this also kicks the state machine to sendReady() so we stop spinning in farTPmainLoop - FarTP.setIngame(); - - // Create the loading texture. We can't do that before because we need to add search path first. - beginLoading (LoadBackground); - UseEscapeDuringLoading = USE_ESCAPE_DURING_LOADING; - - // character selection menu - while( InterfaceState == GLOBAL_MENU ) // != GOGOGO_IN_THE_GAME) && (InterfaceState != QUIT_THE_GAME)) - { - if (ClientCfg.SelectCharacter == -1) - { - NLGUI::CDBManager::getInstance()->getDbProp ("UI:CURRENT_SCREEN")->setValue32(0); // 0 == select - } - InterfaceState = globalMenu(); - } - - // Restore user UI scaling - CViewRenderer::getInstance()->setInterfaceScale(ClientCfg.InterfaceScale); - - // Disable inputs - Actions.enable(false); - EditActions.enable(false); - -// resetTextContext ("ingame.ttf", true); - resetTextContext ("ryzom.ttf", true); - - if (InterfaceState == GOGOGO_IN_THE_GAME) - { - pauseBGDownloader(); - return true; - } - if (InterfaceState == QUIT_THE_GAME) - return false; - nlassert ((InterfaceState == GOGOGO_IN_THE_GAME) || (InterfaceState == QUIT_THE_GAME)); - return true; -} - -// Automatic connection to the server, the user can't do anything -// ------------------------------------------------------------------------------------------------ -TInterfaceState autoLogin (const string &cookie, const string &fsaddr, bool firstConnection) -{ - noUserChar = userChar = false; - string defaultPort = string(":47851"); - if(!fsaddr.empty()) - { - // If we have a front end address from command line, use this one - UsedFSAddr = fsaddr; - if (UsedFSAddr.find(":") == string::npos) - { - UsedFSAddr += defaultPort; - } - } - else - { - // Otherwise, use the front end address from configfile - UsedFSAddr = ClientCfg.FSHost; - FSAddr = UsedFSAddr; // to be able to do /reconnect - LoginSM.pushEvent( CLoginStateMachine::ev_skip_all_login ); - if (UsedFSAddr.find(":") == string::npos) - { - UsedFSAddr += defaultPort; - FSAddr += defaultPort; // to be able to do /reconnect - } - } - - if (firstConnection) - NetMngr.init (cookie, UsedFSAddr); - - // Connection - if (!ClientCfg.Local/*ace!ClientCfg.Light*/) - { - string result; - - if (firstConnection) - { - NetMngr.connect (result); - - if (!result.empty()) - { - nlerror ("connection : %s.", result.c_str()); - return QUIT_THE_GAME; - } - - // Ok the client is connected - - // Set the impulse callback. - NetMngr.setImpulseCallback (impulseCallBack); - // Set the database. - NetMngr.setDataBase (IngameDbMngr.getNodePtr()); - - // init the string manager cache. - STRING_MANAGER::CStringManagerClient::instance()->initCache(UsedFSAddr, ClientCfg.LanguageCode); - } - } - else - { - CCharacterSummary cs; - cs.Name = "babar"; - //cs.Surname = "l'elephant"; - cs.People = EGSPD::CPeople::Zorai; - cs.VisualPropA.PropertySubData.Sex = 0; // Male -//Deprecated -// cs.Role = ROLES::range_warrior; -// cs.Job = JOBS::CasterBuffer; -// cs.JobLevel = 16; - CharacterSummaries.push_back(cs); - - cs.Name = "yeah"; - //cs.Surname = "zeelot"; - cs.People = EGSPD::CPeople::Matis; - cs.VisualPropA.PropertySubData.Sex = 1; // Female -//Deprecated -// cs.Role = ROLES::buffer_magician; -// cs.Job = JOBS::CasterHealer; -// cs.JobLevel = 8; - CharacterSummaries.push_back(cs); - - userChar = true; - } - - WaitServerAnswer = true; - - return GLOBAL_MENU; -} - -// ------------------------------------------------------------------------------------------------ -void globalMenuMovieShooter() -{ - - if(MovieShooterSaving) - { - // Add the buffer frame to the movie. - if(!MovieShooter.addFrame(TimeInSec, Driver)) - { - // Fail to add the frame => abort. - endMovieShooting(); - } - else - { - // Ok, just add a display. - displaySpecialTextProgress("MovieShooting"); - } - } - -} - -// ------------------------------------------------------------------------------------------------ -// Build a valid PlayerName for file Save selection. -std::string buildPlayerNameForSaveFile(const ucstring &playerNameIn) -{ - // remove any shard name appended - ucstring playerName = playerNameIn; - ucstring::size_type pos = playerNameIn.find('('); - if(pos!=ucstring::npos && pos>0) - { - playerName.resize(pos); - } - - // replace any special ucchar with '_' - string ret; - ret.resize(playerName.size()); - for(uint i=0;i='A' && c<='Z') || - (c>='a' && c<='z') || - (c>='0' && c<='9') || - (c=='_') ) - { - ret[i]= tolower(c); - } - else - ret[i]= '_'; - } - return ret; -} - -// ------------------------------------------------------------------------------------------------ -class CSoundGlobalMenu -{ -public: - CSoundGlobalMenu() - { - _MusicWantedAsync= false; - _NbFrameBeforeChange= NbFrameBeforeChangeMax; - } - void setMusic(const string &music, bool async); - void updateSound(); -private: - string _MusicPlayed; - string _MusicWanted; - bool _MusicWantedAsync; - sint _NbFrameBeforeChange; - enum {NbFrameBeforeChangeMax= 10}; -}; - -void CSoundGlobalMenu::updateSound() -{ - // **** update the music played - // The first music played is the music played at loading, before select char - if(_MusicPlayed.empty()) - _MusicPlayed= toLower(ClientCfg.SoundOutGameMusic); - if(_MusicWanted.empty()) - _MusicWanted= toLower(ClientCfg.SoundOutGameMusic); - - // because music is changed when the player select other race for instance, - // wait the 3D to load (stall some secs) - - // if the wanted music is the same as the one currently playing, just continue playing - if(_MusicPlayed!=_MusicWanted) - { - // wait nbFrameBeforeChangeMax before actually changing the music - _NbFrameBeforeChange--; - if(_NbFrameBeforeChange<=0) - { - _MusicPlayed= _MusicWanted; - // play the music - if (SoundMngr != NULL) - SoundMngr->playMusic(_MusicPlayed, 500, _MusicWantedAsync, true, true); - } - } - - - // **** update mngr - if (SoundMngr != NULL) - SoundMngr->update(); -} - -void CSoundGlobalMenu::setMusic(const string &music, bool async) -{ - _MusicWanted= toLower(music); - _MusicWantedAsync= async; - // reset the counter - _NbFrameBeforeChange= NbFrameBeforeChangeMax; -} -static CSoundGlobalMenu SoundGlobalMenu; - - -static bool LuaBGDSuccessFlag = true; // tmp, for debug - - -void updateBGDownloaderUI() -{ - CInterfaceManager *im = CInterfaceManager::getInstance(); - CBGDownloaderAccess &bgDownloader = CBGDownloaderAccess::getInstance(); - bool bgWindowVisible = true; - if (im->isInGame()) - { - static NLMISC::CRefPtr bgDownloaderWindow; - if (!bgDownloaderWindow) - { - bgDownloaderWindow = CWidgetManager::getInstance()->getElementFromId("ui:interface:bg_downloader"); - } - bgWindowVisible = bgDownloaderWindow && bgDownloaderWindow->getActive(); - } - bool prevSuccess = LuaBGDSuccessFlag; - if (isBGDownloadEnabled() && PatchBegun) - { - if (AvailablePatchs == 0) - { - if (LuaBGDSuccessFlag) - { - LuaBGDSuccessFlag = CLuaManager::getInstance().executeLuaScript("bgdownloader:setPatchSuccess()"); - } - } - else - { - switch(bgDownloader.getLastTaskResult()) - { - case BGDownloader::TaskResult_Unknown: - { - float progress = 0.f; - /*if (bgDownloader.getTotalSize() != 0) - { - progress = (float) bgDownloader.getPatchingSize() / bgDownloader.getTotalSize(); - }*/ - if (bgDownloader.getTotalFilesToGet() != 0) - { - progress = (bgDownloader.getCurrentFilesToGet() + bgDownloader.getCurrentFileProgress()) / bgDownloader.getTotalFilesToGet(); - } - if (LuaBGDSuccessFlag && bgWindowVisible) - { - LuaBGDSuccessFlag = CLuaManager::getInstance().executeLuaScript(toString("bgdownloader:setPatchProgress(%f)", progress)); - } - // display current priority of the downloader - if (LuaBGDSuccessFlag && bgWindowVisible) - { - LuaBGDSuccessFlag = CLuaManager::getInstance().executeLuaScript("bgdownloader:displayPriority()"); - } - } - break; - case BGDownloader::TaskResult_Success: - if (LuaBGDSuccessFlag && bgWindowVisible) - { - LuaBGDSuccessFlag = CLuaManager::getInstance().executeLuaScript("bgdownloader:setPatchSuccess()"); - } - // task finished - AvailablePatchs = 0; - if (bgDownloader.getPatchCompletionFlag(true /* clear flag */)) - { - // when in-game, display a message to signal the end of the patch - if (im->isInGame()) - { - im->displaySystemInfo(CI18N::get("uiBGD_InGamePatchCompletion"), "BC"); - } - } - break; - default: - // error case - if (LuaBGDSuccessFlag && bgWindowVisible) - { - LuaBGDSuccessFlag = CLuaManager::getInstance().executeLuaScript("bgdownloader:setPatchError()"); - } - break; - } - } - } - else - { - if (LuaBGDSuccessFlag && bgWindowVisible) - { - if (isBGDownloadEnabled()) - { - // no necessary patch for now - LuaBGDSuccessFlag = CLuaManager::getInstance().executeLuaScript("bgdownloader:setNoNecessaryPatch()"); - } - else - { - // no download ui - LuaBGDSuccessFlag = CLuaManager::getInstance().executeLuaScript("bgdownloader:setNoDownloader()"); - } - } - } - if (prevSuccess != LuaBGDSuccessFlag) - { - nlwarning("Some scipt error occurred"); - } -} - - -// compute patcher priority, depending on the presence of one or more mainland characters : in this case, give the patch a boost -void updatePatcherPriorityBasedOnCharacters() -{ - if (isBGDownloadEnabled()) - { - if (CBGDownloaderAccess::getInstance().getDownloadThreadPriority() != BGDownloader::ThreadPriority_Paused) - { - // choose priority based on available characters : - bool hasMainlandChar = false; - for(std::vector::iterator it = CharacterSummaries.begin(); it != CharacterSummaries.end(); ++it) - { - if (it->Name.empty()) continue; - if (!it->InNewbieland) - { - hasMainlandChar = true; - break; - } - } - CBGDownloaderAccess::getInstance().requestDownloadThreadPriority(hasMainlandChar ? BGDownloader::ThreadPriority_Normal : BGDownloader::ThreadPriority_Low, false); - } - } -} - -// Launch the interface to choose a character -// ------------------------------------------------------------------------------------------------ -TInterfaceState globalMenu() -{ - CLoginProgressPostThread::getInstance().step(CLoginStep(LoginStep_CharacterSelection, "login_step_character_selection")); - - CBGDownloaderAccess &bgDownloader = CBGDownloaderAccess::getInstance(); - - if (isBGDownloadEnabled()) - { - // If there's a need for mainland download, then proceed - if (AvailablePatchs & (1 << BGDownloader::DownloadID_MainLand)) - { - // if a task is already started, then this was a situation where player went back from game to the character selection, - // so just unpause - BGDownloader::TTaskResult dummyResult; - ucstring dummyMessage; - if (!bgDownloader.isTaskEnded(dummyResult, dummyMessage)) - { - unpauseBGDownloader(); - } - } - } - - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - sint32 nScreenConnecting, nScreenIntro, nScreenServerCrashed; - fromString(CWidgetManager::getInstance()->getParser()->getDefine("screen_connecting"), nScreenConnecting); - fromString(CWidgetManager::getInstance()->getParser()->getDefine("screen_intro"), nScreenIntro); - fromString(CWidgetManager::getInstance()->getParser()->getDefine("screen_crashing"), nScreenServerCrashed); - - // SKIP INTRO : Write to the database if we have to skip the intro and write we want to skip further intro to client cfg - if (ClientCfg.SkipIntro) - { - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SKIP_INTRO", false); - if (pNL != NULL) - pNL->setValue64(1); - } - - TGameCycle serverTick = NetMngr.getCurrentServerTick(); - bool PlayerWantToGoInGame = false; - bool firewallTimeout = false; - - ProgressBar.finish(); // no progress while selecting character - - while (PlayerWantToGoInGame == false) - { - - #if defined(NL_OS_WINDOWS) && defined(NL_DEBUG) - // tmp for debug - if (::GetAsyncKeyState(VK_SPACE)) - { - pIM->uninitOutGame(); - pIM->initOutGame(); - CWidgetManager::getInstance()->activateMasterGroup ("ui:outgame", true); - NLGUI::CDBManager::getInstance()->getDbProp ("UI:CURRENT_SCREEN")->setValue32(2); // TMP TMP - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - CWidgetManager::getInstance()->getElementFromId("ui:outgame:charsel")->setActive(false); - CWidgetManager::getInstance()->getElementFromId("ui:outgame:charsel")->setActive(true); - // Active inputs - Actions.enable(true); - EditActions.enable(true); - LuaBGDSuccessFlag = true; - CWidgetManager::getInstance()->getParser()->reloadAllLuaFileScripts(); - } - #endif - - updateBGDownloaderUI(); - - - // Update network. - try - { - if ( ! firewallTimeout ) - NetMngr.update(); - } - catch (const EBlockedByFirewall&) - { - if ( NetMngr.getConnectionState() == CNetManager::Disconnect ) - { - firewallTimeout = true; - } - else - { - // Display the firewall alert string - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:outgame:connecting:title")); - if (pVT != NULL) - pVT->setText(CI18N::get("uiFirewallAlert")+ucstring("...")); - - // The mouse and fullscreen mode should be unlocked for the user to set the firewall permission - nlSleep( 30 ); // 'nice' the client, and prevent to make too many send attempts - } - - } - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - // check if we can send another dated block - if (NetMngr.getCurrentServerTick() != serverTick) - { - // - serverTick = NetMngr.getCurrentServerTick(); - NetMngr.send(serverTick); - } - else - { - // Send dummy info - NetMngr.send(); - } - // Update the DT T0 and T1 global variables - updateClientTime(); - CInputHandlerManager::getInstance()->pumpEvents(); - Driver->clearBuffers(CRGBA::Black); - Driver->setMatrixMode2D11(); - - // Update sound - SoundGlobalMenu.updateSound(); - - // Interface handling & displaying (processes clicks...) - pIM->updateFrameEvents(); - pIM->updateFrameViews(NULL); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - // Movie shooter - globalMenuMovieShooter(); - - // Force the client to sleep a bit. - if(ClientCfg.Sleep >= 0) - { - nlSleep(ClientCfg.Sleep); - } - - #if defined(NL_OS_WINDOWS) && defined(NL_DEBUG) - if (::GetAsyncKeyState(VK_CONTROL)) - { - pIM->displayUIViewBBoxs(""); - pIM->displayUICtrlBBoxs(""); - pIM->displayUIGroupBBoxs(""); - displayDebugUIUnderMouse(); - } - #endif - - // Display - Driver->swapBuffers(); - - // SERVER INTERACTIONS WITH INTERFACE - if (WaitServerAnswer) - { - if (noUserChar || userChar) - { - - if (isBGDownloadEnabled()) - { - // If there's a need for mainland download, then proceed - if (AvailablePatchs & (1 << BGDownloader::DownloadID_MainLand)) - { - // if a task is already started, then this was a situation where player went back from game to the character selection, - // so just unpause - BGDownloader::TTaskResult dummyResult; - ucstring dummyMessage; - if (bgDownloader.isTaskEnded(dummyResult, dummyMessage)) - { - // launch mainland patch as a background task - BGDownloader::CTaskDesc task(BGDownloader::DLState_GetAndApplyPatch, - (1 << BGDownloader::DownloadID_MainLand)); - bgDownloader.startTask(task, getBGDownloaderCommandLine(), false /* showDownloader */); - - // choose priority based on available characters : - updatePatcherPriorityBasedOnCharacters(); - - PatchBegun = true; - } - } - } - - //nlinfo("impulseCallBack : received userChars list"); - noUserChar = userChar = false; - if( FarTP.isReselectingChar() || !FarTP.isServerHopInProgress() ) // if doing a Server Hop, expect serverReceivedReady without action from the user - { - sint charSelect = -1; - if (ClientCfg.SelectCharacter != -1) - charSelect = ClientCfg.SelectCharacter; - - if (LoginCharsel != -1) - charSelect = LoginCharsel; - - WaitServerAnswer = false; - if (charSelect == -1 || FarTP.isReselectingChar()) - { - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:SERVER_RECEIVED_CHARS", false); - if (pNL != NULL) - { - pNL->setValue64 (1); // Send impulse to interface observers - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - pNL->setValue64 (0); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - } - } - else - { - // check that the pre selected character is available - if (CharacterSummaries[charSelect].People == EGSPD::CPeople::Unknown || charSelect > 4) - { - // BAD ! preselected char does not exist, use the first available or fail - uint i; - for (i=0; isystemMessageBox("You have no character for the current user.\nClient will exit.", "Char loading error", UDriver::okType, UDriver::exclamationIcon); - exit(-1); - } - else - { - UDriver::TMessageBoxId ret = Driver->systemMessageBox("The pre-selected character doesn't exist.\nDo you want to use the first available character instead ?", "Char loading error", UDriver::yesNoType, UDriver::warningIcon); - if (ret == UDriver::noId) - exit(-1); - else - charSelect = i; - } - } - // Auto-selection for fast launching (dev only) - CAHManager::getInstance()->runActionHandler("launch_game", NULL, toString("slot=%d|edit_mode=0", charSelect)); - - if (LoginCharsel == -1) - ClientCfg.SelectCharacter = charSelect; - } - - } - - // Clear sending buffer that may contain prevous QUIT_GAME when getting back to the char selection screen - NetMngr.flushSendBuffer(); - } - - if (CharNameValidArrived) - { - //nlinfo("impulseCallBack : received CharNameValidArrived"); - CharNameValidArrived = false; - WaitServerAnswer = false; - if (ClientCfg.SelectCharacter == -1) - { - CCDBNodeLeaf *pNL; - pNL = NLGUI::CDBManager::getInstance()->getDbProp(CharNameValidDBLink,false); - if (pNL != NULL) - { - if (CharNameValid) - pNL->setValue64(1); - else - pNL->setValue64(0); - } - - pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:SERVER_RECEIVED_VALID", false); - if (pNL != NULL) - { - pNL->setValue64 (1); // Send impulse to interface observers - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - pNL->setValue64 (0); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - } - } - } - - if (serverReceivedReady) - { - //nlinfo("impulseCallBack : received serverReceivedReady"); - serverReceivedReady = false; - WaitServerAnswer = false; - PlayerWantToGoInGame = true; - } - } - else - { - noUserChar = false; - userChar = false; - CharNameValidArrived = false; - serverReceivedReady = false; - } - - // Check if server disconnect the client - if (!ClientCfg.Local) - { - if (NetMngr.getConnectionState() == CNetManager::Disconnect) - { - // Display the connection failure screen - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:CURRENT_SCREEN", false); - if (pNL != NULL) - pNL->setValue64 (nScreenServerCrashed); - - if ( firewallTimeout ) - { - // Display the firewall error string instead of the normal failure string - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:outgame:crashing:title")); - if (pVT != NULL) - { - pVT->setMultiLine( true ); - pVT->setText(CI18N::get("uiFirewallFail")+ucstring(".\n")+ - CI18N::get("uiFirewallAlert")+ucstring(".")); - } - } - } - } - - - - // We want to quit the game without playing - if (game_exit) - return QUIT_THE_GAME; - } - - if (ClientCfg.SelectCharacter != -1) - PlayerSelectedSlot = ClientCfg.SelectCharacter; - - // Notify the state machine that we're exiting from global menu - LoginSM.pushEvent(CLoginStateMachine::ev_global_menu_exited); - - // Init the current Player Name (for interface.cfg and sentence.name save). Make a good File Name. - ucstring &playerName= CharacterSummaries[PlayerSelectedSlot].Name; - PlayerSelectedFileName= buildPlayerNameForSaveFile(playerName); - - // Init the current Player Home shard Id and name - CharacterHomeSessionId = CharacterSummaries[PlayerSelectedSlot].Mainland; - PlayerSelectedMainland= CharacterSummaries[PlayerSelectedSlot].Mainland; - PlayerSelectedHomeShardName.clear(); - PlayerSelectedHomeShardNameWithParenthesis.clear(); - for(uint i=0;igetWindowSize(width, height); - ClientCfg.Width = width; - ClientCfg.Height = height; - } - - connectionRestoreVideoMode (); - } - - // Skip intro next time - ClientCfg.writeBool("SkipIntro", true); - - // return SELECT_CHARACTER; - return GOGOGO_IN_THE_GAME; -} - - -// Init the character selection slot texts from the character summaries -// ------------------------------------------------------------------------------------------------ -class CAHNetInitCharSel : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - string sPath = getParam(Params, "slottexts"); - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - uint i; - for (i = 0; i < CharacterSummaries.size(); ++i) - { - CCharacterSummary &rCS = CharacterSummaries[i]; - CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId(sPath+":text"+NLMISC::toString(i)); - CViewText *pVT = dynamic_cast(pIE); - if (pVT == NULL) return; - - if (rCS.Name.empty()) - pVT->setText(CI18N::get("uiEmptySlot")); - else - pVT->setText(rCS.Name); - } - // 5 slots - for (; i < 5; ++i) - { - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(sPath+":text"+NLMISC::toString(i))); - if (pVT == NULL) return; - pVT->setText(CI18N::get("uiEmptySlot")); - } - } -}; -REGISTER_ACTION_HANDLER (CAHNetInitCharSel, "net_init_char_sel"); - -// ------------------------------------------------------------------------------------------------ -void setTarget(CCtrlBase *ctrl, const string &targetName, ucstring &value) -{ - std::vector targets; - // find first enclosing group - CCtrlBase *currCtrl = ctrl; - CInterfaceGroup *ig = NULL; - while (currCtrl) - { - ig = dynamic_cast(currCtrl); - if (ig != NULL) break; - currCtrl = currCtrl->getParent(); - } - if (ig) - { - CInterfaceExprValue exprValue; - exprValue.setUCString(value); - - CInterfaceLink::splitLinkTargets(targetName, ig, targets); - for(uint k = 0; k < targets.size(); ++k) - { - if (targets[k].Elem) targets[k].affect(exprValue); - } - } -} - -// ------------------------------------------------------------------------------------------------ -void setTarget(CCtrlBase *ctrl, const string &targetName, uint32 value) -{ - std::vector targets; - // find first enclosing group - CCtrlBase *currCtrl = ctrl; - CInterfaceGroup *ig = NULL; - while (currCtrl) - { - ig = dynamic_cast(currCtrl); - if (ig != NULL) break; - currCtrl = currCtrl->getParent(); - } - if (ig) - { - CInterfaceExprValue exprValue; - exprValue.setInteger(value); - - CInterfaceLink::splitLinkTargets(targetName, ig, targets); - for(uint k = 0; k < targets.size(); ++k) - { - if (targets[k].Elem) targets[k].affect(exprValue); - } - } -} - -// ------------------------------------------------------------------------------------------------ -class CAHGetSlot: public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - string sProp = getParam(Params, "prop"); - string sTarget = getParam(Params, "target"); - string sSlot = getParam(Params, "slot"); - - CInterfaceExprValue result; - if (!CInterfaceExpr::eval(sSlot, result)) - return; - uint8 selectedSlot = (uint8)result.getInteger(); - if (selectedSlot >= CharacterSummaries.size()) - return; - - PlayerSelectedSlot = selectedSlot; - - if (CharacterSummaries[PlayerSelectedSlot].Name.empty()) - return; - - ucstring sValue(""); - uint32 nValue = 0; - - if (sProp == "name") - { - sValue = CharacterSummaries[PlayerSelectedSlot].Name; - setTarget (pCaller, sTarget, sValue); - } -/* else if (sProp == "surname") -Deprecated { - sValue = CharacterSummaries[PlayerSelectedSlot].Surname; - setTarget (pCaller, sTarget, sValue); - } -*/ else if (sProp == "title") - { - bool womanTitle; - if( CharacterSummaries[PlayerSelectedSlot].VisualPropA.PropertySubData.Sex == 1 ) - { - UserEntity->setGender( GSGENDER::female ); - womanTitle = true; - } - else - { - UserEntity->setGender( GSGENDER::male ); - womanTitle = false; - } - string titleStr = CHARACTER_TITLE::toString(CharacterSummaries[PlayerSelectedSlot].Title); - sValue = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(titleStr, womanTitle); - { - // Sometimes translation contains another title - ucstring::size_type pos = sValue.find('$'); - if (pos != ucstring::npos) - { - sValue = STRING_MANAGER::CStringManagerClient::getTitleLocalizedName(CEntityCL::getTitleFromName(sValue), womanTitle); - } - } - setTarget (pCaller, sTarget, sValue); - } -/* else if (sProp == "orient") -Deprecated { - sValue = ROLES::roleToUCString(CharacterSummaries[PlayerSelectedSlot].Role); - setTarget (pCaller, sTarget, sValue); - } - else if (sProp == "job") - { -//Deprecated -// sValue = JOBS::jobToUCString(CharacterSummaries[PlayerSelectedSlot].Job); - sValue = JOBS::jobToUCString(JOBS::BladeBearer); - setTarget (pCaller, sTarget, sValue); - } -*/ else if (sProp == "level") - { -//Deprecated -// sValue = toString(CharacterSummaries[PlayerSelectedSlot].JobLevel); - sValue = toString(1); - setTarget (pCaller, sTarget, sValue); - } - else if (sProp == "pos") - { - nValue = CharacterSummaries[PlayerSelectedSlot].Location; - setTarget (pCaller, sTarget, nValue); - } - } -}; -REGISTER_ACTION_HANDLER (CAHGetSlot, "get_slot"); - - -// Setup the database from a database entry which represents a slot -// ------------------------------------------------------------------------------------------------ -class CAHSetDBFromSlot : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - string sDBLink = getParam(Params, "dblink"); - string sSlot = getParam(Params, "slot"); - - CInterfaceExprValue result; - if (!CInterfaceExpr::eval(sSlot, result)) - return; - - PlayerSelectedSlot = (uint8)result.getInteger(); - - if (PlayerSelectedSlot >= CharacterSummaries.size()) - return; - - // Setup the database from the character summary - CCharacterSummary &rCS = CharacterSummaries[PlayerSelectedSlot]; - if (rCS.Name.empty()) - return; - - SCharacter3DSetup::setupDBFromCharacterSummary(sDBLink, rCS); - } -}; -REGISTER_ACTION_HANDLER (CAHSetDBFromSlot, "set_db_from_slot"); - - -// Reset all the pushed radio button of a group -// ------------------------------------------------------------------------------------------------ -class CAHResetPushed: public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - string sDBLink = getParam(Params, "dblink"); - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId(pCaller->getId(), sDBLink); - CInterfaceGroup *pIG = dynamic_cast(pIE); - if (pIG == NULL) return; - - const vector vCB = pIG->getControls(); - for (uint i = 0; i < vCB.size(); ++i) - { - CCtrlBaseButton *pBut = dynamic_cast(vCB[i]); - if (pBut && pBut->getType() == CCtrlBaseButton::RadioButton) - { - pBut->setPushed (false); - } - } - } -}; -REGISTER_ACTION_HANDLER (CAHResetPushed, "reset_pushed"); - - - - - -// Launch the game given a slot (slot is reference to the character summaries -// ------------------------------------------------------------------------------------------------ -class CAHLaunchGame : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - // Get the edit/play mode - string sEditMode = getParam(Params, "edit_mode"); - bool wantsEditMode = false; - CInterfaceExprValue result; - bool wantsNewScenario = false; - - if (CInterfaceExpr::eval(sEditMode, result)) - { - wantsEditMode = (result.getInteger() == 1) || (result.getInteger() == 2); - wantsNewScenario = (result.getInteger() == 2); - } - - CInterfaceManager *im = CInterfaceManager::getInstance(); - if (wantsEditMode) - { - // full patch needed for edition, warn the client - if (AvailablePatchs != 0) - { - if (im->isInGame()) - { - inGamePatchUncompleteWarning(); - } - else - { - im->messageBoxWithHelp(CI18N::get("uiBGD_FullPatchNeeded"), "ui:outgame"); - } - return; - } - } - - // Get the player selected slot - string sSlot = getParam(Params, "slot"); - if (sSlot != "ingame_auto") - { - CInterfaceExprValue result; - if (!CInterfaceExpr::eval(sSlot, result)) - return; - PlayerSelectedSlot = (uint8)result.getInteger(); - if (PlayerSelectedSlot >= CharacterSummaries.size()) - return; - - ClientCfg.writeInt("SelectedSlot",PlayerSelectedSlot); - if (ClientCfg.SaveConfig) - ClientCfg.ConfigFile.save(); - } - - - /* - static volatile bool isMainlandCharacter = false; // TMP until we can get this info - if (isMainlandCharacter) - { - nlassert(0); // use id="message_box" !!! - if (AvailablePatchs != 0) - { - im->messageBoxWithHelp(CI18N::get("uiBGD_MainlandCharFullPatchNeeded"), "ui:outgame"); - } - return; - } - */ - - - // Select the right sheet to create the user character. - ClientCfg.UserSheet = CharacterSummaries[PlayerSelectedSlot].SheetId.toString(); - - // If the user wants to enter its editing session, get the ring server to Far TP to. - if (wantsEditMode) - { - - if (wantsNewScenario) - { - CSessionBrowserImpl &sb = CSessionBrowserImpl::getInstance(); - sb.init(NULL); - sb.closeEditSession(sb.getCharId()); - sb.waitOneMessage(CSessionBrowserImpl::getMessageName("on_invokeResult")); - } - if (FarTP.requestFarTPToSession( (TSessionId)0, PlayerSelectedSlot, CFarTP::LaunchEditor, false )) - { - WaitServerAnswer = true; // prepare to receive the character messages - } - -// // If the player clicked 'Launch Editor', there was no CONNECTION:SELECT_CHAR sent yet, -// // so don't wait for the EGS to acknowledge our quit message as he does not know our character -// LoginSM.pushEvent(CLoginStateMachine::ev_ingame_return); - - return; - } - - // Send CONNECTION:SELECT_CHAR - CBitMemStream out; - nlverify( GenericMsgHeaderMngr.pushNameToStream ("CONNECTION:SELECT_CHAR", out) ); - //nlinfo("impulseCallBack : CONNECTION:SELECT_CHAR '%d' sent.", PlayerSelectedSlot); - - - CSelectCharMsg SelectCharMsg; - SelectCharMsg.c = (uint8)PlayerSelectedSlot; - out.serial (SelectCharMsg); - if (!ClientCfg.Local/*ace!ClientCfg.Light*/) - { - NetMngr.push(out); - NetMngr.send(NetMngr.getCurrentServerTick()); - } - - //PlayerWantToGoInGame = true; - -// CBitMemStream out2; -// if(GenericMsgHeaderMngr.pushNameToStream("CONNECTION:ENTER", out2)) -// { -// NetMngr.push(out2); -// nlinfo("impulseCallBack : CONNECTION:ENTER sent"); -// } -// else -// nlwarning("unknown message name : 'CONNECTION:ENTER'."); - - WaitServerAnswer = true; - if (ClientCfg.Local) - serverReceivedReady = true; - } -}; -REGISTER_ACTION_HANDLER (CAHLaunchGame, "launch_game"); - - -// Ask the server to create a character -// ------------------------------------------------------------------------------------------------ -class CAHAskCreateChar : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - // Create the message for the server to create the character. - CBitMemStream out; - if (!GenericMsgHeaderMngr.pushNameToStream("CONNECTION:CREATE_CHAR", out)) - { - nlwarning ("don't know message name CONNECTION:CREATE_CHAR"); - return; - } - - // Setup the name - string sEditBoxPath = getParam (Params, "name"); - ucstring sFirstName = ucstring("NotSet"); - ucstring sSurName = ucstring("NotSet"); - CGroupEditBox *pGEB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(sEditBoxPath)); - if (pGEB != NULL) - sFirstName = pGEB->getInputString(); - else - nlwarning ("can't get edit box name : %s",sEditBoxPath.c_str()); - - // Build the character summary from the database branch ui:temp:char3d - CCharacterSummary CS; - string sCharSumPath = getParam(Params, "charsum"); - SCharacter3DSetup::setupCharacterSummaryFromDB(CS, sCharSumPath); - CS.Mainland = MainlandSelected; - CS.Name = sFirstName; - //CS.Surname = sSurName; - - // Create the message to send to the server from the character summary - CCreateCharMsg CreateCharMsg; - - CreateCharMsg.setupFromCharacterSummary(CS); - - // Slot - { - string sSlot = getParam(Params, "slot"); - - CInterfaceExprValue result; - if (!CInterfaceExpr::eval(sSlot, result)) - return; - - CreateCharMsg.Slot = (uint8)result.getInteger(); - - NLGUI::CDBManager::getInstance()->getDbProp("UI:SELECTED_SLOT")->setValue32(PlayerSelectedSlot); - } - - // Setup the new career - string sCaracBasePath = getParam (Params, "caracs"); - CreateCharMsg.NbPointFighter = (uint8)NLGUI::CDBManager::getInstance()->getDbProp(sCaracBasePath+"FIGHT")->getValue32(); - CreateCharMsg.NbPointCaster = (uint8)NLGUI::CDBManager::getInstance()->getDbProp(sCaracBasePath+"MAGIC")->getValue32(); - CreateCharMsg.NbPointCrafter = (uint8)NLGUI::CDBManager::getInstance()->getDbProp(sCaracBasePath+"CRAFT")->getValue32(); - CreateCharMsg.NbPointHarvester = (uint8)NLGUI::CDBManager::getInstance()->getDbProp(sCaracBasePath+"FORAGE")->getValue32(); - - // Setup starting point - string sLocationPath = getParam(Params, "loc"); - { - CreateCharMsg.StartPoint = RYZOM_STARTING_POINT::borea; - - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp (sLocationPath, false); - if (pNL != NULL) - CreateCharMsg.StartPoint = (RYZOM_STARTING_POINT::TStartPoint)(pNL->getValue64()); - else - nlwarning(("Can't read starting point from the database : " + sLocationPath).c_str()); - - if (CS.People == EGSPD::CPeople::Fyros) - CreateCharMsg.StartPoint= (RYZOM_STARTING_POINT::TStartPoint)(((uint8)CreateCharMsg.StartPoint) + ((uint8)RYZOM_STARTING_POINT::fyros_start)); - else if (CS.People == EGSPD::CPeople::Matis) - CreateCharMsg.StartPoint= (RYZOM_STARTING_POINT::TStartPoint)(((uint8)CreateCharMsg.StartPoint) + ((uint8)RYZOM_STARTING_POINT::matis_start)); - else if (CS.People == EGSPD::CPeople::Tryker) - CreateCharMsg.StartPoint= (RYZOM_STARTING_POINT::TStartPoint)(((uint8)CreateCharMsg.StartPoint) + ((uint8)RYZOM_STARTING_POINT::tryker_start)); - else // if (CS.People == EGSPD::CPeople::Zorai) - CreateCharMsg.StartPoint= (RYZOM_STARTING_POINT::TStartPoint)(((uint8)CreateCharMsg.StartPoint) + ((uint8)RYZOM_STARTING_POINT::zorai_start)); - - } - - // Send the message to the server - CreateCharMsg.serialBitMemStream (out); - if (!ClientCfg.Local/*!ClientCfg.Light*/) - { - noUserChar = userChar = false; - - NetMngr.push(out); - NetMngr.send(NetMngr.getCurrentServerTick()); - - //nlinfo("impulseCallBack : CONNECTION:CREATE_CHAR sent"); - CreateCharMsg.dump(); - } - else - { - userChar = true; - if (CharacterSummaries.size() < 5) - CharacterSummaries.push_back(CS); - } - WaitServerAnswer = true; - } -}; -REGISTER_ACTION_HANDLER (CAHAskCreateChar, "ask_create_char"); - - - -// Ask the server to delete a character -// ------------------------------------------------------------------------------------------------ -class CAHAskDeleteChar : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - // Create the message for the server to create the character. - CBitMemStream out; - if (!GenericMsgHeaderMngr.pushNameToStream("CONNECTION:DELETE_CHAR", out)) - { - nlwarning ("don't know message name CONNECTION:DELETE_CHAR"); - return; - } - - // Get the selected slot - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - string sSlot = getParam(Params, "slot"); - - CInterfaceExprValue result; - if (!CInterfaceExpr::eval(sSlot, result)) - return; - - uint8 nSelectedSlot = (uint8)result.getInteger(); - if (nSelectedSlot >= CharacterSummaries.size()) - return; - - out.serial (nSelectedSlot); - - // Yoyo: delete the Local files. To avoid problem if recreate a character with same name. - ucstring &playerName= CharacterSummaries[nSelectedSlot].Name; - string playerDeletedFileName= buildPlayerNameForSaveFile(playerName); - // Delete the 2 Local files - pIM->deletePlayerConfig(playerDeletedFileName); - pIM->deletePlayerKeys(playerDeletedFileName); - - // Send the message to the server - if (!ClientCfg.Local/*ace!ClientCfg.Light*/) - { - noUserChar = userChar = false; - NetMngr.push(out); - NetMngr.send(NetMngr.getCurrentServerTick()); - - //nlinfo("impulseCallBack : CONNECTION:DELETE_CHAR %d sent", nSelectedSlot); - } - else - { - if (nSelectedSlot < CharacterSummaries.size()) - CharacterSummaries.erase (CharacterSummaries.begin()+nSelectedSlot); - if (CharacterSummaries.size() != 0) - userChar = true; - else - noUserChar = true; - } - WaitServerAnswer = true; - } -}; -REGISTER_ACTION_HANDLER (CAHAskDeleteChar, "ask_delete_char"); - -// ------------------------------------------------------------------------------------------------ -string getTarget(CCtrlBase * /* ctrl */, const string &targetName) -{ - string sTmp = targetName; - std::vector targetsVector; - CInterfaceLink::splitLinkTargets(sTmp, NULL, targetsVector); - - CInterfaceLink::CTargetInfo &rTI = targetsVector[0]; - - CInterfaceElement *elem = rTI.Elem; - if (!elem) - { - nlwarning(" : Element is NULL"); - return ""; - } - const CReflectedProperty *pRP = CReflectSystem ::getProperty(elem->getReflectedClassName(), rTI.PropertyName); - - if (pRP->Type == CReflectedProperty::String) - return ((elem->*(pRP->GetMethod.GetString))()); - return ""; -} - -// ------------------------------------------------------------------------------------------------ -ucstring getUCTarget(CCtrlBase * /* ctrl */, const string &targetName) -{ - string sTmp = targetName; - std::vector targetsVector; - CInterfaceLink::splitLinkTargets(sTmp, NULL, targetsVector); - - CInterfaceLink::CTargetInfo &rTI = targetsVector[0]; - - CInterfaceElement *elem = rTI.Elem; - if (!elem) - { - nlwarning(" : Element is NULL"); - return ucstring(""); - } - const CReflectedProperty *pRP = elem->getReflectedProperty(rTI.PropertyName); - - if (pRP->Type == CReflectedProperty::UCString) - return ((elem->*(pRP->GetMethod.GetUCString))()); - return ucstring(""); -} - -/*// Ask the server to rename a character -// ------------------------------------------------------------------------------------------------ -class CAHAskRenameChar : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - string sName = getTarget(NULL,getParam(Params, "name")); - string sSurname = getTarget(NULL,getParam(Params, "surname")); - - string sDBSlot = getParam(Params, "dbslot"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - uint8 nSelectedSlot = (uint8)NLGUI::CDBManager::getInstance()->getDbProp(sDBSlot,false)->getValue32(); - - if (nSelectedSlot > CharacterSummaries.size()) - return; - - // Create the message for the server to create the character. - CBitMemStream out; - if (!GenericMsgHeaderMngr.pushNameToStream("CONNECTION:RENAME_CHAR", out)) - { - nlwarning ("don't know message name CONNECTION:RENAME_CHAR"); - return; - } - - // Get the selected slot - out.serial (nSelectedSlot); - out.serial (sName); - out.serial (sSurname); - - // Send the message to the server - if (!ClientCfg.Light) - { - noUserChar = userChar = false; - NetMngr.push (out); - NetMngr.send (NetMngr.getCurrentServerTick()); - - nldebug("impulseCallBack : CONNECTION:RENAME_CHAR sent"); - - // Wait for the character message which describe all the characters on a server - while (!noUserChar && !userChar) - { - //NetMngr.waitForServer(); - NetMngr.update(); - NetMngr.send(); - nlSleep(100); - } - } - else - { - CharacterSummaries[nSelectedSlot].FirstName = sName; - CharacterSummaries[nSelectedSlot].Surname = sSurname; - } - } -}; -REGISTER_ACTION_HANDLER (CAHAskRenameChar, "ask_rename_char"); -*/ - -// Ask the server if the name is not already used -// ------------------------------------------------------------------------------------------------ -class CAHAskValidName : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - string sTarget = getParam(Params, "target"); - string sDBLink = getParam(Params, "dblink"); - CharNameValidDBLink = sDBLink; - - ucstring sName = getUCTarget(NULL,sTarget); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - if (sName.empty()) - { - NLGUI::CDBManager::getInstance()->getDbProp(sDBLink,false)->setValue32(0); - return; - } - - // Ask the server - CharNameValid = true; - - // PATCH DU BUG DE L'ESPACE !!! - if (sName.find(' ') != ucstring::npos) - CharNameValid = false; - // PATCH DU BUG DE L'ESPACE !!! - - - if (CharNameValid) - { - if (!ClientCfg.Local/*ace!ClientCfg.Light*/) - { - - CBitMemStream out; - if (!GenericMsgHeaderMngr.pushNameToStream("CONNECTION:ASK_NAME", out)) - { - nlwarning ("don't know message name CONNECTION:ASK_NAME"); - return; - } - - CCheckNameMsg checkNameMsg; - checkNameMsg.Name = sName; - checkNameMsg.HomeSessionId = MainlandSelected; - checkNameMsg.serialBitMemStream(out); - - NewKeysCharNameWanted = sName; - // append shard name - for(uint k = 0; k < Mainlands.size(); ++k) - { - if (Mainlands[k].Id == MainlandSelected) - { - // extract name from mainland - /*ucstring::size_type first = Mainlands[k].Name.find('('); - ucstring::size_type last = Mainlands[k].Name.find(')'); - if (first != ucstring::npos && last != ucstring::npos && first < last) - { - NewKeysCharNameWanted += Mainlands[k].Name.substr(first, last - first + 1); - }*/ - NewKeysCharNameWanted += ('(' + Mainlands[k].Name + ')'); - break; - } - } - - NewKeysCharNameValidated.clear(); - - NetMngr.push(out); - NetMngr.send(NetMngr.getCurrentServerTick()); - - //nlinfo("impulseCallBack : CONNECTION:ASK_NAME sent"); - - // Wait for the valid character name message - CharNameValidArrived = false; - } - else - { - - CharNameValid = true; - CharNameValidArrived = true; - - for (uint i = 0; i < CharacterSummaries.size(); ++i) - { - ucstring ls = CharacterSummaries[i].Name.toString(); - if (ls == sName) - CharNameValid = false; - } - } - } - else - { - CharNameValidArrived = true; - } - WaitServerAnswer = true; - } -}; -REGISTER_ACTION_HANDLER (CAHAskValidName, "ask_valid_name"); - -// ------------------------------------------------------------------------------------------------ -class CAHPlaySound : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - string sName = getParam(Params, "name"); - TStringId id = CStringMapper::map(sName); - if (SoundMngr != NULL) - SoundMngr->spawnSource(id,CVector(0,0,0)); - } -}; -REGISTER_ACTION_HANDLER (CAHPlaySound, "play_sound"); - -// ------------------------------------------------------------------------------------------------ -class CAHPlayMusicOutgame : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - // get the name of the wanted music - string sName = getParam(Params, "name"); - bool async; - fromString(getParam(Params, "async"), async); - - // if empty name, return to default mode - if(sName.empty()) - sName= ClientCfg.SoundOutGameMusic; - - // change the music - SoundGlobalMenu.setMusic(sName, async); - } -}; -REGISTER_ACTION_HANDLER (CAHPlayMusicOutgame, "play_music_outgame"); - -// ------------------------------------------------------------------------------------------------ -class CAHRepeatUntil : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - string sProc = getParam(Params, "proc"); - string sCond = getParam(Params, "cond"); - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - for(;;) - { - vector p; - p.push_back(sProc); - CWidgetManager::getInstance()->runProcedure(sProc, pCaller, p); - - CInterfaceExprValue result; - if (CInterfaceExpr::eval(sCond, result)) - { - if (result.getBool()) - break; - } - else - { - break; - } - } - - } -}; -REGISTER_ACTION_HANDLER (CAHRepeatUntil, "repeatuntil"); - - -// ------------------------------------------------------------------------------------------------ -class CAHDispInfo : public IActionHandler -{ -public: - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - string sStr = getParam(Params, "str"); - string sVal = getParam(Params, "val"); - - string res; - - CInterfaceExprValue result; - if (CInterfaceExpr::eval(sStr, result)) - { - if (result.toString()) - { - res += result.getString(); - } - } - if (CInterfaceExpr::eval(sVal, result)) - { - if (result.toString()) - { - res += result.getString(); - } - } - - nlinfo(res.c_str()); - } -}; -REGISTER_ACTION_HANDLER (CAHDispInfo, "disp_info"); - - -// *************************************************************************** -class CAHInitMainlandList : public IActionHandler -{ -public: - - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - //CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_MAINLAND)); - if (pList == NULL) - { - nlwarning("element " GROUP_LIST_MAINLAND " not found probably bad outgame.xml"); - return; - } - - CInterfaceGroup *pPrevLine = NULL; - for(uint i = 0; i < Mainlands.size(); i++) - { - vector< pair < string, string > > params; - params.clear(); - params.push_back(pair("id", toString(Mainlands[i].Id))); - if (i>0) - params.push_back(pair("posref", "BL TL")); - - CInterfaceGroup *pNewLine = CWidgetManager::getInstance()->getParser()->createGroupInstance("t_mainland", GROUP_LIST_MAINLAND, params); - if (pNewLine != NULL) - { - CViewBase *pVBon = pNewLine->getView("online"); - CViewBase *pVBoff = pNewLine->getView("offline"); - if ((pVBon != NULL) && (pVBoff != NULL)) - { - pVBon->setActive(Mainlands[i].Online); - pVBoff->setActive(!Mainlands[i].Online); - } - - CViewText *pVT = dynamic_cast(pNewLine->getView("name")); - if (pVT != NULL) - { - ucstring ucstr = Mainlands[i].Name + ucstring(" ") + Mainlands[i].Description; - pVT->setText(ucstr); - } - - // Add to the list - pNewLine->setParent(pList); - pNewLine->setParentSize(pList); - pNewLine->setParentPos(pPrevLine); - pList->addGroup(pNewLine); - - pPrevLine = pNewLine; - } - } - // UI Patch - if (!Mainlands.empty()) - { - //choose default mainland from language code - uint32 defaultMainland = 0; - for(uint i = 0; i < Mainlands.size(); i++) - { - if( Mainlands[i].LanguageCode == ClientCfg.LanguageCode ) - { - defaultMainland = i; - break; - } - } - - CCtrlButton *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_MAINLAND ":"+toString(Mainlands[defaultMainland].Id)+":but")); - if (pCB != NULL) - { - pCB->setPushed(true); - CAHManager::getInstance()->runActionHandler (pCB->getActionOnLeftClick(), pCB, pCB->getParamsOnLeftClick()); - } - } - pList->invalidateCoords(); - } -}; -REGISTER_ACTION_HANDLER (CAHInitMainlandList, "init_mainland_list"); - - -// *************************************************************************** -class CAHResetMainlandList : public IActionHandler -{ -public: - - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - //CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_MAINLAND)); - pList->clearGroups(); - } -}; -REGISTER_ACTION_HANDLER (CAHResetMainlandList, "reset_mainland_list"); - - -// *************************************************************************** -class CAHMainlandSelect : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const std::string &Params) - { - //nlinfo("CAHMainlandSelect called"); - struct CUnpush : public CInterfaceElementVisitor - { - CCtrlBase *Ref; - virtual void visitCtrl(CCtrlBase *ctrl) - { - if (ctrl == Ref) return; - CCtrlBaseButton *but = dynamic_cast(ctrl); - if (but) - { - but->setPushed(false); - } - } - }; - CInterfaceGroup *list = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_MAINLAND)); - if (!list) - return; - - // unselect - if (Params.empty()) - { - CUnpush unpusher; - unpusher.Ref = pCaller; - list->visit(&unpusher); - } - - // now select - uint32 mainland; - if (Params.empty()) - { - CCtrlButton *pCB = dynamic_cast(pCaller); - if (!pCB) - return; - - std::string name = pCB->getId(); - name = name.substr(0, name.rfind(':')); - - if (!fromString(name.substr(name.rfind(':')+1, name.size()), mainland)) - return; - - pCB->setPushed(true); - } - else - if (!fromString(Params, mainland)) - return; - - // and store - MainlandSelected = (TSessionId)mainland; - } -}; -REGISTER_ACTION_HANDLER (CAHMainlandSelect, "mainland_select"); - - -// *************************************************************************** -class CAHInitKeysetList : public IActionHandler -{ -public: - - - - CInterfaceGroup *PrevLine; - CInterfaceGroup *List; - bool First; - - CInterfaceGroup *buildTemplate(const std::string &templateName, const std::string &id) - { - vector< pair < string, string > > params; - params.clear(); - params.push_back(pair("id", id)); - if (!First) - { - params.push_back(pair("posref", "BL TL")); - } - First = false; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - return CWidgetManager::getInstance()->getParser()->createGroupInstance(templateName, GROUP_LIST_KEYSET, params); - } - - void addGroupInList(CInterfaceGroup *pNewLine) - { - if (!pNewLine) return; - // Add to the list - pNewLine->setParent(List); - pNewLine->setParentSize(List); - pNewLine->setParentPos(PrevLine); - List->addGroup(pNewLine); - - PrevLine = pNewLine; - } - - void addSeparator() - { - addGroupInList(buildTemplate("t_keyseparator", "")); - } - - // add a new keyset in the list - void addKeySet(const std::string &filename, const ucstring &name, const ucstring tooltip) - { - nlassert(List); - CInterfaceGroup *pNewLine = buildTemplate("t_keyset", toString(filename)); - if (pNewLine != NULL) - { - CViewText *pVT = dynamic_cast(pNewLine->getView("name")); - if (pVT != NULL) - { - pVT->setText(name); - } - - CCtrlBase *pBut = pNewLine->getCtrl("but"); - if (pBut != NULL) - { - pBut->setDefaultContextHelp(tooltip); - } - addGroupInList(pNewLine); - } - } - - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - NewKeysCharNameWanted.clear(); - NewKeysCharNameValidated.clear(); - GameKeySet = "keys.xml"; - RingEditorKeySet = "keys_r2ed.xml"; - First = true; - PrevLine = NULL; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - List = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_KEYSET)); - if (List == NULL) - { - nlwarning("element " GROUP_LIST_KEYSET " not found probably bad outgame.xml"); - return; - } - - // built-in keysets - CConfigFile::CVar *keySetVar = ClientCfg.ConfigFile.getVarPtr(KeySetVarName); - sint wasdIndex = -1; - sint zqsdIndex = -1; - if (keySetVar && keySetVar->size() != 0) - { - for (uint k = 0; k < keySetVar->size(); ++k) - { - if (keySetVar->asString(k) == "zqsd") zqsdIndex = (sint) k; - if (keySetVar->asString(k) == "wasd") wasdIndex = (sint) k; - - std::string strId = "uiCP_KeysetName_" + keySetVar->asString(k); - strFindReplace(strId, ".", "_"); - ucstring keySetName = CI18N::get(strId); - strId = "uiCP_KeysetTooltip_" + keySetVar->asString(k); - strFindReplace(strId, ".", "_"); - if (CI18N::hasTranslation(strId)) - { - ucstring keySetTooltip = CI18N::get(strId); - addKeySet(keySetVar->asString(k), keySetName, keySetTooltip); - } - } - } - else - { - nlwarning("'%s' var not found in config file, or list is empty, proposing default keyset only", KeySetVarName); - std::string defaultKeySet = "keys"; - ucstring keySetName = CI18N::get("uiCP_KeysetName_" + defaultKeySet); - ucstring keySetTooltip = CI18N::get("uiCP_KeysetTooltip_" + defaultKeySet); - addKeySet(defaultKeySet, keySetName, keySetTooltip); - } - - // keyset from previous chars - std::vector savedFiles; - CPath::getPathContent("save/", false, false, true, savedFiles); - enum { GameKeys = 0x1, EditorKeys = 0x2 }; - typedef std::map TKeySetFileMap; - TKeySetFileMap keySetFiles; // combination of 'GameKeys' & 'EditorKeys' flag for each character - for (uint k = 0; k < savedFiles.size(); ++k) - { - if (testWildCard(CFile::getFilename(savedFiles[k]), "keys_*.xml")) - { - bool editorKeys = testWildCard(CFile::getFilename(savedFiles[k]), "keys_r2ed_*.xml"); - std::string baseName = CFile::getFilenameWithoutExtension(savedFiles[k]).substr(strlen(editorKeys ? "keys_r2ed_" : "keys_")); - if(!keySetFiles.count(baseName)) keySetFiles[baseName] = 0; - keySetFiles[baseName] |= editorKeys ? EditorKeys : GameKeys; - } - } - // - bool separatorAdded = false; - if (!keySetFiles.empty()) - { - for(TKeySetFileMap::iterator it = keySetFiles.begin(); it != keySetFiles.end(); ++it) - { - ucstring name; - if (ClientCfg.Local) - { - name = ucstring(it->first); - } - else - { - // search matching ucstring name from character summaries - for (uint k = 0; k < CharacterSummaries.size(); ++k) - { - if (it->first == buildPlayerNameForSaveFile(CharacterSummaries[k].Name)) - { - name = CharacterSummaries[k].Name; - } - } - } - if (!name.empty()) - { - if (!separatorAdded) - { - addSeparator(); - separatorAdded = true; - } - addKeySet(it->first, ucstring(it->first), CI18N::get(std::string("uiCP_KeysetImport") + (it->second & GameKeys ? "_Game" : "") - + (it->second & EditorKeys ? "_Editor" : ""))); - } - } - } - - // default to 'ZQSD' for French and Belgian keyboard, 'WASD' else - bool wasd = !CSystemUtils::isAzertyKeyboard(); - - /*sint startIndex = wasd ? wasdIndex : zqsdIndex; - if (startIndex == -1) startIndex = 0; - */ - // TMP TMP : no way to have 2 keys for the same action for now -> default to 'arrows' setting. - sint startIndex = 0; - nlassert(startIndex >= 0); - if (startIndex < (sint) List->getNumGroup()) - { - CInterfaceGroup *gr = dynamic_cast(List->getGroup(startIndex)); - if (gr) - { - CCtrlButton *pCB = dynamic_cast(gr->getCtrl("but")); - if (pCB != NULL) - { - pCB->setPushed(true); - CAHManager::getInstance()->runActionHandler (pCB->getActionOnLeftClick(), pCB, pCB->getParamsOnLeftClick()); - } - } - } - List->invalidateCoords(); - } -}; -REGISTER_ACTION_HANDLER (CAHInitKeysetList, "init_keyset_list"); - - -// *************************************************************************** -class CAHResetKeysetList : public IActionHandler -{ -public: - - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - //CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_KEYSET)); - pList->clearGroups(); - } -}; -REGISTER_ACTION_HANDLER (CAHResetKeysetList, "reset_keyset_list"); - - -// *************************************************************************** -class CAHResetKeysetSelect : public IActionHandler -{ - std::string getIdPostFix(const std::string fullId) - { - std::string::size_type pos = fullId.find_last_of(":"); - if (pos != std::string::npos) - return fullId.substr(pos + 1); - - return ""; - } - - virtual void execute(CCtrlBase *pCaller, const std::string &Params) - { - // 'unpush' all groups but the caller - struct CUnpush : public CInterfaceElementVisitor - { - CCtrlBase *Ref; - virtual void visitCtrl(CCtrlBase *ctrl) - { - if (ctrl == Ref) return; - CCtrlBaseButton *but = dynamic_cast(ctrl); - if (but) - { - but->setPushed(false); - } - } - }; - CInterfaceGroup *list = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_KEYSET)); - if (!list) - return; - - // unselect - CUnpush unpusher; - unpusher.Ref = pCaller; - list->visit(&unpusher); - - // now select - CCtrlBaseButton *but = dynamic_cast(pCaller); - if (but) - but->setPushed(true); - - std::string id; - if (Params.empty()) - { - if (!pCaller) return; - if (!pCaller->getParent()) return; - - id = getIdPostFix(pCaller->getParent()->getId()); - } - else - id = getIdPostFix(Params); - - GameKeySet = "keys.xml"; - RingEditorKeySet = "keys_r2ed.xml"; - - // compute the two filenames from the id - // if id is in the built-in keysets - CConfigFile::CVar *keySetVar = ClientCfg.ConfigFile.getVarPtr(KeySetVarName); - if (keySetVar && keySetVar->size() > 0) - { - for (uint k = 0; k < keySetVar->size(); ++k) - { - if (keySetVar->asString(k) == id) - { - GameKeySet = "keys" + string(id.empty() ? "" : "_") + id + ".xml"; - RingEditorKeySet = "keys_r2ed" + string(id.empty() ? "" : "_") + id + ".xml"; - return; - } - } - } - - // else maybe from a previous character? - if (CFile::isExists("save/keys_" + id + ".xml")) - GameKeySet = "keys_" + id + ".xml"; - - if (CFile::isExists("save/keys_r2ed_" + id + ".xml")) - RingEditorKeySet = "keys_r2ed_" + id + ".xml"; - - // NB: key file will be copied for real when the new character summary is - } -}; -REGISTER_ACTION_HANDLER (CAHResetKeysetSelect, "keyset_select"); - - - - - -// *************************** SCENARIO CONTROL WINDOW *********************** -// *************************************************************************** -// helper function for "setScenarioInformation" -static void setTextField(CInterfaceGroup* scenarioWnd, const std::string &uiName, const ucstring &text) -{ - CInterfaceElement *result = scenarioWnd->findFromShortId(uiName); - if(result) - { - CViewText* viewText = dynamic_cast(result); - if(viewText) - viewText->setText(text); - CGroupEditBox* editBox = dynamic_cast(result); - if(editBox) - editBox->setInputString(text); - - } -} -// helper function for "setScenarioInformation" -static void setTextField(CInterfaceGroup* scenarioWnd, const std::string &uiName, const std::string &utf8Text) -{ - ucstring ucText; - ucText.fromUtf8(utf8Text); - setTextField(scenarioWnd, uiName, ucText); -} -// helper function for "setScenarioInformation" -static std::string fieldLookup(const vector< pair< string, string > > &values, const std::string &id) -{ - for(uint i=0; i > values; - if(R2::getEditor().isInitialized()) - { - values = R2::getEditor().getDMC().getEditionModule().getScenarioHeader(); - } - else - { - R2::CScenarioValidator sv; - std::string md5, signature; - sv.setScenarioToLoad(scenarioName, values, md5, signature, false); - } - // - setTextField(scenarioWnd, "rules_value_text", fieldLookup(values, "Rules")); - uint levelRange = 0; - uint32 nLevel; - fromString(fieldLookup(values, "Level"), nLevel); - switch(nLevel) - { - case 20: levelRange = 0; break; - case 50: levelRange = 1; break; - case 100: levelRange = 2; break; - case 150: levelRange = 3; break; - case 200: levelRange = 4; break; - case 250: levelRange = 5; break; - } - setTextField(scenarioWnd, "level_value_text", CI18N::get("uiRAP_Level" + toString(levelRange))); - setTextField(scenarioWnd, "language_value_text", CI18N::get("uiR2ED" + fieldLookup(values, "Language"))); - setTextField(scenarioWnd, "type_value_text", CI18N::get("uiR2ED" + fieldLookup(values, "Type"))); - setTextField(scenarioWnd, "edit_small_description", fieldLookup(values, "ShortDescription")); - if(R2::getEditor().isInitialized()) - { - setTextField(scenarioWnd, "scenario_value_text", "'" + fieldLookup(values, "Title") + "'"); - } -} - - -void getChildrenControls(CInterfaceGroup* group, std::vector & controls) -{ - for(uint i=0; igetGroups().size(); i++) - getChildrenControls(group->getGroups()[i], controls); - - for(uint i=0; igetControls().size(); i++) - controls.push_back(group->getControls()[i]); -} - -inline void setToggleButton(CInterfaceGroup* scenarioWnd, const string & buttonName, bool pushed) -{ - CInterfaceElement * result = scenarioWnd->findFromShortId(buttonName); - if(result) - { - CInterfaceGroup * group = dynamic_cast(result); - if(group) - { - result = group->findFromShortId(string("toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - baseButton->setPushed(!pushed); - } - } - } -} - - -class CAHScenarioControl : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHScenarioControl called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup* scenarioWnd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:r2ed_scenario_control")); - if(!scenarioWnd) return; - - // -------- active some groups in function of Ryzom mode or Edition/Animation mode ---- - // active team toggle button? - CInterfaceElement *result = scenarioWnd->findFromShortId(string("invite_team")); - if(result) - { - CInterfaceGroup* groupTeam = dynamic_cast(result); - if(groupTeam) - { - bool team = !(R2::getEditor().isInitialized()); - if(team) - team = (NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:TEAM_MEMBER")->getValue8())!=0; - groupTeam->setActive(team); - } - } - - // set scenario name label - result = scenarioWnd->findFromShortId(string("current_scenario_label_text")); - if(result) - { - CViewText* viewText = dynamic_cast(result); - if(viewText) - { - viewText->setText(R2::getEditor().isInitialized()?CI18N::get("uiR2EDScenarioName"):CI18N::get("uiR2EDScenarioFileName")); - } - } - - // ok button tranlation - result = scenarioWnd->findFromShortId(string("ok_button")); - if(result) - { - CCtrlTextButton* okButton = dynamic_cast(result); - if(okButton) - { - if(R2::getEditor().getAccessMode()!=R2::CEditor::AccessDM) - okButton->setHardText(CI18N::get("uiR2EDLaunchScenario").toString()); - else - okButton->setHardText(CI18N::get("uiR2EDApplyScenarioFilters").toString()); - } - } - - // init current scenario name and parameters - if(!R2::getEditor().isInitialized()) - { - ScenarioFileName.clear(); - - // empty scenario - CInterfaceElement *result = scenarioWnd->findFromShortId(string("scenario_value_text")); - if(result) - { - CViewText* viewText= dynamic_cast(result); - - if(viewText) - viewText->setText(ucstring("")); - } - } - setScenarioInformation(scenarioWnd, ""); - - // hide description and information? - result = scenarioWnd->findFromShortId(string("scenario_info_prop")); - if(result) - result->setActive(R2::getEditor().isInitialized()); - - result = scenarioWnd->findFromShortId(string("description_gr")); - if(result) - result->setActive(R2::getEditor().isInitialized()); - - // mainlands list - result = scenarioWnd->findFromShortId(string("shards")); - if(result) - { - CGroupList * shardList = dynamic_cast(result); - if(shardList) - { - shardList->deleteAllChildren(); - - for(uint i = 0; i < Mainlands.size(); i++) - { - vector< pair < string, string > > params; - params.clear(); - params.push_back(pair("id", toString(Mainlands[i].Id))); - params.push_back(pair("w", "1024")); - params.push_back(pair("tooltip", "uiRingFilterShard")); - CInterfaceGroup *toggleGr = CWidgetManager::getInstance()->getParser()->createGroupInstance("label_toggle_button", shardList->getId(), params); - shardList->addChild(toggleGr); - // set unicode name - CViewText *shardName = dynamic_cast(toggleGr->getView("button_text")); - if (shardName) - { - shardName->setText(Mainlands[i].Name); - } - } - } - } - - // show/display "back" button - result = scenarioWnd->findFromShortId(string("load_button")); - if(result) - { - CCtrlBaseButton * loadB = dynamic_cast(result); - if(loadB) - { - loadB->setActive(!R2::getEditor().isInitialized()); - } - } - - // fill toggle buttons - if(R2::getEditor().getAccessMode()==R2::CEditor::AccessDM) - { - CSessionBrowserImpl & sessionBrowser = CSessionBrowserImpl::getInstance(); - sessionBrowser.getSessionInfo(sessionBrowser.getCharId(), R2::getEditor().getDMC().getEditionModule().getCurrentAdventureId()); - - if(sessionBrowser.waitOneMessage(sessionBrowser.getMessageName("on_sessionInfoResult"))) - { - TRaceFilter & raceFilter = sessionBrowser._LastRaceFilter; - setToggleButton(scenarioWnd, "fyros", raceFilter.checkEnumValue(TRaceFilterEnum::rf_fyros)); - setToggleButton(scenarioWnd, "matis", raceFilter.checkEnumValue(TRaceFilterEnum::rf_matis)); - setToggleButton(scenarioWnd, "tryker", raceFilter.checkEnumValue(TRaceFilterEnum::rf_tryker)); - setToggleButton(scenarioWnd, "zorai", raceFilter.checkEnumValue(TRaceFilterEnum::rf_zorai)); - - TReligionFilter & religionFilter = sessionBrowser._LastReligionFilter; - setToggleButton(scenarioWnd, "kami", religionFilter.checkEnumValue(TReligionFilterEnum::rf_kami)); - setToggleButton(scenarioWnd, "karavan", religionFilter.checkEnumValue(TReligionFilterEnum::rf_karavan)); - setToggleButton(scenarioWnd, "neutral", religionFilter.checkEnumValue(TReligionFilterEnum::rf_neutral)); - - TGuildFilter & guildFilter = sessionBrowser._LastGuildFilter; - setToggleButton(scenarioWnd, "guild_gr", (guildFilter==TGuildFilter::gf_any_player)); - - TShardFilter & shardFilter = sessionBrowser._LastShardFilter; - for(uint i=0; ifindFromShortId(string("global_access_toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - baseButton->setPushed(subscriptionClosed); - } - - bool autoInvite = sessionBrowser._LastAutoInvite; - result = scenarioWnd->findFromShortId(string("auto_invite_toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - baseButton->setPushed(!autoInvite); - } - - // description - string description = sessionBrowser._LastDescription; - if(!description.empty()) - { - result = scenarioWnd->findFromShortId(string("edit_small_description")); - if(result) - { - CGroupEditBox* editBox = dynamic_cast(result); - if(editBox) - editBox->setInputString(description); - } - } - } - else - { - nlwarning("getSessionInfo callback return false"); - } - } - else - { - result = scenarioWnd->findFromShortId(string("access_players_filter")); - if(result) - { - CInterfaceGroup* filtersGroup = dynamic_cast(result); - if(filtersGroup) - { - std::vector controls; - getChildrenControls(filtersGroup, controls); - for(uint i=0; i(control); - if(baseButton && (baseButton->getType()==CCtrlBaseButton::ToggleButton)) - baseButton->setPushed(false); - } - } - } - } - } -}; -REGISTER_ACTION_HANDLER (CAHScenarioControl, "init_scenario_control"); - - -// *************************************************************************** -class CAHScenarioInformation : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - nlinfo("CAHScenarioDescription called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup* scenarioWnd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:r2ed_scenario_control")); - if(!scenarioWnd) return; - - CInterfaceElement *result = scenarioWnd->findFromShortId(string("scenario_value_text")); - if(result) - { - CViewText* viewText= dynamic_cast(result); - - if(viewText) - { - ScenarioFileName = getParam(Params, "ScenarioName"); - setScenarioInformation(scenarioWnd, ScenarioFileName); - - string scenarioName = ScenarioFileName; - string::size_type posScenarioName = 0; - while(posScenarioName!=string::npos) - { - scenarioName = scenarioName.substr(posScenarioName==0?posScenarioName:posScenarioName+1); - posScenarioName = scenarioName.find('/'); - } - viewText->setText(scenarioName); - } - } - - // active description and information - result = scenarioWnd->findFromShortId(string("scenario_info_prop")); - if(result) - result->setActive(true); - - result = scenarioWnd->findFromShortId(string("description_gr")); - if(result) - result->setActive(true); - } -}; -REGISTER_ACTION_HANDLER (CAHScenarioInformation, "scenario_information"); - -// *************************************************************************** -class CAHHideCharsFilters : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHHideCharsFilters called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup* scenarioWnd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:r2ed_scenario_control")); - if(!scenarioWnd) return; - - bool lookingForPlayers = true; - CInterfaceElement *result = scenarioWnd->findFromShortId(string("global_access_toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - lookingForPlayers = !baseButton->getPushed(); // warning : on / off textures are inverted !!! - } - - result = scenarioWnd->findFromShortId(string("access_body_gr")); - if(result) - result->setActive(lookingForPlayers); - - result = scenarioWnd->findFromShortId(string("sep_global_access")); - if(result) - result->setActive(lookingForPlayers); - - result = scenarioWnd->findFromShortId(string("auto_invite_label")); - if(result) - result->setActive(lookingForPlayers); - - result = scenarioWnd->findFromShortId(string("auto_invite_toggle_butt")); - if(result) - result->setActive(lookingForPlayers); - - result = scenarioWnd->findFromShortId(string("invite_team")); - if(result) - { - bool team = (NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:TEAM_MEMBER")->getValue8())!=0; - team = (team && !(R2::getEditor().isInitialized()) && lookingForPlayers); - result->setActive(team); - } - } -}; -REGISTER_ACTION_HANDLER (CAHHideCharsFilters, "hide_chars_filters"); - -// *************************************************************************** -class CAHLoadScenario : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &/* Params */) - { - nlinfo("CAHLoadScenario called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup* scenarioWnd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:r2ed_scenario_control")); - if(!scenarioWnd) return; - - CInterfaceElement *result = NULL; - - // load scenario - if(!R2::getEditor().isInitialized()) - { - R2::CEditor::setStartingAnimationFilename(ScenarioFileName); - } - - // description - string description; - result = scenarioWnd->findFromShortId(string("edit_small_description")); - if(result) - { - CGroupEditBox* editBox = dynamic_cast(result); - if(editBox) - description = editBox->getInputString().toString(); - } - - // races - map races; - races["fyros"] = false; - races["matis"] = false; - races["tryker"] = false; - races["zorai"] = false; - for(map::iterator itRace=races.begin(); itRace!=races.end(); itRace++) - { - result = scenarioWnd->findFromShortId(itRace->first); - if(result) - { - CInterfaceGroup * group = dynamic_cast(result); - if(group) - { - result = group->findFromShortId(string("toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - itRace->second = !baseButton->getPushed(); - } - } - } - } - - // religion - map religions; - religions["kami"] = false; - religions["karavan"] = false; - religions["neutral"] = false; - for(map::iterator itReligion=religions.begin(); itReligion!=religions.end(); itReligion++) - { - result = scenarioWnd->findFromShortId(itReligion->first); - if(result) - { - CInterfaceGroup * group = dynamic_cast(result); - if(group) - { - result = group->findFromShortId(string("toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - itReligion->second = !baseButton->getPushed(); - } - } - } - } - - // guild - bool anyPlayer = false; - result = scenarioWnd->findFromShortId(string("guild_gr")); - if(result) - { - CInterfaceGroup * group = dynamic_cast(result); - if(group) - { - result = group->findFromShortId(string("toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - anyPlayer = !baseButton->getPushed(); - } - } - } - - // shards - std::vector shards(Mainlands.size(), false); - for(uint i=0; ifindFromShortId(toString(Mainlands[i].Id)); - if(result) - { - CInterfaceGroup * group = dynamic_cast(result); - if(group) - { - result = group->findFromShortId(string("toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - shards[i] = !baseButton->getPushed(); - } - } - } - } - - // levels - map levels; - levels["20"] = false; - levels["50"] = false; - levels["100"] = false; - levels["150"] = false; - levels["200"] = false; - levels["250"] = false; - for(map::iterator itLevel=levels.begin(); itLevel!=levels.end(); itLevel++) - { - result = scenarioWnd->findFromShortId(itLevel->first); - if(result) - { - CInterfaceGroup * group = dynamic_cast(result); - if(group) - { - result = group->findFromShortId(string("toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - itLevel->second = !baseButton->getPushed(); - } - } - } - } - - // global access - bool globalAccess = false; - result = scenarioWnd->findFromShortId(string("global_access_toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - globalAccess = !baseButton->getPushed(); - } - - // auto invite - bool autoInvite = false; - result = scenarioWnd->findFromShortId(string("auto_invite_toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - autoInvite = !baseButton->getPushed(); - } - - // invite your team - bool inviteTeam = false; - result = scenarioWnd->findFromShortId(string("team_toggle_butt")); - if(result) - { - CCtrlBaseButton * baseButton = dynamic_cast(result); - if(baseButton) - inviteTeam = !baseButton->getPushed(); - } - - bool launchScenarioFromRingAccessPoint = false; - - vector< pair< string, string > > values; - if(R2::getEditor().isInitialized()) - { - values = R2::getEditor().getDMC().getEditionModule().getScenarioHeader(); - } - else - { - R2::CScenarioValidator sv; - std::string md5, signature; - sv.setScenarioToLoad(ScenarioFileName, values, md5, signature, false); - launchScenarioFromRingAccessPoint = true; - } - - string rules, level, title; - string initialIsland, initialEntryPoint, initialSeason; - std::string lang, scenarioType; - std::string otherCharAccess; - std::string nevraxScenario = "0"; - std::string trialAllowed = "0"; - for(uint i=0; i pair = values[i]; - - if(pair.first == "Rules") rules = pair.second; - else if(pair.first == "Level") level = pair.second; - else if(pair.first == "Title") title = pair.second; - else if(pair.first == "InitialIsland") initialIsland = pair.second; - else if(pair.first == "InitialEntryPoint") initialEntryPoint = pair.second; - else if(pair.first == "InitialSeason") initialSeason = pair.second; - else if(pair.first == "Language") lang = pair.second; - else if(pair.first == "Type") scenarioType = pair.second; - else if(pair.first == "OtherCharAccess") otherCharAccess = pair.second; - else if(pair.first == "NevraxScenario") nevraxScenario = pair.second; - else if(pair.first == "TrialAllowed") trialAllowed = pair.second; - } - - uint nLevel; - fromString(level, nLevel); - R2::TSessionLevel sessionLevel = R2::TSessionLevel::TValues(nLevel/50 + 1); - - // ---- fix for old scenarii - if (lang == "French") - lang = "fr"; - else if (lang == "German" || lang == "Deutsch") - lang = "de"; - else //if (lang == "English") - lang = "en"; - - if (nlstricmp(scenarioType, "Roleplay") == 0 || nlstricmp(scenarioType, "Role play") == 0) - scenarioType = "so_story_telling"; - else if (nlstricmp(scenarioType, "Combat") == 0) - scenarioType = "so_hack_slash"; - // -------------------------- - - TRuleType ruleType(TRuleType::rt_strict); - if(rules==CI18N::get("uiR2EDliberal").toString()) - ruleType = TRuleType(TRuleType::rt_liberal); - else if(rules == CI18N::get("uiR2EDstrict").toString()) - ruleType = TRuleType(TRuleType::rt_strict); - volatile static bool override = false; - if (override) - { - if(rules== "Masterless") - ruleType = TRuleType(TRuleType::rt_liberal); - else if(rules == "Mastered") - ruleType = TRuleType(TRuleType::rt_strict); - } - - TRaceFilter raceFilter; - if(races["fyros"]) - raceFilter.setEnumValue(TRaceFilterEnum::rf_fyros); - if(races["matis"]) - raceFilter.setEnumValue(TRaceFilterEnum::rf_matis); - if(races["tryker"]) - raceFilter.setEnumValue(TRaceFilterEnum::rf_tryker); - if(races["zorai"]) - raceFilter.setEnumValue(TRaceFilterEnum::rf_zorai); - - TReligionFilter religionFilter; - if(religions["kami"]) - religionFilter.setEnumValue(TReligionFilterEnum::rf_kami); - if(religions["karavan"]) - religionFilter.setEnumValue(TReligionFilterEnum::rf_karavan); - if(religions["neutral"]) - religionFilter.setEnumValue(TReligionFilterEnum::rf_neutral); - - TGuildFilter guildFilter(anyPlayer?TGuildFilter::gf_any_player:TGuildFilter::gf_only_my_guild); - - TShardFilter shardFilter; - for (uint i = 0; i < shards.size(); ++i) - { - if (shards[i]) shardFilter.setEnumValue((RSMGR::TShardFilterEnum::TValues) (1<getDbProp("SERVER:USER:IS_NEWBIE")->getValueBool(); - if (FreeTrial && noob && (nevraxScenario != "1" || trialAllowed != "1")) - { - CViewText* pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:warning_free_trial:text")); - if (pVT != NULL) - pVT->setText(CI18N::get("uiRingWarningFreeTrial")); - CAHManager::getInstance()->runActionHandler("enter_modal", pCaller, "group=ui:interface:warning_free_trial"); - - return; - } - } - - - if(R2::getEditor().getAccessMode()!=R2::CEditor::AccessDM) - { - if (launchScenarioFromRingAccessPoint) - { - // hibernate Edit Session if active - sessionBrowser.hibernateEditSession(charId); - if(!sessionBrowser.waitOneMessage(sessionBrowser.getMessageName("on_invokeResult"))) - { - nlwarning("hibernateEditSession callback return false"); - } - - } - - // schedule session - bool launchSuccess = true; - sessionBrowser.scheduleSession(charId, TSessionType::st_anim, - title, description, sessionLevel, - /*TAccessType::at_public,*/ ruleType, TEstimatedDuration::et_medium, 0, TAnimMode::am_dm, - raceFilter, religionFilter, guildFilter, shardFilter, levelFilter, lang, RSMGR::TSessionOrientation(scenarioType), - !globalAccess, autoInvite); - - if(sessionBrowser.waitOneMessage(sessionBrowser.getMessageName("on_scheduleSessionResult"))) - { - if(sessionBrowser._LastScheduleSessionResult==0) - { - // start session - sessionBrowser.startSession(sessionBrowser._LastScheduleSessionCharId, - sessionBrowser._LastScheduleSessionId); - - if(sessionBrowser.waitOneMessage(sessionBrowser.getMessageName("on_invokeResult"))) - { - - if (launchScenarioFromRingAccessPoint) - { - if (!initialIsland.empty() && !initialEntryPoint.empty() && !initialSeason.empty()) - { - sessionBrowser.setSessionStartParams(charId, sessionBrowser._LastScheduleSessionId, initialIsland, initialEntryPoint, initialSeason); - } - } - - TSessionPartStatus sessionStatus; - if(ruleType==TRuleType::rt_liberal) - sessionStatus = TSessionPartStatus(TSessionPartStatus::sps_play_invited); - else - sessionStatus = TSessionPartStatus(TSessionPartStatus::sps_anim_invited); - - // invite player - sessionBrowser.inviteCharacter( - sessionBrowser._LastScheduleSessionCharId, - sessionBrowser._LastScheduleSessionId, - sessionBrowser._LastScheduleSessionCharId, - sessionStatus.toString()); - - if(sessionBrowser.waitOneMessage(sessionBrowser.getMessageName("on_invokeResult"))) - { - // request session - FarTP.requestFarTPToSession(sessionBrowser._LastScheduleSessionId, PlayerSelectedSlot, CFarTP::JoinSession, - !R2::getEditor().isInitialized()); - } - else - { - nlwarning("inviteCharacter callback return false"); - } - - if (sessionBrowser._LastInvokeResult != 0) - { - nlwarning("inviteCharacter callback use error values %d", sessionBrowser._LastInvokeResult); - } - - if(sessionBrowser._LastInvokeResult == 14) - { - CViewText* pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:warning_free_trial:text")); - if (pVT != NULL) - pVT->setText(CI18N::get("uiRingWarningFreeTrial")); - CAHManager::getInstance()->runActionHandler("enter_modal", pCaller, "group=ui:interface:warning_free_trial"); - } - - - // invite team - if(inviteTeam) - { - for (uint i = 0 ; i < 8 ; ++i) - { - uint32 val = NLGUI::CDBManager::getInstance()->getDbProp(NLMISC::toString("SERVER:GROUP:%d:NAME",i))->getValue32(); - if(val!=0) - { - STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance(); - ucstring res; - if (pSMC->getString(val,res)) - { - string charName = CEntityCL::removeTitleAndShardFromName(res).toString(); - sessionBrowser.inviteCharacterByName(sessionBrowser._LastScheduleSessionCharId, charName); - - if(!sessionBrowser.waitOneMessage(sessionBrowser.getMessageName("on_invokeResult"))) - { - nlwarning("inviteCharacterByName callback return false"); - } - - if(sessionBrowser._LastInvokeResult == 14) - { - CViewText* pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:warning_free_trial:text")); - if (pVT != NULL) - pVT->setText(CI18N::get("uiRingWarningInviteFreeTrial")); - CAHManager::getInstance()->runActionHandler("enter_modal", pCaller, "group=ui:interface:warning_free_trial"); - } - } - } - } - } - } - else - { - nlwarning("startSession callback return false"); - launchSuccess = false; - } - } - else if(sessionBrowser._LastScheduleSessionResult==10) - { - pIM->messageBoxWithHelp(CI18N::get("uiRingWarningBanishedPlayer")); - } - else - { - launchSuccess=false; - } - } - else - { - nlwarning("scheduleSession callback return false"); - launchSuccess = false; - } - - if(!launchSuccess) - { - pIM->messageBoxWithHelp(CI18N::get("uiRingLaunchScenarioError")); - } - else - { - scenarioWnd->setActive(false); - } - } - else - { - // update session - sessionBrowser.updateSessionInfo(charId, sessionBrowser._LastScheduleSessionId, title, 0, description, sessionLevel, - /*TAccessType::at_public, */TEstimatedDuration::et_medium, 0, raceFilter, religionFilter, - guildFilter, shardFilter, levelFilter, !globalAccess, autoInvite, lang, RSMGR::TSessionOrientation(scenarioType)); - - if(!sessionBrowser.waitOneMessage(sessionBrowser.getMessageName("on_invokeResult"))) - { - nlwarning("updateSessionInfo callback return false"); - pIM->messageBoxWithHelp(CI18N::get("uiRingUpdateScenarioFiltersError")); - } - else - { - scenarioWnd->setActive(false); - } - } - } -}; -REGISTER_ACTION_HANDLER (CAHLoadScenario, "load_scenario"); - - -// *************************************************************************** -class CAHOpenRingSessions : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - if(!R2::getEditor().isInitialized()) - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup* ringSessionsWnd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:ring_sessions")); - if(!ringSessionsWnd) return; - ringSessionsWnd->setActive(true); - } - } -}; -REGISTER_ACTION_HANDLER (CAHOpenRingSessions, "open_ring_sessions"); - -// *************************************************************************** -class CAHInitImportCharacter : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - CInterfaceGroup *list = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CHARACTER)); - if (!list) - { - nlwarning("element " GROUP_LIST_CHARACTER " not found probably bad outgame.xml"); - return; - } - - // retrieve saved files - std::vector savedCharacters; - CPath::getPathContent("save/", false, false, true, savedCharacters); - - CInterfaceGroup *newLine; - CInterfaceGroup *prevLine; - - for (uint i = 0; i < savedCharacters.size(); ++i) - { - // search saved characters only - if (testWildCard(CFile::getFilename(savedCharacters[i]), "character_*.save")) - { - const std::string id = CFile::getFilenameWithoutExtension(savedCharacters[i]).substr(strlen("character_")); - if (id.empty()) - continue; - - std::vector> params; - params.clear(); - params.push_back(std::pair("id", id)); - // adjust ref - if (list->getNumGroup() > 0) - params.push_back(std::pair("posref", "BL TL")); - - newLine = CWidgetManager::getInstance()->getParser()->createGroupInstance("t_import", GROUP_LIST_CHARACTER, params); - if (newLine) - { - CViewText *text = dynamic_cast(newLine->getView("name")); - if (text) - text->setText(ucstring(savedCharacters[i])); - - // first button is pushed - CCtrlButton *button = dynamic_cast(newLine->getCtrl("but")); - if (button && list->getNumGroup() == 0) - button->setPushed(true); - - // add to the list now - newLine->setParent(list); - newLine->setParentSize(list); - newLine->setParentPos(prevLine); - - list->addGroup(newLine); - - prevLine = newLine; - } - } - } - // none case - if (list->getNumGroup() == 0) - CLuaManager::getInstance().executeLuaScript("outgame:procCharselNotifaction(3)"); - - list->invalidateCoords(); - } -}; -REGISTER_ACTION_HANDLER( CAHInitImportCharacter, "import_char_init" ); - -// *************************************************************************** -class CAHResetImportCharacter : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - CInterfaceGroup *list = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CHARACTER)); - if (list) - list->clearGroups(); - - if (!ImportCharacter.empty()) - ImportCharacter = ""; - } -}; -REGISTER_ACTION_HANDLER( CAHResetImportCharacter, "import_char_reset" ); - -// *************************************************************************** -class CAHSelectImportCharacter : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const std::string &Params) - { - struct CUnpush : public CInterfaceElementVisitor - { - CCtrlBase *Ref; - virtual void visitCtrl(CCtrlBase *ctrl) - { - if (ctrl == Ref) return; - CCtrlBaseButton *but = dynamic_cast(ctrl); - if (but) - { - but->setPushed(false); - } - } - }; - CInterfaceGroup *list = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CHARACTER)); - if (!list) - return; - - // unselect - if (Params.empty()) - { - CUnpush unpusher; - unpusher.Ref = pCaller; - list->visit(&unpusher); - } - - // now select - std::string name; - if (Params.empty()) - { - CCtrlButton *pCB = dynamic_cast(pCaller); - if (!pCB) - return; - - std::string id = pCB->getId(); - id = id.substr(0, id.rfind(':')); - - if (!fromString(id.substr(id.rfind(':')+1, id.size()), name)) - return; - - pCB->setPushed(true); - } - else - if (!fromString(Params, name)) - return; - - ImportCharacter = ""; - // check filename and store - if (CFile::fileExists(toString("save/character_%s.save", name.c_str()))) - ImportCharacter = name; - } -}; -REGISTER_ACTION_HANDLER( CAHSelectImportCharacter, "import_char_select" ); - -// *************************************************************************** -class CAHImportCharacter : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - if (ImportCharacter.empty()) - return; - - if (!CFile::fileExists(toString("save/character_%s.save", ImportCharacter.c_str()))) - return; - - bool success = false; - - CIFile fd; - CCharacterSummary CS; - // use temporary file until close() - if (fd.open(toString("save/character_%s.save", ImportCharacter.c_str()))) - { - try - { - CS.serial(fd); - SCharacter3DSetup::setupDBFromCharacterSummary("UI:TEMP:CHAR3D", CS); - - // validate import - CDBManager::getInstance()->getDbProp("UI:TEMP:IMPORT")->setValue32(1); - success = true; - } - catch (const EStream &e) - { - nlwarning(e.what()); - } - fd.close(); - } - else - nlwarning("Failed to open file: save/character_%s.save", ImportCharacter.c_str()); - - // user notification - if (!success) - CLuaManager::getInstance().executeLuaScript("outgame:procCharselNotifaction(2)"); - else - CAHManager::getInstance()->runActionHandler("proc", NULL, "proc_charsel_create_new"); - } -}; -REGISTER_ACTION_HANDLER( CAHImportCharacter, "import_char" ); - -// *************************************************************************** -class CAHExportCharacter : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const std::string &Params) - { - if (Params.empty()) - return; - - sint32 slot = -1; - if (!fromString(getParam(Params, "slot"), slot)) - return; - - if (slot >= CharacterSummaries.size() || slot < 0) - return; - - // retrieve infos - CCharacterSummary &CS = CharacterSummaries[slot]; - if (CS.Name.empty()) - return; - - // extract name - const std::string name = buildPlayerNameForSaveFile(CS.Name.toString()); - - COFile fd; - bool success = false; - // use temporary file until close() - if (fd.open(toString("save/character_%s.save", name.c_str()), false, false, true)) - { - try - { - fd.serial(CS); - fd.flush(); - // validate - success = true; - } - catch (const EStream &e) - { - nlwarning(e.what()); - } - fd.close(); - } - else - nlwarning("Failed to open file: save/character_%s.save", name.c_str()); - - const uint8 val = (success == true) ? 0 : 1; - // user notification - CLuaManager::getInstance().executeLuaScript(toString("outgame:procCharselNotifaction(%i)", val)); - } -}; -REGISTER_ACTION_HANDLER( CAHExportCharacter, "export_char" ); diff --git a/code/ryzom/client/src/far_tp.cpp b/code/ryzom/client/src/far_tp.cpp deleted file mode 100644 index 1c2a6e612..000000000 --- a/code/ryzom/client/src/far_tp.cpp +++ /dev/null @@ -1,1522 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010-2011 Winch Gate Property Limited -// -// This source file has been modified by the following contributors: -// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014-2016 Jan BOON (Kaetemi) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -#include "stdpch.h" -#include "nel/3d/u_driver.h" -#include "far_tp.h" -#include "net_manager.h" -#include "connection.h" -#include "interface_v3/interface_manager.h" -#include "login_patch.h" -#include "init_main_loop.h" -#include "weather.h" -#include "time_client.h" -#include "timed_fx_manager.h" -#include "world_database_manager.h" -#include "continent_manager.h" -#include "user_entity.h" -#include "entities.h" -#include "interface_v3/input_handler_manager.h" -#include "interface_v3/bot_chat_page_all.h" -#include "sound_manager.h" -#include "actions_client.h" -#include "r2/editor.h" -#include "global.h" -#include "release.h" -#include "nel/misc/string_conversion.h" -#include "debug_client.h" -#include "session_browser_impl.h" -#include "game_share/security_check.h" -#include "client_chat_manager.h" -#include "bg_downloader_access.h" -#include "login_progress_post_thread.h" -#include "interface_v3/action_handler_base.h" -#include "item_group_manager.h" -#include "nel/misc/cmd_args.h" - -#ifdef DEBUG_NEW -#define new DEBUG_NEW -#endif - -using namespace NLMISC; -using namespace NLNET; -using namespace NL3D; -using namespace RSMGR; -using namespace R2; - -extern CClientChatManager ChatMngr; -extern CVariable SBSPortOffset; - -// *************************************************************************** -// Login state machine -// *************************************************************************** - -// Adapted from "nel/misc/string_conversion.h" -#define NL_BEGIN_CLASS_STRING_CONVERSION_TABLE(__class, __type) \ -static const NLMISC::CStringConversion<__class::__type>::CPair __type##_nl_string_conversion_table[] = \ -{ -#define NL_END_CLASS_STRING_CONVERSION_TABLE(__class, __type, __tableName, __defaultValue) \ -}; \ -NLMISC::CStringConversion<__class::__type> \ -__tableName(__type##_nl_string_conversion_table, sizeof(__type##_nl_string_conversion_table) \ - / sizeof(__type##_nl_string_conversion_table[0]), __class::__defaultValue); -#define NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(__class, val) { #val, __class::val}, - - -NL_BEGIN_CLASS_STRING_CONVERSION_TABLE (CLoginStateMachine, TState) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_start) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_login) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_auto_login) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_shard_list) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_start_config) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_scan_data) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_display_eula) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_check_patch) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_display_cat) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_patch) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_close_client) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_reboot_screen) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_restart_client) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_connect) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_browser_screen) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_ingame) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_leave_shard) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_enter_far_tp_main_loop) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_disconnect) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_reconnect_fs) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_reconnect_select_char) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_reconnect_ready) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_exit_global_menu) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_reconnect_error) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_create_account) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_end) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, st_unknown) -NL_END_CLASS_STRING_CONVERSION_TABLE(CLoginStateMachine, TState, StateConversion, st_unknown) - -NL_BEGIN_CLASS_STRING_CONVERSION_TABLE (CLoginStateMachine, TEvent) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_quit) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_skip_all_login) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_init_done) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_game_conf) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_data_scan) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_close_data_scan) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_login_ok) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_bad_login) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_shard_selected) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_patch_needed) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_no_patch) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_run_patch) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_close_patch) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_accept_eula) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_decline_eula) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_reboot) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_ingame_return) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_far_tp_main_loop_entered) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_connect) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_conn_failed) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_conn_dropped) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_enter_game) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_self_reconnected) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_chars_received) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_no_user_char) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_ready_received) -// NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_reselect_char) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_reconnect_ok_received) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_global_menu_exited) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_relog) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_create_account) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_close_create_account) - NL_CLASS_STRING_CONVERSION_TABLE_ENTRY(CLoginStateMachine, ev_unknown) -NL_END_CLASS_STRING_CONVERSION_TABLE(CLoginStateMachine, TEvent, EventConversion, ev_unknown) - -//----------------------------------------------- -// toString : -//----------------------------------------------- -const std::string& CLoginStateMachine::toString(CLoginStateMachine::TState state) -{ - return StateConversion.toString(state); -} - -//----------------------------------------------- -// toString : -//----------------------------------------------- -const std::string& CLoginStateMachine::toString(CLoginStateMachine::TEvent event) -{ - return EventConversion.toString(event); -} - - -#define SM_BEGIN_EVENT_TABLE \ - for(;!isTerminationRequested();) \ - { \ - TEvent ev = waitEvent(); \ - -#define SM_END_EVENT_TABLE \ - } \ - -/* -#define SM_EVENT(eventId, stateId) \ - if (ev == eventId) \ - { \ - try \ - { \ - COFile outputF; \ - string sLog = NLMISC::toString("[%s] %s -> %s\n", CLoginStateMachine::toString(ev).c_str(), CLoginStateMachine::toString(_CurrentState).c_str(), CLoginStateMachine::toString(stateId).c_str()); \ - if ( outputF.open( getLogDirectory() + "error_join.log", true, true ) ) \ - { \ - outputF.serialBuffer( (uint8*)(&sLog[0]), (uint)sLog.size() ); \ - outputF.close(); \ - } \ - } \ - catch (const Exception &) \ - {} \ - _CurrentState = stateId; \ - break; \ - } \ -*/ - -#define SM_EVENT(eventId, stateId) \ - if (ev == eventId) \ - { \ - _CurrentState = stateId; \ - break; \ - } \ - -extern std::string LoginLogin, LoginPassword, LoginCustomParameters; -extern bool noUserChar; -extern bool userChar; -extern bool serverReceivedReady; -extern bool CharNameValidArrived; -extern bool FirstFrame; -extern bool IsInRingSession; - -extern void selectTipsOfTheDay (uint tips); -#define BAR_STEP_TP 2 - -extern NLMISC::CCmdArgs Args; - -CLoginStateMachine::TEvent CLoginStateMachine::waitEvent() -{ - nlassert(CCoTask::getCurrentTask() == this); - - while (_NextEvents.empty() && !isTerminationRequested()) - { - // wait until someone push an event on the state machine - yield(); - - if (isTerminationRequested()) - return ev_quit; - } - - TEvent ev = _NextEvents.front(); - _NextEvents.pop_front(); - - return ev; -} - -void CLoginStateMachine::pushEvent(TEvent eventId) -{ - // set the next event - _NextEvents.push_back(eventId); - - if (CCoTask::getCurrentTask() != this) - { - /// resume the state machine to advance state - resume(); - } -} - - -void CLoginStateMachine::run() -{ - // state machine coroutine - - while (_CurrentState != st_end && !isTerminationRequested()) - { - switch(_CurrentState) - { - case st_start: - /// initial state - - if (!ClientCfg.TestBrowser) - { - if (LoginPassword.empty()) - { - if (!LoginCustomParameters.empty() && LoginLogin.empty()) - { - // alternate login procedure - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_init_done, st_alt_login); - SM_EVENT(ev_skip_all_login, st_ingame); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - } - else - { - // standard procedure - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_init_done, st_login); - SM_EVENT(ev_skip_all_login, st_ingame); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - } - } - else - { - // login 2, bypass the login screen - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_init_done, st_auto_login); - SM_EVENT(ev_skip_all_login, st_ingame); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - - } - } -// else -// { -// // browser test mode -// SM_BEGIN_EVENT_TABLE -// SM_EVENT(ev_init_done, st_browser_screen); -// SM_EVENT(ev_quit, st_end); -// SM_END_EVENT_TABLE -// } - - break; - case st_login: - /// display login screen and options - { - initLoginScreen(); - - if (ClientCfg.R2Mode) - { - // r2 mode - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_login_ok, st_check_patch); - SM_EVENT(ev_game_conf, st_start_config); - SM_EVENT(ev_data_scan, st_scan_data); - SM_EVENT(ev_create_account, st_create_account); - SM_EVENT(ev_bad_login, st_login); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - } - else - { - // legacy mode - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_login_ok, st_shard_list); - SM_EVENT(ev_game_conf, st_start_config); - SM_EVENT(ev_data_scan, st_scan_data); - SM_EVENT(ev_create_account, st_create_account); - SM_EVENT(ev_bad_login, st_login); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - } - } - break; - case st_auto_login: - initAutoLogin(); - -// if (ClientCfg.R2Mode) - { - // r2 mode - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_login_ok, st_check_patch); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - } -// else -// { -// // legacy mode -// SM_BEGIN_EVENT_TABLE -// SM_EVENT(ev_login_ok, st_check_patch); -// SM_EVENT(ev_quit, st_end); -// SM_END_EVENT_TABLE -// } - break; - case st_alt_login: - initAltLogin(); - -// if (ClientCfg.R2Mode) - { - // r2 mode - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_login_not_alt, st_login); - SM_EVENT(ev_login_ok, st_check_patch); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - } -// else -// { -// // legacy mode -// SM_BEGIN_EVENT_TABLE -// SM_EVENT(ev_login_ok, st_check_patch); -// SM_EVENT(ev_quit, st_end); -// SM_END_EVENT_TABLE -// } - break; - case st_shard_list: - /// display the shard list - initShardDisplay(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_shard_selected, st_check_patch); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - - break; - case st_start_config: - /// launch the configurator and close ryzom - break; - case st_scan_data: - /// run the check data thread - initDataScan(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_close_data_scan, st_login); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - - break; - case st_create_account: - - if (initCreateAccount()) - { - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_login_ok, st_check_patch); - SM_EVENT(ev_close_create_account, st_login); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - } - else - { - // return to login menu if an error occurred - _CurrentState = st_login; - } - - break; - case st_display_eula: - { - /// display the eula and wait for validation - - if (ClientCfg.SkipEULA) - { - // we don't want to see eula, auto accept - pushEvent(ev_accept_eula); - } - - bool mustReboot = false; - - if (isBGDownloadEnabled()) - { - mustReboot = CBGDownloaderAccess::getInstance().mustLaunchBatFile(); - } - else - { - mustReboot = CPatchManager::getInstance()->mustLaunchBatFile(); - } - - if (mustReboot) - { - // skip eula and show reboot screen - _CurrentState = st_reboot_screen; - break; - } - - initEula(); - -// Login sequence was reordered -// if (ClientCfg.R2Mode) -// { -// // ring mode -// SM_BEGIN_EVENT_TABLE -// SM_EVENT(ev_accept_eula, st_browser_screen); -// SM_EVENT(ev_quit, st_end); -// SM_END_EVENT_TABLE -// } -// else -// { -// // legacy mode - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_accept_eula, st_connect); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE -// } - } - break; - case st_check_patch: - /// check the data to check if patch needed - CLoginProgressPostThread::getInstance().step(CLoginStep(LoginStep_PostLogin, "login_step_post_login")); - - if (!ClientCfg.PatchWanted || (Args.haveArg("n") && Args.getLongArg("nopatch").front() == "1")) - { - // client don't want to be patched ! - _CurrentState = st_display_eula; - break; - } - - initPatchCheck(); - SM_BEGIN_EVENT_TABLE - if (isBGDownloadEnabled()) - { - SM_EVENT(ev_patch_needed, st_patch); // no choice for patch content when background downloader is used - } - else - { - SM_EVENT(ev_patch_needed, st_display_cat); - } - SM_EVENT(ev_no_patch, st_display_eula); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - - break; - case st_display_cat: - initCatDisplay(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_run_patch, st_patch); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - - break; - case st_patch: - /// run the patch process and display progress - initPatch(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_close_patch, st_display_eula); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - break; - case st_close_client: - /// terminate the client and quit - break; - case st_reboot_screen: - /// display the reboot screen and wait validation - initReboot(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_reboot, st_end); - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - - break; - case st_restart_client: - /// restart the client with login bypass params - break; - case st_connect: - /// connect to the FS (start the 'in game' mode) - ConnectToShard(); - - if (ClientCfg.R2Mode) - { - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_enter_game, st_ingame); - SM_END_EVENT_TABLE - } - else - { - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_enter_game, st_end); - SM_EVENT(ev_conn_failed, st_shard_list); - SM_END_EVENT_TABLE - } - break; -// case st_browser_screen: -// /// show the outgame browser -// -// if (!ClientCfg.TestBrowser) -// { -// // in test browser mode, the browser is already init -// initWebBrowser(); -// } -// -// SM_BEGIN_EVENT_TABLE -// SM_EVENT(ev_connect, st_connect); -// SM_EVENT(ev_relog, st_login); -// SM_EVENT(ev_quit, st_end); -// SM_END_EVENT_TABLE -// -// break; - case st_ingame: - SM_BEGIN_EVENT_TABLE - //SM_EVENT(ev_chars_received, st_ingame); // ignored for normal login procedure - //SM_EVENT(ev_no_user_char, st_ingame); // " - //SM_EVENT(ev_ready_received, st_ingame); // " - //SM_EVENT(ev_global_menu_exited, st_ingame); " - SM_EVENT(ev_connect, st_leave_shard); // connect to another shard - SM_END_EVENT_TABLE - break; - case st_leave_shard: - /* - * Far TP / Server Hop / Reselect character entry point - */ - - // Server Hop part 1: We are not in main loop but still at character selection - // => make a hop to the specified server without doing anything with interface - // Far TP part 1.1: From the ingame main loop, the admin html box gives us an event ev_connect for the destination shard. - // Note: the admin html box is run by CInputHandlerManager::getInstance()->pumpEvents() in the main loop. - // Tip: to see where a co-task is resumed from, just add a breakpoint on the end of CCoTask::resume(). - CAHManager::getInstance()->runActionHandler("quit_ryzom", NULL, ""); - - if (!FarTP.isIngame()) // assumes there is no Far TP starting between char selection and main loop, see below - { - crashLogAddServerHopEvent(); - - FarTP.onServerQuitOk(); // don't wait for onServerQuitOK() because the EGS will no longer send it if it requests a Far TP during "select char" (not sending USER_CHAR) - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_ingame_return, st_disconnect); - SM_END_EVENT_TABLE - } - else - { - if(FarTP.isReselectingChar()) - crashLogAddReselectPersoEvent(); - else - crashLogAddFarTpEvent(); - - if (NetMngr.getConnectionState() == CNetworkConnection::Disconnect) - FarTP.onServerQuitOk(); // don't wait for onServerQuitOK() because the EGS is down - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_ingame_return, st_enter_far_tp_main_loop); - SM_EVENT(ev_enter_game, st_ingame); - SM_END_EVENT_TABLE - } - break; - case st_enter_far_tp_main_loop: - // if bgdownloader is used, then pause it - pauseBGDownloader(); - - - // Far TP part 1.2: let the main loop finish the current frame. - // This is called when CONNECTION:SERVER_QUIT_OK is received (from NetMngr.update() in main loop). - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_far_tp_main_loop_entered, st_disconnect); - SM_END_EVENT_TABLE - break; - case st_disconnect: - // Far TP part 2: disconnect from the FS and unload shard-specific data (called from farTPmainLoop()) - // FarTP.disconnectFromPreviousShard(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_connect, st_reconnect_fs); - SM_END_EVENT_TABLE - break; - case st_reconnect_fs: - // Server Hop part 3.1: connect to the new shard (called from globalMenu()) - // Far TP part 3.1: connect to the new shard (called from farTPmainLoop()) - FarTP.connectToNewShard(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_self_reconnected, st_ingame); - SM_EVENT(ev_chars_received, st_reconnect_select_char); - SM_EVENT(ev_no_user_char, st_reconnect_error); - SM_EVENT(ev_conn_failed, st_reconnect_error); - SM_EVENT(ev_conn_dropped, st_reconnect_error); - SM_END_EVENT_TABLE - break; - case st_reconnect_select_char: - // Server Hop part 3.2: bypass character selection ui & select the same character. - // Far TP part 3.2: bypass character selection ui & select the same character. - // This is called from farTPmainloop(), when CONNECTION:USER_CHARS is received. - if( !FarTP.isReselectingChar() ) - { - FarTP.selectCharAndEnter(); - } - // Far TP part 3.2bis: see in farTPmainLoop() - - if (!FarTP.isIngame()) - { - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_ready_received, st_exit_global_menu); - SM_EVENT(ev_conn_dropped, st_reconnect_error); - SM_END_EVENT_TABLE - } - else - { - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_ready_received, st_reconnect_ready); - SM_EVENT(ev_conn_dropped, st_reconnect_error); - if ( FarTP.isReselectingChar() && (ev == ev_connect) ) - { - // Inside this Character Reselect we embed a new Server Hop - FarTP.beginEmbeddedServerHop(); - _CurrentState = st_leave_shard; - break; - } - SM_END_EVENT_TABLE - } - break; - case st_exit_global_menu: - // Server Hop part 3.3 - // Stay in Server Hop state until the global menu has been exited - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_global_menu_exited, FarTP.isServerHopEmbedded() ? st_reconnect_ready : st_ingame); - SM_END_EVENT_TABLE - break; - case st_reconnect_ready: - // Far TP part 3.3: send ready. - // This is called from farTPmainloop(), when CONNECTION:READY is received. - - if ( FarTP.isServerHopEmbedded() ) - FarTP.endEmbeddedServerHop(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_enter_game, st_ingame); - SM_EVENT(ev_conn_dropped, st_reconnect_error); - SM_END_EVENT_TABLE - break; - case st_reconnect_error: - // Far TP failed - FarTP.onFailure(); - - SM_BEGIN_EVENT_TABLE - SM_EVENT(ev_quit, st_end); - SM_END_EVENT_TABLE - break; - default: - nlwarning("Unhandeled state"); - break; - } - } -} - - -// *************************************************************************** -// Far TP -// *************************************************************************** - -CFarTP FarTP; - -extern std::string CurrentCookie; -extern string ClientApp; - - -namespace R2 -{ - extern bool ReloadUIFlag; -} - - -/* - * requestFarTPToSession - */ -bool CFarTP::requestFarTPToSession(TSessionId sessionId, uint8 charSlot, CFarTP::TJoinMode joinMode, bool bailOutIfSessionVanished) -{ - if (_HookedForEditor) - { - // Redirect Far TP to editor instead of following instructions - _HookedForEditor = false; - return FarTP.requestFarTPToSession((TSessionId)0, charSlot, CFarTP::LaunchEditor, true); // allow bailing out in case of edition session not reachable - } - - // call the join session using the session browser interface - uint32 charId = (NetMngr.getLoginCookie().getUserId()<<4)+(0xf&charSlot); - - // Clean out for next Far TP - _SessionIdToJoinFast = 0; - - CSessionBrowserImpl &sb = CSessionBrowserImpl::getInstance(); - sb.init(NULL); -// sb.setAuthInfo(NetMngr.getLoginCookie()); -// sb.connectItf(CInetAddress("borisb", 80)); - - sb.CurrentJoinMode = joinMode; - // send the join session -// _JoinSessionResultReceived = false; - try - { - switch (joinMode) - { - case LaunchEditor: - { -retryJoinEdit: - TSessionId sessionId(0); - sb.joinEditSession(charId, ClientApp); - - bool ret = sb.waitOneMessage(CSessionBrowserImpl::getMessageName("on_joinSessionResult")); - - if (!ret) - throw "Protocol error"; - if (sb._LastJoinSessionResult == 2) - { - // the edit session did not exist, create a new one - sb.scheduleSession(charId, TSessionType::st_edit, "", "", TSessionLevel::sl_a, /*TAccessType::at_private, */TRuleType::rt_strict, TEstimatedDuration::et_long, 0, TAnimMode(), TRaceFilter(), TReligionFilter(), TGuildFilter(), TShardFilter(), TLevelFilter(), std::string(), TSessionOrientation(), true, true); - ret = sb.waitOneMessage(CSessionBrowserImpl::getMessageName("on_scheduleSessionResult")); - if (!ret || sb._LastScheduleSessionResult!= 0) throw "schedule error"; - sessionId = sb._LastScheduleSessionId; - - // invite the char in the session - sb.inviteCharacter(charId, sessionId, charId, TSessionPartStatus::sps_edit_invited); - ret = sb.waitOneMessage(CSessionBrowserImpl::getMessageName("on_invokeResult")); - if (!ret || sb._LastInvokeResult != 0) throw "Invitation Error"; - - // now, start the edit session - sb.startSession(charId, sessionId); - ret = sb.waitOneMessage(CSessionBrowserImpl::getMessageName("on_invokeResult")); - if (!ret || sb._LastInvokeResult != 0) throw "start session error"; - - // retry to join - goto retryJoinEdit; - } - else if (sb._LastJoinSessionResult == 15) - { - sessionId = sb._LastJoinSessionId; - // the session was closed, the SU has put it in planned state, start it - sb.startSession(charId, sessionId); - ret = sb.waitOneMessage(CSessionBrowserImpl::getMessageName("on_invokeResult")); - if (!ret || sb._LastInvokeResult != 0) throw "start session error (2), no DSS available"; - // retry to join - goto retryJoinEdit; - } - else if (sb._LastJoinSessionResult != 0) - { - // any other error are not recoverable from here - throw "join session error"; - } - - // ok, the join is accepted !, the other far TP work is done in the callback - } - break; - case JoinSession: - { - sb.joinSession(charId, sessionId, ClientApp); - - bool ret = sb.waitOneMessage(CSessionBrowserImpl::getMessageName("on_joinSessionResult")); - - if (!ret) - throw "Protocol error"; - if (sb._LastJoinSessionResult == 16) - { -// #pragma message (NL_LOC_WRN "inform the player that he is banned from the ring") - throw "User ban from the ring"; - } - if (sb._LastJoinSessionResult != 0) - { - throw "Join session error"; - } - // ok, the join is accepted !, the other far TP work is done in the callback - } - break; - case JoinMainland: -//retryJoinMainland: - { - TSessionId sessionId(0); - sb.joinMainland(charId, ClientApp); - - bool ret = sb.waitOneMessage(CSessionBrowserImpl::getMessageName("on_joinSessionResult")); - - if (!ret) - throw "Protocol error"; - if (sb._LastJoinSessionResult != 0) - { - // some error during the join - throw "Error joining session"; - } - // ok, the join is accepted !, the other far TP work is done in the callback - } - break; - default: - nlstop; - } - - return true; - } - -// -// const string url = _URLBase + string(_URLTable[joinMode]); -// string res; -// try -// { -// // Get the address of a front-end service via http -// if (!HttpClient.connect(url)) -// throw 1; -// switch (joinMode) -// { -// case CFarTP::LaunchEditor: -// if (!HttpClient.sendGetWithCookie(url, "ryzomId", CurrentCookie, toString("charSlot=%u", charSlot))) -// throw 2; -// break; -// case CFarTP::JoinSession: -// if (!HttpClient.sendPostWithCookie(url, "ryzomId", CurrentCookie, toString("sessionId=%u&charSlot=%u", sessionId, charSlot))) -// throw 2; -// break; -// case CFarTP::JoinMainland: -// if (!HttpClient.sendPostWithCookie(url, "ryzomId", CurrentCookie, "ml=")) -// throw 2; -// break; -// } -// if (!HttpClient.receive(res)) -// throw 3; -// HttpClient.disconnect(); -// string::size_type luaPos = res.find(""); -// if (luaPos == string::npos) -// throw 4; -// res = res.substr(luaPos + 5); -// res = res.substr(0, res.find("")); -// nlinfo("Found server for %ssession %u", joinMode==CFarTP::LaunchEditor ? "editing " : "", sessionId); -// -// // Begin Far TP -// CInterfaceManager *pIM = CInterfaceManager::getInstance(); -// pIM->executeLuaScript(res, true); -// return true; -// } - catch ( char *errorMsg ) - { -// // Get more details on the error -// string httpErrorStr; -// if (errorNum < 4) // we didn't receive an answer -// httpErrorStr = toString(" (HTTP error %u)", errorNum); -// if ( errorNum == 4 ) -// { -// string::size_type posEndOfFirstLine = res.find( "\n" ); -// if ( posEndOfFirstLine == string::npos ) -// { -// // Invalid http answer -// httpErrorStr = toString(" (HTTP invalid)"); -// } -// else -// { -// // Http status not OK (e.g. "404 Not Found") -// httpErrorStr = res.substr( 0, posEndOfFirstLine ); -// if ( httpErrorStr.find( "200 OK" ) == string::npos ) -// httpErrorStr = " (" + httpErrorStr + ")"; -// else -// httpErrorStr.clear(); -// } -// } - bool requestRetToMainland = /*httpErrorStr.empty() &&*/ bailOutIfSessionVanished; - bool isAttemptingEmbeddedServerHop = isReselectingChar() && (joinMode != CFarTP::JoinSession); - bool letReturnToCharSelect = (!isIngame()) || isAttemptingEmbeddedServerHop; - - // User-friendly message - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - if ( letReturnToCharSelect ) - { -// // Hide all buttons except Quit. If !requestRetToMainland, we will show them back at the end of connectToNewShard(). -// CAHManager::getInstance()->runActionHandler( "proc", NULL, "charsel_disable_buttons" ); -// CAHManager::getInstance()->runActionHandler( "set", NULL, "target_property=ui:outgame:charsel:quit_but:active|value=1" ); - - CInterfaceElement *btnOk = CWidgetManager::getInstance()->getElementFromId("ui:outgame:charsel:message_box:ok"); - if (btnOk) - btnOk->setActive( ! requestRetToMainland ); - - // Hide the black screen i.e. force showing the interface - CInterfaceElement *charSelBlackScreen = CWidgetManager::getInstance()->getElementFromId("ui:outgame:charsel:black_screen"); - if (charSelBlackScreen) - { - CViewBase *charSelBlackScreenBitmap = dynamic_cast(charSelBlackScreen); - if (charSelBlackScreenBitmap) - charSelBlackScreenBitmap->setAlpha(0); - } - } - pIM->messageBoxWithHelp( - CI18N::get(requestRetToMainland ? "uiSessionVanishedFarTP" : "uiSessionUnreachable") + ucstring(errorMsg), - letReturnToCharSelect ? "ui:outgame:charsel" : "ui:interface"); - - // Info in the log - string outErrorMsg = toString("Could not join %ssession %u: '%s' error\n", joinMode==CFarTP::LaunchEditor ? "editing " : "", sessionId.asInt(), errorMsg ); - nlwarning( outErrorMsg.c_str() ); -// if ( httpErrorStr.empty() ) -// { -// string delimiter = "Content-Type: text/html"; -// string::size_type delimPos = res.find( delimiter ); -// if ( delimPos != string::npos ) -// res = res.substr( delimPos + delimiter.size() ); -// } -// uint pos = 0; -// do -// { -// WarningLog->displayRaw( res.substr( pos, 200 ).c_str() ); // truncates long strings -// pos += 200; -// } -// while ( pos < res.size() ); - WarningLog->displayRawNL( "" ); - - // Save this error (regular log file is deleted at every startup) -// res = res + "\n\n"; - /*try - { - COFile outputF; - if ( outputF.open( getLogDirectory() + "error_join.log", true, true ) ) - { - time_t currentTime; - time( ¤tTime ); - string headerS = NLMISC::toString( "\n\n%s%s\n\n", asctime(localtime(¤tTime)), outErrorMsg.c_str() ); - outputF.serialBuffer( (uint8*)(&headerS[0]), (uint)headerS.size() ); -// outputF.serialBuffer( (uint8*)(&res[0]), res.size() ); - outputF.close(); - } - } - catch (const Exception &) - {} - */ - - // If the session is not a permanent session and has vanished, pop the position - if ( requestRetToMainland ) - { - requestReturnToPreviousSession( sessionId ); - LastGameCycle = NetMngr.getCurrentServerTick(); - NetMngr.send(NetMngr.getCurrentServerTick()); - } - else if ( letReturnToCharSelect ) - { - // Show all buttons except 'New character' so that the character can retry entering game or choose another character. - CAHManager::getInstance()->runActionHandler( "proc", NULL, "charsel_enable_buttons" ); - CAHManager::getInstance()->runActionHandler( "set", NULL, "target_property=ui:outgame:charsel:create_new_but:active|value=0" ); - - CInterfaceGroup* charselGroup = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:outgame:charsel")); - if(charselGroup) - CAHManager::getInstance()->runActionHandler( "proc", charselGroup, "charsel_init_buttons" ); - } - - return false; - } -} - - -/* - * hookNextFarTPForEditor - */ -void CFarTP::hookNextFarTPForEditor() -{ - _HookedForEditor = true; -} - -/* - * requestReturnToPreviousSession - */ -void CFarTP::requestReturnToPreviousSession(TSessionId rejectedSessionId) -{ - const string msgName = "CONNECTION:RET_MAINLAND"; - CBitMemStream out; - nlverify(GenericMsgHeaderMngr.pushNameToStream(msgName, out)); - out.serial(PlayerSelectedSlot); - out.serial(rejectedSessionId); - NetMngr.push(out); - nlinfo("%s sent", msgName.c_str()); -} - -/* - * requestReconnection - */ -void CFarTP::requestReconnection() -{ - _ReselectingChar = true; - if (!requestFarTPToSession(TSessionId(std::numeric_limits::max()), std::numeric_limits::max(), CFarTP::JoinMainland, false)) - _ReselectingChar = false; -} - - -const char * CFarTP::_URLTable[CFarTP::NbJoinModes] = -{ - "edit_session.php", - "join_session.php", - "join_shard.php" -}; - - -/* - * States - */ - -bool CFarTP::isFarTPInProgress() const -{ - CLoginStateMachine::TState state = LoginSM.getCurrentState(); - return (state == CLoginStateMachine::st_leave_shard || - state == CLoginStateMachine::st_enter_far_tp_main_loop || - state == CLoginStateMachine::st_disconnect || - state == CLoginStateMachine::st_reconnect_fs || - state == CLoginStateMachine::st_reconnect_select_char || - state == CLoginStateMachine::st_reconnect_ready || - state == CLoginStateMachine::st_reconnect_error); -} - -bool CFarTP::isServerHopInProgress() const -{ - CLoginStateMachine::TState state = LoginSM.getCurrentState(); - return (state == CLoginStateMachine::st_leave_shard || - state == CLoginStateMachine::st_reconnect_fs || - state == CLoginStateMachine::st_reconnect_select_char || - state == CLoginStateMachine::st_exit_global_menu || - state == CLoginStateMachine::st_reconnect_error); // TODO: error handling -} - - -// from begin of Far TP to disconnection -bool CFarTP::isLeavingShard() const -{ - CLoginStateMachine::TState state = LoginSM.getCurrentState(); - return (state == CLoginStateMachine::st_leave_shard || - state == CLoginStateMachine::st_enter_far_tp_main_loop || - state == CLoginStateMachine::st_disconnect); -} - -// from reconnection to game entering -bool CFarTP::isJoiningShard() const -{ - CLoginStateMachine::TState state = LoginSM.getCurrentState(); - return (state == CLoginStateMachine::st_reconnect_fs || - state == CLoginStateMachine::st_reconnect_select_char || - state == CLoginStateMachine::st_reconnect_ready || - state == CLoginStateMachine::st_reconnect_error); -} - - -/* - * Events - */ - -void CFarTP::onServerQuitOk() -{ - game_exit_request = false; - ryzom_exit_request = false; - - if (LoginSM.getCurrentState() == CLoginStateMachine::st_leave_shard) - LoginSM.pushEvent(CLoginStateMachine::ev_ingame_return); -} - -void CFarTP::onServerQuitAbort() -{ - game_exit_request = false; - ryzom_exit_request = false; - - if (LoginSM.getCurrentState() == CLoginStateMachine::st_leave_shard) - LoginSM.pushEvent(CLoginStateMachine::ev_enter_game); - _ReselectingChar = false; -} - -void CFarTP::disconnectFromPreviousShard() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - if (isIngame()) - { - // Display background (TODO: not Kami) - beginLoading (StartBackground); - UseEscapeDuringLoading = false; - - // Play music and fade out the Game Sound - if (SoundMngr) - { - // Loading Music Loop.ogg - LoadingMusic = ClientCfg.SoundOutGameMusic; - SoundMngr->playEventMusic(LoadingMusic, CSoundManager::LoadingMusicXFade, true); - SoundMngr->fadeOutGameSound(ClientCfg.SoundTPFade); - } - - // Change the tips - selectTipsOfTheDay (rand()); - - // Start progress bar and display background - ProgressBar.reset (BAR_STEP_TP); - ucstring nmsg("Loading..."); - ProgressBar.newMessage ( ClientCfg.buildLoadingString(nmsg) ); - ProgressBar.progress(0); - } - - // Disconnect from the FS - NetMngr.disconnect(); - - if (isIngame()) - { - // Save the R2EDEnabled flag to know if we are switching it when we reconnect - _PreviousR2EdEnabled = ClientCfg.R2EDEnabled; - - // Release R2 editor if applicable - R2::getEditor().autoConfigRelease(IsInRingSession); - } - - if( isReselectingChar() ) - { - releaseMainLoopReselect(); - } - else - { - // String manager: remove all waiting callbacks and removers - // (if some interface stuff has not received its string yet, its remover will get useless) - STRING_MANAGER::CStringManagerClient::release( false ); - - // Ugly globals - userChar = false; - noUserChar = false; - serverReceivedReady = false; - CharNameValidArrived = false; - UserCharPosReceived = false; - SabrinaPhraseBookLoaded = false; - } - - // Restart the network manager, the interface sync counter and the entities - pIM->resetShardSpecificData(); - - /* - ServerToLocal autocopy stuff: - When reinit will reset server counters to 0 in the server database, onServerChange() - will be called and data will be copied since CInterfaceManager::_LocalSyncActionCounter==0 - (done in resetShardSpecificData() above) - If we do the resetShardSpecificData() after, scenari could arise where Local database could not be reseted - */ - NetMngr.reinit(); - - if (isIngame() && !isReselectingChar()) - { - nlinfo("FarTP: calling EntitiesMngr.reinit()"); - EntitiesMngr.reinit(); - } - LoginSM.pushEvent(CLoginStateMachine::ev_connect); -} - -void CFarTP::connectToNewShard() -{ - // TODO: start commands? - - // Connect to the next FS - NetMngr.initCookie(Cookie, FSAddr); - - // connect the session browser to the new shard - NLNET::CInetAddress sbsAddress(CSessionBrowserImpl::getInstance().getFrontEndAddress()); - sbsAddress.setPort(sbsAddress.port()+SBSPortOffset); - CSessionBrowserImpl::getInstance().connectItf(sbsAddress); - - string result; - NetMngr.connect(result); - if (!result.empty()) - { - _Reason = new string(result); - LoginSM.pushEvent(CLoginStateMachine::ev_conn_failed); - return; - } - - // Reinit the string manager cache. - STRING_MANAGER::CStringManagerClient::instance()->initCache(FSAddr, ClientCfg.LanguageCode); - - // reset the chat mode - ChatMngr.resetChatMode(); - - // The next step will be triggered by the CONNECTION:USER_CHARS msg from the server -} - -// return to character selection screen -bool CFarTP::reselectCharacter() -{ - if ( ! reconnection() ) - { - // The user clicked the Quit button - releaseOutGame(); - return false; - } - return true; -} - -void CFarTP::selectCharAndEnter() -{ - CBitMemStream out; - nlverify (GenericMsgHeaderMngr.pushNameToStream("CONNECTION:SELECT_CHAR", out)); - CSelectCharMsg SelectCharMsg; - SelectCharMsg.c = (uint8)PlayerSelectedSlot; // PlayerSelectedSlot has not been reset - out.serial(SelectCharMsg); - NetMngr.push(out); - /*//Obsolete - CBitMemStream out2; - nlverify(GenericMsgHeaderMngr.pushNameToStream("CONNECTION:ENTER", out2)); - NetMngr.push(out2); - */ - LastGameCycle = NetMngr.getCurrentServerTick(); - NetMngr.send(NetMngr.getCurrentServerTick()); - - // if (!isIngame()) - // globalMenu will exit when WaitServerAnswer and serverReceivedReady (triggered by the CONNECTION:READY msg) are true - // else - // Next step will be triggered by the CONNECTION:READY msg from the server -} - -void CFarTP::sendReady() -{ - if ( isReselectingChar() ) - { - initMainLoop(); - } - else - { - // Set season - RT.updateRyzomClock(NetMngr.getCurrentServerTick()); - DayNightCycleHour = (float)RT.getRyzomTime(); - CurrSeason = RT.getRyzomSeason(); - RT.updateRyzomClock(NetMngr.getCurrentServerTick()); - DayNightCycleHour = (float)RT.getRyzomTime(); - ManualSeasonValue = RT.getRyzomSeason(); - - // Reset all fx (no need to CTimedFXManager::getInstance().reset() and EntitiesMngr.getGroundFXManager().reset() because the entities have been removed) - CProjectileManager::getInstance().reset(); - FXMngr.reset(); // (must be done after EntitiesMngr.release()) - EntitiesMngr.getGroundFXManager().init(Scene, ClientCfg.GroundFXMaxDist, ClientCfg.GroundFXMaxNB, ClientCfg.GroundFXCacheSize); - - // Get the sheet for the user from the CFG. - // Initialize the user and add him into the entity manager. - // DO IT AFTER: Database, Collision Manager, PACS, scene, animations loaded. - CSheetId userSheet(ClientCfg.UserSheet); - nlinfo("FarTP: calling EntitiesMngr.create(0, userSheet.asInt())"); - TNewEntityInfo emptyEntityInfo; - emptyEntityInfo.reset(); - EntitiesMngr.create(0, userSheet.asInt(), emptyEntityInfo); - - // Wait for the start position (USER_CHAR) and set the continent - waitForUserCharReceived(); - - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - if ( ClientCfg.R2EDEnabled != _PreviousR2EdEnabled ) - { - // Reload textures, keys and interface config if we are switch between playing and r2 mode - // Must be done after receiving the current R2EDEnabled flag (USER_CHAR) - pIM->loadIngameInterfaceTextures(); - - // Unload (and save if leaving normal playing mode) keys and interface config - // Instead of doing it in disconnectFromPreviousShard(), we do it here, only when it's needed - ClientCfg.R2EDEnabled = ! ClientCfg.R2EDEnabled; - pIM->uninitInGame0(); - CItemGroupManager::getInstance()->uninit(); - - ClientCfg.R2EDEnabled = ! ClientCfg.R2EDEnabled; - ActionsContext.removeAllCombos(); - - if ( ! ClientCfg.R2EDEnabled ) - { - // Remove all existing keys and load them back, and load new interface config - pIM->loadKeys(); - CWidgetManager::getInstance()->hideAllWindows(); - pIM->loadInterfaceConfig(); - pIM->loadLandmarks(); - } - else - { - R2::ReloadUIFlag = true; // in R2ED mode the CEditor class deals with it - } - } - pIM->configureQuitDialogBox(); // must be called after waitForUserCharReceived() to know the ring config - - ContinentMngr.select(UserEntity->pos(), ProgressBar); // IMPORTANT : must select continent after ui init, because ui init also load landmarks (located in the icfg file) - // landmarks would be invisible else (RT 12239) - - - - // Update Network until current tick increase. - LastGameCycle = NetMngr.getCurrentServerTick(); - while (LastGameCycle == NetMngr.getCurrentServerTick()) - { - // Event server get events - CInputHandlerManager::getInstance()->pumpEventsNoIM(); - // Update Network. - NetMngr.update(); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - // Be nice to the system - nlSleep(100); - } - LastGameCycle = NetMngr.getCurrentServerTick(); - ProgressBar.progress(1); - - // Create the message for the server to create the character. - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream("CONNECTION:READY", out)) - { - out.serial(ClientCfg.LanguageCode); - NetMngr.push(out); - NetMngr.send(NetMngr.getCurrentServerTick()); - } - - // To be sure server crash is not fault of client - ConnectionReadySent = true; // must be called before BotChatPageAll->initAfterConnectionReady() - - // To reset the inputs. - CInputHandlerManager::getInstance()->pumpEventsNoIM(); - - if(BotChatPageAll && (! ClientCfg.R2EDEnabled)) - BotChatPageAll->initAfterConnectionReady(); - - // Transition from background to game - FirstFrame = true; - } - - ProgressBar.finish(); - - LoginSM.pushEvent(CLoginStateMachine::ev_enter_game); - - if (_DSSDown) - { - _DSSDown = false; - onDssDown(true); - } -} - -void CFarTP::onFailure() -{ - // Display message - string reason; - if (_Reason) - { - reason += ": " + (*_Reason); - delete _Reason; - _Reason = NULL; - } - else if (noUserChar) - { - reason += ": no characters found!"; - } - Driver->systemMessageBox(("Unable to join shard"+reason).c_str(), "Error", UDriver::okType, UDriver::exclamationIcon); - - // TODO: recover from error - - LoginSM.pushEvent(CLoginStateMachine::ev_quit); -} - -void CFarTP::onDssDown(bool forceReturn) -{ - if (!forceReturn) - { - // If leaving shard, don't bother with DSS "downitude" - if (isLeavingShard()) - return; - // If joining shard, store event and launch it at the end of reconnection - if (isJoiningShard()) - { - _DSSDown = true; // note: still, some cases will make the client hang or abort, e.g. DSS down before the client receives the start pos (in ring shard) - return; - } - } - - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - pIM->messageBoxWithHelp(CI18N::get("uiDisconnected")); - requestReturnToPreviousSession(); -} - -extern bool loginFinished; -void setLoginFinished( bool f ); -extern bool loginOK; - -void CFarTP::joinSessionResult(uint32 /* userId */, TSessionId /* sessionId */, uint32 /* result */, const std::string &/* shardAddr */, const std::string &/* participantStatus */) -{ -// _LastJoinSessionResultMsg = result; -// -// _JoinSessionResultReceived = true; -// -// if (result == 0) -// { -// // ok, the join is successful -// -// FSAddr = shardAddr; -// -// setLoginFinished( true ); -// loginOK = true; -// -// LoginSM.pushEvent(CLoginStateMachine::ev_connect); -// -// } -// else -// { -// // TODO : display the error message on client screen and log -// nlstop; -// } -} - - -void CFarTP::setJoinSessionResult(TSessionId sessionId, const CSecurityCode& securityCode) -{ - _SessionIdToJoinFast = sessionId; - _SecurityCodeForDisconnection = securityCode; -} - -void CFarTP::writeSecurityCodeForDisconnection(NLMISC::IStream& msgout) -{ - CSecurityCheckForFastDisconnection::forwardSecurityCode(msgout, _SessionIdToJoinFast, _SecurityCodeForDisconnection); -} - -// Not run by the cotask but within the main loop -void CFarTP::farTPmainLoop() -{ - ConnectionReadySent = false; - LoginSM.pushEvent(CLoginStateMachine::ev_far_tp_main_loop_entered); - - disconnectFromPreviousShard(); - - uint nbRecoSelectCharReceived = 0; - - bool welcomeWindow = true; - - // Update network until the end of the FarTP process, before resuming the main loop - while (!ConnectionReadySent) - { - // Event server get events - CInputHandlerManager::getInstance()->pumpEventsNoIM(); - - // Update Network. - NetMngr.update(); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - // TODO: resend in case the last datagram sent was lost? -// // check if we can send another dated block -// if (NetMngr.getCurrentServerTick() != serverTick) -// { -// // -// serverTick = NetMngr.getCurrentServerTick(); -// NetMngr.send(serverTick); -// } -// else -// { -// // Send dummy info -// NetMngr.send(); -// } - - if (LoginSM.getCurrentState() == CLoginStateMachine::st_reconnect_select_char) - { - // Far TP part 3.2bis: go to character selection dialog - // This is done outside the co-routine because it may need to co-routine to do an embedded server hop - if ( FarTP.isReselectingChar() ) - { - ++nbRecoSelectCharReceived; - if ( nbRecoSelectCharReceived <= 1 ) - { - ClientCfg.SelectCharacter = -1; // turn off character autoselection - if ( ! FarTP.reselectCharacter() ) // it should not return here in farTPmainLoop() in the same state otherwise this would be called twice - return; - } - else - nlwarning( "Received more than one st_reconnect_select_char event" ); - } - } - else if (LoginSM.getCurrentState() == CLoginStateMachine::st_reconnect_ready) - { - // Don't call sendReady() within the cotask but within the main loop, as it contains - // event/network loops that could trigger a global exit(). - sendReady(); - welcomeWindow = !isReselectingChar(); - } - - // Be nice to the system - nlSleep(100); - } - - // active/desactive welcome window - if(welcomeWindow) - initWelcomeWindow(); -} diff --git a/code/ryzom/client/src/interface_v3/inventory_manager.cpp b/code/ryzom/client/src/interface_v3/inventory_manager.cpp deleted file mode 100644 index 20480dc38..000000000 --- a/code/ryzom/client/src/interface_v3/inventory_manager.cpp +++ /dev/null @@ -1,4049 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010-2019 Winch Gate Property Limited -// -// This source file has been modified by the following contributors: -// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2015-2019 Jan BOON (Kaetemi) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - -#include "stdpch.h" -#include "nel/misc/cdb_leaf.h" -#include "nel/misc/cdb_branch.h" -#include "inventory_manager.h" -#include "interface_manager.h" -#include "bot_chat_page_trade.h" -#include "bot_chat_page_all.h" -#include "nel/gui/group_container.h" -#include "nel/gui/group_menu.h" -#include "nel/misc/cdb_leaf.h" -#include "nel/misc/cdb_branch.h" -#include "list_sheet_base.h" -#include "../net_manager.h" -#include "../user_entity.h" -#include "../global.h" - -#include "nel/misc/algo.h" - -// TODO: remove this ugly dependence -#include "sphrase_manager.h" - -// For handlers -#include "nel/gui/action_handler.h" -#include "nel/gui/group_editbox.h" -#include "dbctrl_sheet.h" - -#include "../sheet_manager.h" -#include "game_share/slot_equipment.h" -#include "game_share/animal_status.h" -#include "game_share/bot_chat_types.h" - -#include "../client_cfg.h" - -#include "../misc.h" - -#ifdef DEBUG_NEW -#define new DEBUG_NEW -#endif - -using namespace std; -using namespace NLMISC; - -extern TSessionId CharacterHomeSessionId; - -extern NLMISC::CLog g_log; -// Context help -extern void contextHelp (const std::string &help); - -CTempInvManager *CTempInvManager::_Instance = NULL; -CInventoryManager *CInventoryManager::_Instance = NULL; - -NLMISC_REGISTER_OBJECT(CViewBase, CDBGroupListSheetBag, std::string, "list_sheet_bag"); -NLMISC_REGISTER_OBJECT(CViewBase, CDBGroupIconListBag, std::string, "list_icon_bag"); -NLMISC_REGISTER_OBJECT(CViewBase, CDBGroupListSheetFilterCLMSlot, std::string, "list_sheet_filter_clm_slot"); -NLMISC_REGISTER_OBJECT(CViewBase, CDBGroupListSheetFilterExchangeable, std::string, "list_sheet_filter_exchangeable"); - -// *************************************************************************** -// db path for all the inventories (without the SERVER: prefix) -const std::string CInventoryManager::InventoryDBs[]= -{ - "INVENTORY:BAG", - // MAX_INVENTORY_ANIMAL - "INVENTORY:PACK_ANIMAL0", - "INVENTORY:PACK_ANIMAL1", - "INVENTORY:PACK_ANIMAL2", - "INVENTORY:PACK_ANIMAL3", - "INVENTORY:PACK_ANIMAL4", - "INVENTORY:PACK_ANIMAL5", - "INVENTORY:PACK_ANIMAL6", - "INVENTORY:TEMP", - "EXCHANGE:GIVE", - "EXCHANGE:RECEIVE", - "TRADING", - "INVENTORY:SHARE", - "GUILD:INVENTORY", - "INVENTORY:ROOM", -}; - -static void dummyCheck() -{ - // if this raise, correct the 2 tables above and below - nlctassert(MAX_INVENTORY_ANIMAL==7); -} - -const uint CInventoryManager::InventoryIndexes[]= -{ - INVENTORIES::bag, - // MAX_INVENTORY_ANIMAL - INVENTORIES::pet_animal1, - INVENTORIES::pet_animal2, - INVENTORIES::pet_animal3, - INVENTORIES::pet_animal4, - INVENTORIES::pet_animal5, - INVENTORIES::pet_animal6, - INVENTORIES::pet_animal7, - INVENTORIES::temporary, - INVENTORIES::exchange, - INVENTORIES::exchange_proposition, - INVENTORIES::trading, - INVENTORIES::reward_sharing, - INVENTORIES::guild, - INVENTORIES::player_room, -}; - -const uint CInventoryManager::NumInventories= sizeof(CInventoryManager::InventoryDBs)/sizeof(CInventoryManager::InventoryDBs[0]); - - -// ************************************************************************************************* -CItemImage::CItemImage() -{ - Sheet = NULL; - Quality = NULL; - Quantity = NULL; - CreateTime = NULL; - Serial = NULL; - UserColor = NULL; - Price = NULL; - Weight= NULL; - NameId= NULL; - InfoVersion= NULL; -} - -// ************************************************************************************************* -void CItemImage::build(CCDBNodeBranch *branch) -{ - if (!branch) return; - Sheet = dynamic_cast(branch->getNode(ICDBNode::CTextId("SHEET"), false)); - Quality = dynamic_cast(branch->getNode(ICDBNode::CTextId("QUALITY"), false)); - Quantity = dynamic_cast(branch->getNode(ICDBNode::CTextId("QUANTITY"), false)); - CreateTime = dynamic_cast(branch->getNode(ICDBNode::CTextId("CREATE_TIME"), false)); - Serial = dynamic_cast(branch->getNode(ICDBNode::CTextId("SERIAL"), false)); - UserColor = dynamic_cast(branch->getNode(ICDBNode::CTextId("USER_COLOR"), false)); - Price = dynamic_cast(branch->getNode(ICDBNode::CTextId("PRICE"), false)); - Weight = dynamic_cast(branch->getNode(ICDBNode::CTextId("WEIGHT"), false)); - NameId = dynamic_cast(branch->getNode(ICDBNode::CTextId("NAMEID"), false)); - InfoVersion= dynamic_cast(branch->getNode(ICDBNode::CTextId("INFO_VERSION"), false)); - ResaleFlag = dynamic_cast(branch->getNode(ICDBNode::CTextId("RESALE_FLAG"), false)); - - // Should always have at least those one:(ie all but Price) - nlassert(Sheet && Quality && Quantity && CreateTime && Serial && UserColor && Weight && NameId && InfoVersion); -} - -uint64 CItemImage::getItemId() const -{ - return ((uint64)getSerial() << 32) | getCreateTime(); -} - -// ************************************************************************************************* -void CItemInfoCache::load(const std::string &filename) -{ - try - { - CIFile f; - if (f.open(filename)) - { - serial(f); - } - } catch(...) - { } -} - -void CItemInfoCache::save(const std::string &filename) -{ - try - { - COFile f; - if (f.open(filename)) - { - serial(f); - } - }catch(...) - { } -} - -void CItemInfoCache::serial(NLMISC::IStream &s) -{ - s.serialCheck(NELID("METI")); - uint ver = 1; - s.serialVersion(ver); - - uint8 byte = 1; - if (s.isReading()) - { - _ItemInfoCacheMap.clear(); - while(true) - { - uint64 key; - - s.serial(byte); - if (byte == 0) - { - break; - } - s.serial(key); - s.serial(_ItemInfoCacheMap[key].CacheCycle); - _ItemInfoCacheMap[key].serial(s); - - // these are not used in item info cache - _ItemInfoCacheMap[key].InfoVersionFromMsg = 0; - _ItemInfoCacheMap[key].InfoVersionFromSlot = 0; - _ItemInfoCacheMap[key].InfoVersionSlotServerWaiting = 0; - } - } - else - { - byte = 1; - TItemInfoCacheMap::iterator it = _ItemInfoCacheMap.begin(); - while (it != _ItemInfoCacheMap.end()) - { - // purge item from cache if not encountered in X save - if (it->second.CacheCycle < 10000) - { - // 'record exists' byte - s.serial(byte); - - // item id (serial << 32 | createTime) - uint64 key = it->first; - s.serial(key); - - uint32 cycle = it->second.CacheCycle+1; - s.serial(cycle); - - // item info - it->second.serial(s); - } - - ++it; - } - // eof of records byte - byte = 0; - s.serial(byte); - } -} - -const CClientItemInfo *CItemInfoCache::getItemInfo(uint32 serial, uint32 createTime) const -{ - if (serial > 0 && createTime > 0) - { - uint64 itemId = ((uint64)serial << 32) | createTime; - return getItemInfo(itemId); - } - - return NULL; -} - -const CClientItemInfo *CItemInfoCache::getItemInfo(uint64 itemId) const -{ - if (itemId > 0) - { - TItemInfoCacheMap::const_iterator it = _ItemInfoCacheMap.find(itemId); - if (it != _ItemInfoCacheMap.end()) - return &(it->second); - } - - return NULL; -} - -void CItemInfoCache::readFromImpulse(uint64 itemId, CItemInfos itemInfo) -{ - if (itemId > 0) - { - _ItemInfoCacheMap[itemId].readFromImpulse(itemInfo); - _ItemInfoCacheMap[itemId].CacheCycle = 0; - } -} - -void CItemInfoCache::debugItemInfoCache() const -{ - nlinfo("ItemInfoCache: %d entries", _ItemInfoCacheMap.size()); - uint count = 0; - for (TItemInfoCacheMap::const_iterator it = _ItemInfoCacheMap.begin(); it != _ItemInfoCacheMap.end(); ++it) - { - uint32 serial = (it->first >> 32) & 0xFFFFFFFF; - uint32 created = it->first & 0xFFFFFFFF; - nlinfo("[%-4d] cacheCycle:%d, serial:%d, createTime:%d", count++, it->second.CacheCycle, serial, created); - } - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - pIM->displaySystemInfo(toString("ItemInfoCache: %d entries written to client.log", _ItemInfoCacheMap.size())); -} - -// ************************************************************************************************* -// CInventoryManager -// ************************************************************************************************* - -// ************************************************************************************************* -CInventoryManager::CInventoryManager() -{ - Money = NULL; - ServerMoney = NULL; - uint i; - for (i = 0; i < MAX_HANDINV_ENTRIES; ++i) - { - Hands[i] = ServerHands[i] = 0; - UIHands[i] = NULL; - } - - for (i = 0; i < MAX_EQUIPINV_ENTRIES; ++i) - { - Equip[i] = ServerEquip[i] = 0; - UIEquip[i] = NULL; - UIEquip2[i] = NULL; - } - - for (i = 0; i < MAX_BAGINV_ENTRIES; i++) - { - BagItemEquipped[i]= false; - } - - _ItemInfoCacheFilename = toString("save/item_infos_%d.cache", CharacterHomeSessionId.asInt()); - _ItemInfoCache.load(_ItemInfoCacheFilename); - - nlctassert(NumInventories== sizeof(InventoryIndexes)/sizeof(InventoryIndexes[0])); -} - -// *************************************************************************** -CInventoryManager::~CInventoryManager() -{ - _ItemInfoCache.save(_ItemInfoCacheFilename); -} - -// ************************************************************************************************* -CInventoryManager *CInventoryManager::getInstance() -{ - if( !_Instance ) - _Instance = new CInventoryManager(); - return _Instance; -} - -// *************************************************************************** -void CInventoryManager::releaseInstance() -{ - if( _Instance ) - delete _Instance; - _Instance = NULL; -} - -// ************************************************************************************************* -CItemImage &CInventoryManager::getBagItem(uint index) -{ - nlassert(index < MAX_BAGINV_ENTRIES); - return Bag[index]; -} - -// ************************************************************************************************* -CItemImage &CInventoryManager::getTempItem(uint index) -{ - nlassert(index < MAX_TEMPINV_ENTRIES); - return TempInv[index]; -} - -// ************************************************************************************************* -CItemImage *CInventoryManager::getHandItem(uint index) -{ - nlassert(index < MAX_HANDINV_ENTRIES); - if (Hands[index] != 0) - return &Bag[Hands[index]-1]; - else - return NULL; -} - -// ************************************************************************************************* -CItemImage *CInventoryManager::getEquipItem(uint index) -{ - nlassert(index < MAX_EQUIPINV_ENTRIES); - if (Equip[index] != 0) - return &Bag[Equip[index]]; - else - return NULL; -} - -// ************************************************************************************************* -CDBCtrlSheet *CInventoryManager::getHandSheet(uint index) -{ - return UIHands[index]; -} - -// ************************************************************************************************* -CDBCtrlSheet *CInventoryManager::getEquipSheet(uint index) -{ - return UIEquip[index]; -} - - -// ************************************************************************************************* -CItemImage &CInventoryManager::getServerBagItem(uint index) -{ - nlassert(index < MAX_BAGINV_ENTRIES); - return ServerBag[index]; -} -const CItemImage &CInventoryManager::getServerBagItem(uint index) const -{ - nlassert(index < MAX_BAGINV_ENTRIES); - return ServerBag[index]; -} - -// ************************************************************************************************* -CItemImage &CInventoryManager::getServerTempItem(uint index) -{ - nlassert(index < MAX_TEMPINV_ENTRIES); - return ServerTempInv[index]; -} -const CItemImage &CInventoryManager::getServerTempItem(uint index) const -{ - nlassert(index < MAX_TEMPINV_ENTRIES); - return ServerTempInv[index]; -} - -// ************************************************************************************************* -CItemImage *CInventoryManager::getServerHandItem(uint index) -{ - nlassert(index < MAX_HANDINV_ENTRIES); - if (ServerHands[index] != 0) - return &ServerBag[ServerHands[index]]; - else - return NULL; -} - -// ************************************************************************************************* -CItemImage *CInventoryManager::getServerEquipItem(uint index) -{ - nlassert(index < MAX_EQUIPINV_ENTRIES); - if (ServerEquip[index] != 0) - return &ServerBag[ServerEquip[index]]; - else - return NULL; -} - -// ************************************************************************************************* -uint64 CInventoryManager::getMoney() const -{ - return Money ? Money->getValue64() : 0; -} - -// ************************************************************************************************* -void CInventoryManager::setMoney(uint64 value) -{ - if (Money) Money->setValue64(value); -} - -// ************************************************************************************************* -uint64 CInventoryManager::getServerMoney() const -{ - return ServerMoney ? ServerMoney->getValue64() : 0; -} - -// ************************************************************************************************* -void CInventoryManager::setServerMoney(uint64 value) -{ - if (ServerMoney) ServerMoney->setValue64(value); -} -// ************************************************************************************************* -void CInventoryManager::init() -{ - CInterfaceManager *im = CInterfaceManager::getInstance(); - // LOCAL DB - initItemArray(LOCAL_INVENTORY ":BAG", Bag, MAX_BAGINV_ENTRIES); - initItemArray(LOCAL_INVENTORY ":TEMP", TempInv, MAX_TEMPINV_ENTRIES); - Money = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":MONEY"); - initIndirection (LOCAL_INVENTORY ":HAND:", Hands, MAX_HANDINV_ENTRIES, true); - initIndirection (LOCAL_INVENTORY ":EQUIP:", Equip, MAX_EQUIPINV_ENTRIES, true); - // Init observers for auto equipment - { - for (uint i = 0; i < MAX_BAGINV_ENTRIES; ++i) - { - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(i) + ":SHEET"); - ICDBNode::CTextId textId; - pNL->addObserver(&_DBBagObs, textId); - } - } - // Init Animals - for(uint i=0;igetDbProp(SERVER_INVENTORY ":MONEY"); - // Init Animals - for(uint i=0;i(CWidgetManager::getInstance()->getElementFromId(CTRL_HAND_RIGHT)); - UIHands[1] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_HAND_LEFT)); - - UIEquip[SLOT_EQUIPMENT::HEADDRESS] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_HEADDRESS)); - UIEquip[SLOT_EQUIPMENT::EARL] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_EARING_LEFT)); - UIEquip[SLOT_EQUIPMENT::EARR] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_EARING_RIGHT)); - UIEquip[SLOT_EQUIPMENT::NECKLACE] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_NECK)); - UIEquip[SLOT_EQUIPMENT::WRISTL] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_BRACELET_LEFT)); - UIEquip[SLOT_EQUIPMENT::WRISTR] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_BRACELET_RIGHT)); - UIEquip[SLOT_EQUIPMENT::FINGERL] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_RING_LEFT)); - UIEquip[SLOT_EQUIPMENT::FINGERR] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_RING_RIGHT)); - UIEquip[SLOT_EQUIPMENT::ANKLEL] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_ANKLET_LEFT)); - UIEquip[SLOT_EQUIPMENT::ANKLER] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWEL_ANKLET_RIGHT)); - - UIEquip[SLOT_EQUIPMENT::HEAD] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMOR_HEAD)); - UIEquip[SLOT_EQUIPMENT::CHEST] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMOR_CHEST)); - UIEquip[SLOT_EQUIPMENT::ARMS] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMOR_ARMS)); - UIEquip[SLOT_EQUIPMENT::FEET] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMOR_FEET)); - UIEquip[SLOT_EQUIPMENT::LEGS] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMOR_LEGS)); - UIEquip[SLOT_EQUIPMENT::HANDS] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMOR_HANDS)); - - UIEquip2[SLOT_EQUIPMENT::HEADDRESS] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_HEADDRESS)); - UIEquip2[SLOT_EQUIPMENT::EARL] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_EARING_LEFT)); - UIEquip2[SLOT_EQUIPMENT::EARR] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_EARING_RIGHT)); - UIEquip2[SLOT_EQUIPMENT::NECKLACE] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_NECK)); - UIEquip2[SLOT_EQUIPMENT::WRISTL] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_BRACELET_LEFT)); - UIEquip2[SLOT_EQUIPMENT::WRISTR] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_BRACELET_RIGHT)); - UIEquip2[SLOT_EQUIPMENT::FINGERL] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_RING_LEFT)); - UIEquip2[SLOT_EQUIPMENT::FINGERR] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_RING_RIGHT)); - UIEquip2[SLOT_EQUIPMENT::ANKLEL] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_ANKLET_LEFT)); - UIEquip2[SLOT_EQUIPMENT::ANKLER] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_JEWL2_ANKLET_RIGHT)); - - UIEquip2[SLOT_EQUIPMENT::HEAD] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMR2_HEAD)); - UIEquip2[SLOT_EQUIPMENT::CHEST] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMR2_CHEST)); - UIEquip2[SLOT_EQUIPMENT::ARMS] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMR2_ARMS)); - UIEquip2[SLOT_EQUIPMENT::FEET] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMR2_FEET)); - UIEquip2[SLOT_EQUIPMENT::LEGS] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMR2_LEGS)); - UIEquip2[SLOT_EQUIPMENT::HANDS] = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_ARMR2_HANDS)); - - - // Init ItemInfoObservers - { - CCDBNodeLeaf *nodeTS; - - nodeTS= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:TRADING:SESSION", false); - if( nodeTS ) - { - ICDBNode::CTextId textId; - nodeTS->addObserver(&_DBTradeInfoObs, textId); - } - - // Init All Version obs - for(uint i=0;igetDbProp("SERVER:" + InventoryDBs[i] + ":" + toString(j) + ":INFO_VERSION", false); - CCDBNodeLeaf *nodeSH= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:" + InventoryDBs[i] + ":" + toString(j) + ":SHEET", false); - if( nodeIV && nodeSH ) - { - ICDBNode::CTextId textIdIV, textIdSH; - nodeIV->addObserver(&_DBInfoSlotVersionObs, textIdIV); - nodeSH->addObserver(&_DBItemSheetObs, textIdSH); - // if current value!=0, simulate a receive item info obs - if(nodeIV->getValue32()) - { - onReceiveItemInfoSlotVersion(nodeIV); - } - } - else - // stop here for this inventory - break; - } - } - } - } -} - -// ************************************************************************************************* -void CInventoryManager::initItemArray(const std::string &dbBranchName, CItemImage *dest, uint numItems) -{ - nlassert(dest); - CInterfaceManager *im = CInterfaceManager::getInstance(); - CCDBNodeBranch *branch = NLGUI::CDBManager::getInstance()->getDbBranch(dbBranchName); - if (!branch) - { - nlwarning("Can't init inventory image from branch %s.", dbBranchName.c_str()); - return; - } - for(uint k = 0; k < numItems; ++k) - { - CCDBNodeBranch *itemBranch = dynamic_cast(branch->getNode((uint16) k)); - if (!itemBranch) - { - nlwarning("Can't retrieve item %d of branch %s", (int) k, dbBranchName.c_str()); - } - else - { - dest[k].build(itemBranch); - } - } -} - -// *************************************************************************** -void CInventoryManager::initIndirection(const std::string &dbbranch, sint32 *indices, sint32 nbIndex, bool putObs) -{ - CInterfaceManager *im = CInterfaceManager::getInstance(); - for (uint i = 0 ; i < (uint)nbIndex; ++i) - { - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(dbbranch + toString(i) + ":INDEX_IN_BAG"); - if (putObs) - { - ICDBNode::CTextId textId; - pNL->addObserver(&_DBEquipObs, textId); - } - if (pNL != NULL) - indices[i] = pNL->getValue32(); - } -} - -// *************************************************************************** -void CInventoryManager::beginDrag(CDBCtrlSheet *pCS, TFrom From) -{ - DNDCurrentItem = pCS; - if (pCS) - CDBCtrlSheet::setCurrSelSheet(pCS); - DNDFrom = From; -} - -// *************************************************************************** -void CInventoryManager::endDrag() -{ - DNDCurrentItem = NULL; - DNDFrom = Nowhere; -} - -// *************************************************************************** -// Used for interface objects which are reference in bag (the getSheet() returns INDEX_IN_BAG) -std::string CInventoryManager::getDBIndexPath(CDBCtrlSheet *pCS) -{ - string sTmp; - uint i; - for (i = 0; i < MAX_HANDINV_ENTRIES; ++i) - { - if (UIHands[i] == pCS) - { - return string(LOCAL_INVENTORY) + ":HAND:" + toString(i); - } - } - - for (i = 0; i < MAX_EQUIPINV_ENTRIES; ++i) - { - if (UIEquip[i] == pCS) - { - return string(LOCAL_INVENTORY) + ":EQUIP:" + toString(i); - } - if (UIEquip2[i] == pCS) - { - return string(LOCAL_INVENTORY) + ":EQUIP:" + toString(i); - } - } - return ""; -} - -// *************************************************************************** -bool CInventoryManager::is2HandItem(uint32 sheetID) -{ - bool result = false; - CEntitySheet *sheet= SheetMngr.get(CSheetId(sheetID)); - if(sheet && sheet->type()== CEntitySheet::ITEM) - { - CItemSheet *item= (CItemSheet*)sheet; - if( item->hasSlot(SLOTTYPE::TWO_HANDS) || item->hasSlot(SLOTTYPE::RIGHT_HAND_EXCLUSIVE) ) - result = true; - } - return result; -} - -// *************************************************************************** -bool CInventoryManager::isMeleeWeaponItem(uint32 sheetID) -{ - bool result = false; - CEntitySheet *sheet= SheetMngr.get(CSheetId(sheetID)); - if(sheet && sheet->type()== CEntitySheet::ITEM) - { - CItemSheet *item= (CItemSheet*)sheet; - if( item->Family == ITEMFAMILY::MELEE_WEAPON ) - result = true; - } - return result; -} - -// *************************************************************************** -bool CInventoryManager::isRangeWeaponItem(uint32 sheetID) -{ - bool result = false; - CEntitySheet *sheet= SheetMngr.get(CSheetId(sheetID)); - if(sheet && sheet->type()== CEntitySheet::ITEM) - { - CItemSheet *item= (CItemSheet*)sheet; - if( item->Family == ITEMFAMILY::RANGE_WEAPON ) - result = true; - } - return result; -} - -// *************************************************************************** -bool CInventoryManager::isDagger(uint32 sheetID) -{ - bool result = false; - CEntitySheet *sheet= SheetMngr.get(CSheetId(sheetID)); - if(sheet && sheet->type()== CEntitySheet::ITEM) - { - CItemSheet *item= (CItemSheet*)sheet; - if( item->ItemType == ITEM_TYPE::DAGGER) - result = true; - } - return result; -} - -// *************************************************************************** -bool CInventoryManager::isSword(uint32 sheetID) -{ - bool result = false; - CEntitySheet *sheet= SheetMngr.get(CSheetId(sheetID)); - if(sheet && sheet->type()== CEntitySheet::ITEM) - { - CItemSheet *item= (CItemSheet*)sheet; - if( item->ItemType == ITEM_TYPE::SWORD) - result = true; - } - return result; -} - -// *************************************************************************** -bool CInventoryManager::isForageToolItem(uint32 sheetID) -{ - bool result = false; - CEntitySheet *sheet= SheetMngr.get(CSheetId(sheetID)); - if(sheet && sheet->type()== CEntitySheet::ITEM) - { - CItemSheet *item= (CItemSheet*)sheet; - if( item->Family == ITEMFAMILY::HARVEST_TOOL ) - result = true; - } - return result; -} - -// *************************************************************************** -uint32 CInventoryManager::getHandItemSheet( bool rightHand ) const -{ - CSheetId item; - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - string dbPropPath = toString("LOCAL:INVENTORY:HAND:%d:INDEX_IN_BAG",rightHand?0:1); - // get the RightHand bag index - sint32 itemSlot= NLGUI::CDBManager::getInstance()->getDbProp(dbPropPath)->getValue32(); - // if something in hand - if(itemSlot>0) - { - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:INVENTORY:BAG:"+toString(itemSlot-1) +":SHEET", false); - if(node) - item= node->getValue32(); - } - return item.asInt(); -} - - -// *************************************************************************** -bool CInventoryManager::isLeftHandItemCompatibleWithRightHandItem(uint32 leftHandSheet, uint32 rightHandSheet, uint32 lastRightHandSheet) -{ - CEntitySheet *pLastRight = SheetMngr.get (CSheetId(lastRightHandSheet)); - if (pLastRight != NULL) - { - if (pLastRight->type() != CEntitySheet::ITEM) return false; - CItemSheet *pIsLastRight = (CItemSheet *)pLastRight; - - // Last item in right hand is a 2 hand item and the new item is nothing (unequip) - if (pIsLastRight->hasSlot(SLOTTYPE::TWO_HANDS) || pIsLastRight->hasSlot(SLOTTYPE::RIGHT_HAND_EXCLUSIVE)) - return false; - } - - if (leftHandSheet == 0) return true; - - CEntitySheet *pLeft = SheetMngr.get (CSheetId(leftHandSheet)); - if (pLeft == NULL) return false; - if (pLeft->type() != CEntitySheet::ITEM) return false; - CItemSheet *pIsLeft = (CItemSheet *)pLeft; - - if ((pIsLeft->Family == ITEMFAMILY::AMMO) && (rightHandSheet == 0)) - return false; - - if ((pIsLeft->ItemType == ITEM_TYPE::DAGGER) && (rightHandSheet == 0)) - return false; - - CEntitySheet *pRight = SheetMngr.get (CSheetId(rightHandSheet)); - if (pRight == NULL) return true; - if (pRight->type() != CEntitySheet::ITEM) return true; - CItemSheet *pIsRight = (CItemSheet *)pRight; - - if (pIsRight->Family == ITEMFAMILY::RANGE_WEAPON) - { - if (pIsLeft->Family == ITEMFAMILY::AMMO) - if (pIsRight->RangeWeapon.Skill == pIsLeft->Ammo.Skill) - return true; - } - - if (pIsLeft->ItemType == ITEM_TYPE::DAGGER) - { - if ((pIsRight->ItemType == ITEM_TYPE::SWORD) || (pIsRight->ItemType == ITEM_TYPE::DAGGER)) - return true; - else - return false; - } - - if (!pIsRight->hasSlot(SLOTTYPE::TWO_HANDS) && !pIsRight->hasSlot(SLOTTYPE::RIGHT_HAND_EXCLUSIVE)) - { - return true; - } - - return false; -} - -// *************************************************************************** -static void grayItem (const std::string &listname, sint32 bagEntryIndex, bool gray) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - IListSheetBase *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(listname)); - - if (pList != NULL) - { - pList->invalidateCoords(); - - for(uint i = 0; i < MAX_BAGINV_ENTRIES; ++i) - { - CDBCtrlSheet *pCS = pList->getSheet(i); - string sTmp = pCS->getSheet(); - sTmp = sTmp.substr(sTmp.rfind(':')+1,sTmp.size()); - sint32 nTmp; - fromString(sTmp, nTmp); - if (nTmp == bagEntryIndex) - pCS->setItemWeared(gray); - } - } -} - -// *************************************************************************** -void CInventoryManager::wearBagItem(sint32 bagEntryIndex) -{ - if(bagEntryIndex>=0 && bagEntryIndex<(sint32)MAX_BAGINV_ENTRIES) - { - BagItemEquipped[bagEntryIndex]= true; - grayItem (LIST_BAG_TEXT, bagEntryIndex, true); - grayItem (LIST_BAG_ICONS, bagEntryIndex, true); - sortBag(); - } -} - -// *************************************************************************** -void CInventoryManager::unwearBagItem(sint32 bagEntryIndex) -{ - if(bagEntryIndex>=0 && bagEntryIndex<(sint32)MAX_BAGINV_ENTRIES) - { - BagItemEquipped[bagEntryIndex]= false; - grayItem (LIST_BAG_TEXT, bagEntryIndex, false); - grayItem (LIST_BAG_ICONS, bagEntryIndex, false); - sortBag(); - } -} - -// *************************************************************************** -bool CInventoryManager::isBagItemWeared(sint32 bagEntryIndex) -{ - if(bagEntryIndex>=0 && bagEntryIndex<(sint32)MAX_BAGINV_ENTRIES) - { - return BagItemEquipped[bagEntryIndex]; - } - - return false; -} - -// ---------------------------------------------------------------------------- -static bool isSwimming() -{ - if (UserEntity != NULL) - return (UserEntity->mode() == MBEHAV::SWIM || UserEntity->mode() == MBEHAV::MOUNT_SWIM); - else - return false; -} - -static bool isRiding() -{ - if (UserEntity) - return UserEntity->isRiding(); - else - return false; -} - -static bool isStunned() -{ - if (UserEntity != NULL) - return (UserEntity->behaviour() == MBEHAV::STUNNED); - else - return false; -} - -static bool isDead() -{ - if (UserEntity != NULL) - return (UserEntity->mode() == MBEHAV::DEATH); - else - return false; -} - -// ---------------------------------------------- -// equip -// -// ---------------------------------------------- -void CInventoryManager::equip(const std::string &bagPath, const std::string &invPath) -{ - if (isSwimming() || isStunned() || isDead() || isRiding()) return; - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - if (bagPath.empty() || invPath.empty()) - { - return; - } - - // Get inventory and slot - string sIndexInBag = bagPath.substr(bagPath.rfind(':')+1,bagPath.size()); - uint16 indexInBag; - fromString(sIndexInBag, indexInBag); - - uint16 inventory = INVENTORIES::UNDEFINED; - uint16 invSlot = 0xffff; - - if (strnicmp(invPath.c_str(),"LOCAL:INVENTORY:HAND",20) == 0) - { - inventory = INVENTORIES::handling; - fromString(invPath.substr(21,invPath.size()), invSlot); - } - else if (strnicmp(invPath.c_str(),"LOCAL:INVENTORY:EQUIP",21) == 0) - { - inventory = INVENTORIES::equipment; - fromString(invPath.substr(22,invPath.size()), invSlot); - } - - // Hands management : check if we have to unequip left hand because of incompatibility with right hand item - sint16 oldRightIndexInBag = NLGUI::CDBManager::getInstance()->getDbProp(invPath + ":INDEX_IN_BAG")->getValue16(); - if (inventory == INVENTORIES::handling && invSlot == 0) - { - CDBCtrlSheet *pCSLeftHand = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_HAND_LEFT)); - if (pCSLeftHand == NULL) - { - return; - } - - // get sheet of left item - uint32 leftSheet = 0; - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":HAND:1:INDEX_IN_BAG", false); - if (pNL == NULL) - { - return; - } - if (pNL->getValue32() > 0) - { - CCDBNodeLeaf *pNL2 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(pNL->getValue32()-1) + ":SHEET", false); - if (pNL2 == NULL) - { - return; - } - leftSheet = pNL2->getValue32(); - } - - // get sheet of previous right hand item - uint32 lastRightSheet = 0; - if (oldRightIndexInBag > 0) - { - pNL = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(oldRightIndexInBag-1) + ":SHEET", false); - if (pNL == NULL) - { - return; - } - lastRightSheet = pNL->getValue32(); - } - - // get sheet of new right hand item - uint32 rightSheet = 0; - if (indexInBag+1 > 0) - { - pNL = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(indexInBag) + ":SHEET", false); - if (pNL == NULL) - { - return; - } - rightSheet = pNL->getValue32(); - } - - // If incompatible -> remove - if (!getInventory().isLeftHandItemCompatibleWithRightHandItem(leftSheet, rightSheet, lastRightSheet)) - { - getInventory().unequip(LOCAL_INVENTORY ":HAND:1"); - } - } - - // update the equip DB pointer - NLGUI::CDBManager::getInstance()->getDbProp(invPath + ":INDEX_IN_BAG")->setValue16(indexInBag+1); - - // Yoyo add: when the user equip an item, the action are invalid during some time - if(indexInBag < MAX_BAGINV_ENTRIES) - { - CItemSheet *pIS= dynamic_cast(SheetMngr.get(CSheetId(getBagItem(indexInBag).getSheetID()))); - if(pIS) - { - CSPhraseManager *pPM= CSPhraseManager::getInstance(); - pPM->setEquipInvalidation(NetMngr.getCurrentServerTick(), pIS->EquipTime); - } - } - - // Update trade window if any - if ((BotChatPageAll != NULL) && (BotChatPageAll->Trade != NULL)) - BotChatPageAll->Trade->invalidateCoords(); - - // Send message to the server - if (inventory != INVENTORIES::UNDEFINED) - { - CBitMemStream out; - const string sMsg = "ITEM:EQUIP"; - if (GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) - { - // Fill the message (equipped inventory, equipped inventory slot, bag slot) - out.serial(inventory); - out.serial(invSlot); - out.serial(indexInBag); - NetMngr.push (out); - - pIM->incLocalSyncActionCounter(); - - //nlinfo("impulseCallBack : %s %d %d %d sent", sMsg.c_str(), inventory, invSlot, indexInBag); - } - else - { - nlwarning ("don't know message name %s", sMsg.c_str()); - } - } -} - - - -// ---------------------------------------------- -// unequip -// -// ---------------------------------------------- -void CInventoryManager::unequip(const std::string &invPath) -{ - if (isSwimming() || isStunned() || isDead() ) return; - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - sint16 oldIndexInBag = NLGUI::CDBManager::getInstance()->getDbProp(invPath + ":INDEX_IN_BAG")->getValue16(); - if( oldIndexInBag == 0 ) - { - return; - } - - // Get inventory and slot - uint16 inventory = INVENTORIES::UNDEFINED; - uint16 invSlot = 0xffff; - - if (strnicmp(invPath.c_str(),"LOCAL:INVENTORY:HAND",20) == 0) - { - inventory = INVENTORIES::handling; - fromString(invPath.substr(21,invPath.size()), invSlot); - } - else if (strnicmp(invPath.c_str(),"LOCAL:INVENTORY:EQUIP",21) == 0) - { - inventory = INVENTORIES::equipment; - fromString(invPath.substr(22,invPath.size()), invSlot); - } - - // Hands management : check if we have to unequip left hand because of incompatibility with right hand item - if (inventory == INVENTORIES::handling && invSlot == 0) - { - CDBCtrlSheet *pCSLeftHand = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_HAND_LEFT)); - if (pCSLeftHand == NULL) - { - return; - } - - // get sheet of left item - uint32 leftSheet = 0; - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":HAND:1:INDEX_IN_BAG", false); - if (pNL == NULL) - { - return; - } - if (pNL->getValue32() > 0) - { - CCDBNodeLeaf *pNL2 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(pNL->getValue32()-1) + ":SHEET", false); - if (pNL2 == NULL) - { - return; - } - leftSheet = pNL2->getValue32(); - } - - // get sheet of previous right hand item - uint32 lastRightSheet = 0; - if (oldIndexInBag > 0) - { - pNL = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(oldIndexInBag-1) + ":SHEET", false); - if (pNL == NULL) - { - return; - } - lastRightSheet = pNL->getValue32(); - } - - // sheet of new right hand item - uint32 rightSheet = 0; - - // If incompatible -> remove - if (!getInventory().isLeftHandItemCompatibleWithRightHandItem(leftSheet, rightSheet, lastRightSheet)) - { - getInventory().unequip(LOCAL_INVENTORY ":HAND:1"); - } - } - - NLGUI::CDBManager::getInstance()->getDbProp(invPath + ":INDEX_IN_BAG")->setValue16(0); - - // Update trade window if any - if ((BotChatPageAll != NULL) && (BotChatPageAll->Trade != NULL)) - BotChatPageAll->Trade->invalidateCoords(); - - // Send message to the server - if (inventory != INVENTORIES::UNDEFINED) - { - CBitMemStream out; - const string sMsg = "ITEM:UNEQUIP"; - if (GenericMsgHeaderMngr.pushNameToStream(sMsg, out)) - { - // Fill the message (equipped inventory, equipped inventory slot) - out.serial(inventory); - out.serial(invSlot); - NetMngr.push (out); - - pIM->incLocalSyncActionCounter(); - - //nlinfo("impulseCallBack : %s %d %d sent", sMsg.c_str(), inventory, invSlot); - } - else - { - nlwarning ("don't know message name %s", sMsg.c_str()); - } - } -} - - -// *************************************************************************** -// Observer on DB equipment branch -// *************************************************************************** -void CInventoryManager::CDBEquipObs::update(ICDBNode* node) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - string sTmp = node->getFullName(); - string sIE, sIE2; // Interface Element - CCDBNodeLeaf *pNL = dynamic_cast(node); - if (pNL == NULL) return; - if (strnicmp(sTmp.c_str(),"LOCAL:INVENTORY:HAND",20) == 0) - { - // Coming from hand - sTmp = sTmp.substr(21,sTmp.size()); - sTmp = sTmp.substr(0,sTmp.rfind(':')); - sint index; - fromString(sTmp, index); - if (index == 0) - sIE = CTRL_HAND_RIGHT; - else - sIE = CTRL_HAND_LEFT; - // update Hands. - getInventory().Hands[index]= pNL->getValue16(); - } - else if (strnicmp(sTmp.c_str(),"LOCAL:INVENTORY:EQUIP",21) == 0) - { - // Coming from equipement - sTmp = sTmp.substr(22,sTmp.size()); - sTmp = sTmp.substr(0,sTmp.rfind(':')); - sint32 nTmp; - fromString(sTmp, nTmp); - SLOT_EQUIPMENT::TSlotEquipment index = (SLOT_EQUIPMENT::TSlotEquipment)nTmp; - switch(index) - { - case SLOT_EQUIPMENT::HEADDRESS: sIE = CTRL_JEWEL_HEADDRESS; - sIE2= CTRL_JEWL2_HEADDRESS; break; - case SLOT_EQUIPMENT::EARL: sIE = CTRL_JEWEL_EARING_LEFT; - sIE2= CTRL_JEWL2_EARING_LEFT; break; - case SLOT_EQUIPMENT::EARR: sIE = CTRL_JEWEL_EARING_RIGHT; - sIE2= CTRL_JEWL2_EARING_RIGHT; break; - case SLOT_EQUIPMENT::NECKLACE: sIE = CTRL_JEWEL_NECK; - sIE2= CTRL_JEWL2_NECK; break; - case SLOT_EQUIPMENT::WRISTL: sIE = CTRL_JEWEL_BRACELET_LEFT; - sIE2= CTRL_JEWL2_BRACELET_LEFT; break; - case SLOT_EQUIPMENT::WRISTR: sIE = CTRL_JEWEL_BRACELET_RIGHT; - sIE2= CTRL_JEWL2_BRACELET_RIGHT; break; - case SLOT_EQUIPMENT::FINGERL: sIE = CTRL_JEWEL_RING_LEFT; - sIE2= CTRL_JEWL2_RING_LEFT; break; - case SLOT_EQUIPMENT::FINGERR: sIE = CTRL_JEWEL_RING_RIGHT; - sIE2= CTRL_JEWL2_RING_RIGHT; break; - case SLOT_EQUIPMENT::ANKLEL: sIE = CTRL_JEWEL_ANKLET_LEFT; - sIE2= CTRL_JEWL2_ANKLET_LEFT; break; - case SLOT_EQUIPMENT::ANKLER: sIE = CTRL_JEWEL_ANKLET_RIGHT; - sIE2= CTRL_JEWL2_ANKLET_RIGHT; break; - - case SLOT_EQUIPMENT::HEAD: sIE = CTRL_ARMOR_HEAD; - sIE2= CTRL_ARMR2_HEAD; break; - case SLOT_EQUIPMENT::CHEST: sIE = CTRL_ARMOR_CHEST; - sIE2= CTRL_ARMR2_CHEST; break; - case SLOT_EQUIPMENT::ARMS: sIE = CTRL_ARMOR_ARMS; - sIE2= CTRL_ARMR2_ARMS; break; - case SLOT_EQUIPMENT::FEET: sIE = CTRL_ARMOR_FEET; - sIE2= CTRL_ARMR2_FEET; break; - case SLOT_EQUIPMENT::LEGS: sIE = CTRL_ARMOR_LEGS; - sIE2= CTRL_ARMR2_LEGS; break; - case SLOT_EQUIPMENT::HANDS: sIE = CTRL_ARMOR_HANDS; - sIE2= CTRL_ARMR2_HANDS; break; - - default: - nlwarning("entry not handled"); - return; - break; - } - // update Equips. - getInventory().Equip[index]= pNL->getValue16(); - } - else return; - - // Set database for wearing the right item - CDBCtrlSheet *pCS = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(sIE)); - CDBCtrlSheet *pCS2 = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(sIE2)); - - // Remove Last reference and update database - sint16 oldVal = pNL->getOldValue16(); - sint16 newVal = pNL->getValue16(); - if (oldVal != 0) - getInventory().unwearBagItem (oldVal-1); - - if (newVal != 0) - getInventory().wearBagItem (newVal-1); - - // Update Display - if (newVal == 0) - { - // in some case left sheet is same than right sheet so don't clear it now (ex: 2 hands item, right hand exclusive) - if (sIE != CTRL_HAND_LEFT) - { - if (pCS != NULL) pCS->setSheet(""); - if (pCS2 != NULL) pCS2->setSheet(""); - } - } - else - { - if (pCS != NULL) pCS->setSheet(LOCAL_INVENTORY ":BAG:"+ toString(newVal-1)); - if (pCS2 != NULL) pCS2->setSheet(LOCAL_INVENTORY ":BAG:"+ toString(newVal-1)); - } - - // Hands management - if (sIE == CTRL_HAND_RIGHT) - { - // if nothing in left hand -> return - CDBCtrlSheet *pCSLeftHand = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_HAND_LEFT)); - if (pCSLeftHand == NULL) - { - return; - } - - // reset display of left hand - CViewRenderer &rVR = *CViewRenderer::getInstance(); - pCSLeftHand->setTextureNoItem(rVR.getTextureIdFromName("hand_left.tga")); - pCSLeftHand->setGrayed(false); - pCSLeftHand->setItemSlot(SLOTTYPE::stringToSlotType("LEFT_HAND")); - pCSLeftHand->setActionOnLeftClick("proc"); - - // If something in left hand check if we have to remove - { - uint32 leftSheet = 0; - CCDBNodeLeaf *pNL3 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":HAND:1:INDEX_IN_BAG", false); - if (pNL3 == NULL) return; - if (pNL3->getValue32() > 0) - { - CCDBNodeLeaf *pNL4 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(pNL3->getValue32()-1) + ":SHEET", false); - if (pNL4 == NULL) return; - leftSheet = pNL4->getValue32(); - } - - uint32 rightSheet = 0; - if (newVal > 0) - { - pNL3 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(newVal-1) + ":SHEET", false); - if (pNL3 == NULL) return; - rightSheet = pNL3->getValue32(); - } - - uint32 lastRightSheet = 0; - if (oldVal > 0) - { - pNL3 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(oldVal-1) + ":SHEET", false); - if (pNL3 == NULL) return; - lastRightSheet = pNL3->getValue32(); - } - - // If incompatible -> remove - if (!getInventory().isLeftHandItemCompatibleWithRightHandItem(leftSheet, rightSheet, lastRightSheet)) - { - pCSLeftHand->setSheet(""); - } - // WORKAROUND: useful when an item is destroyed before it is unequipped (clean the left hand) - if ((leftSheet == 0) && (rightSheet == 0)) - { - pCSLeftHand->setSheet(""); - } - } - - // update display of left hand according to new right hand item - if (newVal > 0) - { - CCDBNodeLeaf *pNL2 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(newVal-1) + ":SHEET", false); - if (pNL2 == NULL) return; - - if (getInventory().is2HandItem(pNL2->getValue32())) - { - if (getInventory().isRangeWeaponItem(pNL2->getValue32())) - { - pCSLeftHand->setItemSlot(SLOTTYPE::stringToSlotType("AMMO")); - pCSLeftHand->setTextureNoItem(rVR.getTextureIdFromName("W_AM_logo.tga")); - } - else - { - pCSLeftHand->setSheet(LOCAL_INVENTORY ":BAG:"+ toString(newVal-1)); - pCSLeftHand->setGrayed(true); - pCSLeftHand->setActionOnLeftClick(""); - } - } - } - } - - // left hand item is changing - if (sIE == CTRL_HAND_LEFT) - { - CDBCtrlSheet *pCSLeftHand = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_HAND_LEFT)); - if ( pCSLeftHand ) - { - CViewRenderer &rVR = *CViewRenderer::getInstance(); - pCSLeftHand->setActionOnLeftClick("proc"); - pCSLeftHand->setGrayed(false); - - // if now there is nothing in left hand - if (newVal == 0) - { - // check if we clear display (have to manage 2 hands weapons for instance) - bool clearLeftHandDisplay = true; - CDBCtrlSheet * pCSRightHand = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_HAND_RIGHT)); - if ( pCSRightHand && pCSRightHand->getSheetId() ) - { - CCDBNodeLeaf *pNL3 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":HAND:0:INDEX_IN_BAG", false); - if (pNL3) - { - if (pNL3->getValue32() > 0) - { - CCDBNodeLeaf *pNL4 = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":BAG:" + toString(pNL3->getValue32()-1) + ":SHEET", false); - if (pNL4) - { - uint32 rightSheet = pNL4->getValue32(); - if (getInventory().is2HandItem(rightSheet)) - { - if (getInventory().isRangeWeaponItem(rightSheet)) - { - pCSLeftHand->setItemSlot(SLOTTYPE::stringToSlotType("AMMO")); - pCSLeftHand->setTextureNoItem(rVR.getTextureIdFromName("W_AM_logo.tga")); - } - else - { - pCSLeftHand->setItemSlot(SLOTTYPE::stringToSlotType("LEFT_HAND")); - pCSLeftHand->setTextureNoItem(rVR.getTextureIdFromName("hand_left.tga")); - clearLeftHandDisplay = false; - } - } - } - } - } - } - if(clearLeftHandDisplay) - { - if (pCS != NULL) pCS->setSheet(""); - if (pCS2 != NULL) pCS2->setSheet(""); - } - } - } - } -} - -// *************************************************************************** -void CInventoryManager::CDBBagObs::update(ICDBNode* /* node */) -{ - if (IngameDbMngr.initInProgress()) return; - - getInventory().checkIndexInBagIntegrity(); - - // AUTO EQUIP the player with incoming item if we can put this item in an equipment slot - - // if we are not initializing the DB -/* - CCDBNodeLeaf *pNL = dynamic_cast(node); - if (pNL != NULL) - if (pNL->getValue32() == 0) - return; - - if (IngameDbMngr.initInProgress()) return; - - sint bagEntryIndex; - - string path = node->getFullName(); - path = path.substr(0,path.rfind(':')); - path = path.substr(path.rfind(':')+1,path.size()); - - fromString(path, bagEntryIndex); - // equip only if slot empty - getInventory().autoEquip(bagEntryIndex, false); -*/ -} - -// *************************************************************************** -bool CInventoryManager::autoEquip(sint bagEntryIndex, bool allowReplace) -{ - uint i; - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - IListSheetBase *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_BAG_TEXT)); - CDBCtrlSheet *pCSSrc = NULL; - - if (pList == NULL) return false; - - for (i = 0; i < MAX_BAGINV_ENTRIES; ++i) - { - pCSSrc = pList->getSheet(i); - string sTmp = pCSSrc->getSheet(); - sTmp = sTmp.substr(sTmp.rfind(':')+1,sTmp.size()); - sint nTmp; - fromString(sTmp, nTmp); - if (nTmp == bagEntryIndex) - break; - } - - if (i == MAX_BAGINV_ENTRIES) return false; - if (pCSSrc == NULL) return false; - - for (i = 0; i < MAX_HANDINV_ENTRIES; ++i) - { - CDBCtrlSheet *pCSDst = getInventory().getHandSheet(i); - if (pCSDst == NULL) continue; - string dstPath = getInventory().getDBIndexPath(pCSDst); - - sint32 indexDstPath = NLGUI::CDBManager::getInstance()->getDbProp(dstPath+":INDEX_IN_BAG")->getValue16(); - - // Already something in that slot? - if (!allowReplace && indexDstPath > 0) - continue; - - // Does the source and destination are items ? - if (pCSSrc->getType() == CCtrlSheetInfo::SheetType_Item) - if (pCSDst->getType() == CCtrlSheetInfo::SheetType_Item) - { - // Right Slot ? - if (pCSDst->canDropItem(pCSSrc)) - { - // Ok let us equip with this item - string srcPath = pCSSrc->getSheet(); - getInventory().equip (srcPath, dstPath); - return true; - } - } - } - - for (i = 0; i < MAX_EQUIPINV_ENTRIES; ++i) - { - CDBCtrlSheet *pCSDst = getInventory().getEquipSheet(i); - if (pCSDst == NULL) continue; - string dstPath = getInventory().getDBIndexPath(pCSDst); - sint32 indexDstPath = NLGUI::CDBManager::getInstance()->getDbProp(dstPath+":INDEX_IN_BAG")->getValue16(); - - // Already something in that slot? - if (!allowReplace && indexDstPath > 0) - continue; - - // Does the source and destination are items ? - if (pCSSrc->getType() == CCtrlSheetInfo::SheetType_Item) - if (pCSDst->getType() == CCtrlSheetInfo::SheetType_Item) - { - // Right Slot ? - if (pCSDst->canDropItem(pCSSrc)) - { - // Ok let us equip with this item - string srcPath = pCSSrc->getSheet(); - getInventory().equip (srcPath, dstPath); - return true; - } - } - } - return false; -} - -// *************************************************************************** -void CInventoryManager::dropOrDestroyItem(CDBCtrlSheet *item, CBitMemStream &out, uint16 quantity) -{ - if (!item) return; - uint16 inventory = (uint16) item->getInventoryIndex(); - // retrieve inventory & slot - uint16 slot = (uint16) item->getIndexInDB(); - out.serial(inventory); - out.serial(slot); - out.serial(quantity); - NetMngr.push(out); -} - -// *************************************************************************** -static void checkEquipmentIntegrity(const string &equipVal) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(equipVal+":INDEX_IN_BAG",false); - if (pNL != NULL) - { - uint32 indexInBag = pNL->getValue16(); - if (indexInBag != 0) - { - string sTmp = string(LOCAL_INVENTORY) + ":BAG:" + toString(indexInBag-1) + ":SHEET"; - CCDBNodeLeaf *pNLBag = NLGUI::CDBManager::getInstance()->getDbProp(sTmp,false); - if (pNLBag != NULL) - { - if (pNLBag->getValue32() == 0) // If no more item in this slot bag - { -// if (! IngameDbMngr.initInProgress()) // Commented because init is end when we received equipment -// pNL->setValue16(0); // Reset INDEX_IN_BAG - } - else - { - // If the slot was previously empty check that there is no reference on it - // else update the reference - if (pNLBag->getOldValue32() == 0) - { - for (uint32 i = 0; i < MAX_EQUIPINV_ENTRIES; ++i) - { - CDBCtrlSheet *pCSDst = getInventory().getEquipSheet(i); - if (pCSDst == NULL) continue; - string dstPath = getInventory().getDBIndexPath(pCSDst); - sint32 indexDstPath = NLGUI::CDBManager::getInstance()->getDbProp(dstPath+":INDEX_IN_BAG")->getValue16(); - - // Update the sheet id of the control sheet - if (indexDstPath == (sint32)indexInBag) - { - pCSDst->setSheetId(pNLBag->getValue32()); - } - } - } - } - } - } - } -} - -// *************************************************************************** -void CInventoryManager::checkIndexInBagIntegrity() -{ - string sTmp; - uint32 i; - - for (i = 0; i < MAX_HANDINV_ENTRIES; ++i) - { - sTmp = string(LOCAL_INVENTORY) + ":HAND:" + toString(i); - checkEquipmentIntegrity(sTmp); - } - - for (i = 0; i < MAX_EQUIPINV_ENTRIES; ++i) - { - sTmp = string(LOCAL_INVENTORY) + ":EQUIP:" + toString(i); - checkEquipmentIntegrity(sTmp); - } -} - -// *************************************************************************** -double CInventoryManager::getBranchBulk(const string &basePath, uint16 startItemIndex, uint16 numItems) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CCDBNodeBranch *branch = NLGUI::CDBManager::getInstance()->getDbBranch(basePath); - if (!branch) - { - nlwarning(" Branch is NULL"); - return 0; - } - - double totalBulk = 0; - // - uint16 lastIndexItem = std::min((uint16) (startItemIndex + numItems), (uint16) branch->getNbNodes()); - for (uint16 currItem = startItemIndex; currItem < lastIndexItem; ++ currItem) - { - ICDBNode *node = branch->getNode(currItem); - if (node) - { - CCDBNodeLeaf *sheetNode = dynamic_cast(node->getNode(ICDBNode::CTextId("SHEET"))); - CCDBNodeLeaf *quantityNode = dynamic_cast(node->getNode(ICDBNode::CTextId("QUANTITY"))); - if (sheetNode && quantityNode) - { - // get the Sheet - CSheetId sheetId = CSheetId(sheetNode->getValue32()); - if (sheetId != CSheetId::Unknown) - { - CItemSheet *itemSheet= dynamic_cast(SheetMngr.get(sheetId)); - if(itemSheet) - { - totalBulk += std::max((sint32)1, quantityNode->getValue32()) * itemSheet->Bulk; - } - } - } - } - } - - return totalBulk; -} - -/* - *Get the number of used and max slots - */ -void CInventoryManager::getBranchSlotCounts(const std::string &basePath, uint& nbUsedSlots, uint& nbMaxSlots ) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CCDBNodeBranch *branch = NLGUI::CDBManager::getInstance()->getDbBranch(basePath); - if (!branch) - { - nlwarning(" Branch is NULL"); - return; - } - - nbMaxSlots = 0; // different from nbNodes, because there can be non-slots leaves (e.g. guild money...) - nbUsedSlots = 0; - uint nbNodes = branch->getNbNodes(); - for ( uint i=0; i!=nbNodes; ++i ) - { - ICDBNode *node = branch->getNode(i); - if (node) - { - CCDBNodeLeaf *sheetNode = dynamic_cast(node->getNode(ICDBNode::CTextId("SHEET"))); - if (sheetNode) - { - // Get the Sheet - CSheetId sheetId = CSheetId(sheetNode->getValue32()); - if (sheetId != CSheetId::Unknown) - { - ++nbUsedSlots; - } - - ++nbMaxSlots; - } - } - } -} - - -// *************************************************************************** -double CInventoryManager::getBagBulk(uint32 inventoryIndex) -{ - nlctassert(MAX_INVENTORY_ANIMAL==7); - if (inventoryIndex == 0) - return getBranchBulk(LOCAL_INVENTORY ":BAG", 0, MAX_BAGINV_ENTRIES); - else if (inventoryIndex == 1) - return getBranchBulk(LOCAL_INVENTORY ":PACK_ANIMAL0", 0, MAX_ANIMALINV_ENTRIES); - else if (inventoryIndex == 2) - return getBranchBulk(LOCAL_INVENTORY ":PACK_ANIMAL1", 0, MAX_ANIMALINV_ENTRIES); - else if (inventoryIndex == 3) - return getBranchBulk(LOCAL_INVENTORY ":PACK_ANIMAL2", 0, MAX_ANIMALINV_ENTRIES); - else if (inventoryIndex == 4) - return getBranchBulk(LOCAL_INVENTORY ":PACK_ANIMAL3", 0, MAX_ANIMALINV_ENTRIES); - else if (inventoryIndex == 5) - return getBranchBulk(LOCAL_INVENTORY ":PACK_ANIMAL4", 0, MAX_ANIMALINV_ENTRIES); - else if (inventoryIndex == 6) - return getBranchBulk(LOCAL_INVENTORY ":PACK_ANIMAL5", 0, MAX_ANIMALINV_ENTRIES); - else if (inventoryIndex == 7) - return getBranchBulk(LOCAL_INVENTORY ":PACK_ANIMAL6", 0, MAX_ANIMALINV_ENTRIES); - else if (inventoryIndex == 8) - return 0; - else if (inventoryIndex == 9) - return 0; - else if (inventoryIndex == 10) - return getBranchBulk(LOCAL_INVENTORY ":TEMP", 0, MAX_TEMPINV_ENTRIES); - return 0; -} - -// *************************************************************************** -double CInventoryManager::getItemBulk(uint32 sheetID) -{ - CItemSheet *itemSheet= dynamic_cast(SheetMngr.get(CSheetId(sheetID))); - if(itemSheet) - return itemSheet->Bulk; - return 0; -} - -// *************************************************************************** -double CInventoryManager::getMaxBagBulk(uint32 inventoryIndex) -{ - nlctassert(MAX_INVENTORY_ANIMAL==7); - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CCDBNodeLeaf *pNL=NULL; - if (inventoryIndex == 0) - pNL = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:STATIC_DATA:BAG_BULK_MAX"); - else if (inventoryIndex == 1) - pNL = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:PACK_ANIMAL:BEAST0:BULK_MAX"); - else if (inventoryIndex == 2) - pNL = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:PACK_ANIMAL:BEAST1:BULK_MAX"); - else if (inventoryIndex == 3) - pNL = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:PACK_ANIMAL:BEAST2:BULK_MAX"); - else if (inventoryIndex == 4) - pNL = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:PACK_ANIMAL:BEAST3:BULK_MAX"); - else if (inventoryIndex == 5) - pNL = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:PACK_ANIMAL:BEAST4:BULK_MAX"); - else if (inventoryIndex == 6) - pNL = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:PACK_ANIMAL:BEAST5:BULK_MAX"); - else if (inventoryIndex == 7) - pNL = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:PACK_ANIMAL:BEAST6:BULK_MAX"); - if (pNL != NULL) - return pNL->getValue32(); - return 0; -} - -// *************************************************************************** -bool CInventoryManager::isSpaceInAllBagsForItem(CDBCtrlSheet *item) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CDBCtrlSheet *pCSDst = item; - if (!pCSDst->isSheetValid()) return false; - string sTmp = pCSDst->getSheet(); - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sTmp+":SHEET",false); - CCDBNodeLeaf *pNLquantity = NLGUI::CDBManager::getInstance()->getDbProp(sTmp+":QUANTITY",false); - if (pNL == NULL) return false; - if (pNLquantity == NULL) return false; - - // Check if we can find empty space for this item (or stack of item) - // in all of the bags that the player owe. - - CInventoryManager *pInv = CInventoryManager::getInstance(); - uint32 quantity = pNLquantity->getValue32(); - double totalBulk = quantity * pInv->getItemBulk(pNL->getValue32()); -// bool bPlaceFound = false; - for (uint32 i = 0; i < 7; ++i) - { - if (pInv->isInventoryAvailable((INVENTORIES::TInventory)CInventoryManager::InventoryIndexes[i])) - if ((pInv->getBagBulk(i) + totalBulk) <= pInv->getMaxBagBulk(i)) - return true; - } - return false; -} - -// *************************************************************************** -bool CInventoryManager::isSpaceInBagForItem(CDBCtrlSheet *item, uint32 quantity, uint32 bagId) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CDBCtrlSheet *pCSDst = item; - if (!pCSDst->isSheetValid()) return false; - string sTmp = pCSDst->getSheet(); - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sTmp+":SHEET",false); - if (pNL == NULL) return false; - - // Check if we can find empty space for this item (or stack of item) - // in a given bag that the player owe. - - CInventoryManager *pInv = CInventoryManager::getInstance(); - double totalBulk = quantity * pInv->getItemBulk(pNL->getValue32()); - if (pInv->isInventoryAvailable((INVENTORIES::TInventory)CInventoryManager::InventoryIndexes[bagId])) - if ((pInv->getBagBulk(bagId) + totalBulk) <= pInv->getMaxBagBulk(bagId)) - return true; - return false; -} - - -// *************************************************************************** -// CTempInvManager -// *************************************************************************** - -// Observers on DB -// *************************************************************************** -void CTempInvManager::CDBObs::update(ICDBNode* /* node */) -{ - CTempInvManager::getInstance()->update(); -} - -void CTempInvManager::CDBObsType::update(ICDBNode* /* node */) -{ - CTempInvManager::getInstance()->updateType(); -} - -void CTempInvManager::CDBForageQQObs::update(ICDBNode* /* node */) -{ - CTempInvManager::getInstance()->updateForageQQ( WhichOne ); -} - -// *************************************************************************** -CTempInvManager::CTempInvManager() -{ - _Mode = TEMP_INV_MODE::Unknown; - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - string sPath = string("LOCAL:INVENTORY:TEMP"); - for (uint i = 0; i < MAX_TEMPINV_ENTRIES; ++i) - { - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sPath+":"+toString(i)+":SHEET", false); - if (pNL != NULL) - { - ICDBNode::CTextId textId; - pNL->addObserver(&_DBObs, textId); - } - } - // Add Also the Mode to observe - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sPath+":TYPE", false); - if(pNL) - { - ICDBNode::CTextId textId; - pNL->addObserver(&_DBObsType, textId); - } - - // Forage - pNL = NLGUI::CDBManager::getInstance()->getDbProp(sPath+":ENABLE_TAKE"); - if (pNL != NULL) - { - ICDBNode::CTextId textId; - pNL->addObserver(&_DBObs, textId); - } - pNL = NLGUI::CDBManager::getInstance()->getDbProp(sPath+":0:QUANTITY"); - _DBForageQQObs[0].WhichOne = 0; - if (pNL != NULL) - { - ICDBNode::CTextId textId; - pNL->addObserver(&_DBForageQQObs[0], textId); - } - pNL = NLGUI::CDBManager::getInstance()->getDbProp(sPath+":0:QUALITY"); - _DBForageQQObs[1].WhichOne = 1; - if (pNL != NULL) - { - ICDBNode::CTextId textId; - pNL->addObserver(&_DBForageQQObs[1], textId); - } -} - -// *************************************************************************** -CTempInvManager::~CTempInvManager() -{ -} - -// *************************************************************************** -void CTempInvManager::releaseInstance() -{ - if( _Instance ) - delete _Instance; - _Instance = NULL; -} - -// *************************************************************************** -void CTempInvManager::update() -{ - bool bAllEmpty = true; - // Check the database state - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - string sPath = string("LOCAL:INVENTORY:TEMP"); - for (uint i = 0; i < MAX_TEMPINV_ENTRIES; i++) - { - string sTmp = sPath + ":" + toString(i) + ":SHEET"; - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sTmp); -// uint32 nOldSheet = pNL->getOldValue32(); - uint32 nSheet = pNL->getValue32(); - if (nSheet != 0) - bAllEmpty = false; - } - - _Mode = (TEMP_INV_MODE::TInventoryMode)NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:INVENTORY:TEMP:TYPE")->getValue8(); - - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(WIN_TEMPINV)); - if (pGC == NULL) - return; - - // show/hide weight info depending on temp inventory mode - bool displayWeight = (_Mode == TEMP_INV_MODE::Craft); - CViewBase *weightText = dynamic_cast(pGC->getView("weight_txt")); - if (weightText != NULL) - weightText->setActive(displayWeight); - CViewBase *weightImg = dynamic_cast(pGC->getView("weight")); - if (weightImg != NULL) - weightImg->setActive(displayWeight); - - if (_Mode == TEMP_INV_MODE::Forage) - { - // Disable/enable "Take all" button - bool disableTake = (NLGUI::CDBManager::getInstance()->getDbProp(sPath+":ENABLE_TAKE")->getValue32() == 0); - NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP_INV:ALL_EMPTY")->setValue32(disableTake); - if ( disableTake ) - { - // Display begin of forage - pGC->setTitle( WIN_TEMPINV_TITLE_WAIT_FORAGING ); - _DBForageQQObs[0].FullValue = 0.0f; - _DBForageQQObs[1].FullValue = 0.0f; - } - else - { - // Display forage result - pGC->setTitle( WIN_TEMPINV_TITLE_FORAGE_RESULT ); - } - } - else - { - // Write to the UI db the empty state - NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP_INV:ALL_EMPTY")->setValue32(bAllEmpty); - } - - if (bAllEmpty) - { - // If all slots are empty, close the interface - pGC->setActive(false); - CAHManager::getInstance()->runActionHandler("phrase_update_all_memory_ctrl_regen_tick_range", NULL); - } - else - { - pGC->setActive(true); - CAHManager::getInstance()->runActionHandler("phrase_update_all_memory_ctrl_regen_tick_range", NULL); - // Something arrived, change text - switch(_Mode) - { - case TEMP_INV_MODE::Loot: pGC->setTitle(WIN_TEMPINV_TITLE_LOOT); break; - case TEMP_INV_MODE::Quarter: pGC->setTitle(WIN_TEMPINV_TITLE_QUARTERING); break; - case TEMP_INV_MODE::Forage: /* see above */ break; - case TEMP_INV_MODE::BagFull: pGC->setTitle(WIN_TEMPINV_TITLE_BAGFULL); break; - case TEMP_INV_MODE::Craft: pGC->setTitle(WIN_TEMPINV_TITLE_CRAFT); break; - case TEMP_INV_MODE::MissionReward: pGC->setTitle(WIN_TEMPINV_TITLE_MISSIONREWARD); break; - case TEMP_INV_MODE::Crystallize: pGC->setTitle(WIN_TEMPINV_TITLE_CRYSTALLIZE); break; - - case TEMP_INV_MODE::Unknown: - default: pGC->setTitle(WIN_TEMPINV_TITLE_ERROR); break; - } - } -} - -// *************************************************************************** -void CTempInvManager::updateType() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - _Mode = (TEMP_INV_MODE::TInventoryMode)NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:INVENTORY:TEMP:TYPE")->getValue8(); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(WIN_TEMPINV)); - // Something arrived, change text - switch(_Mode) - { - case TEMP_INV_MODE::Loot: pGC->setTitle(WIN_TEMPINV_TITLE_LOOT); break; - case TEMP_INV_MODE::Quarter: pGC->setTitle(WIN_TEMPINV_TITLE_QUARTERING); break; - case TEMP_INV_MODE::Forage: /* see above */ break; - case TEMP_INV_MODE::BagFull: pGC->setTitle(WIN_TEMPINV_TITLE_BAGFULL); break; - case TEMP_INV_MODE::Craft: pGC->setTitle(WIN_TEMPINV_TITLE_CRAFT); break; - case TEMP_INV_MODE::MissionReward: pGC->setTitle(WIN_TEMPINV_TITLE_MISSIONREWARD); break; - case TEMP_INV_MODE::Crystallize: pGC->setTitle(WIN_TEMPINV_TITLE_CRYSTALLIZE); break; - - case TEMP_INV_MODE::Unknown: - default: /*pGC->setTitle(WIN_TEMPINV_TITLE_ERROR);*/ // do not overwrite a locally-set title with the default one when ServerAutoCopy syncs the local db during 'make item' (craft) - break; - } -} - -// *************************************************************************** -// Called when INVENTORY:TEMP:0:QUANTITY or INVENTORY:TEMP:0:QUALITY is modified -// Reacts only if mode is Forage -void CTempInvManager::updateForageQQ( uint whichOne ) -{ - if ( _Mode != TEMP_INV_MODE::Forage ) - return; - - // Avoid recursion, because we can't call CCDBNodeLeaf::setValue16() without calling observers! - static bool isInUpdateForageQQ = false; - if ( isInUpdateForageQQ ) - return; - isInUpdateForageQQ = true; - - // Display forage progress with counters - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - bool disableTake = (NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:INVENTORY:TEMP:ENABLE_TAKE")->getValue32() == 0); - if ( disableTake ) - { - float qt = 0.f, ql = 0.f; - switch ( whichOne ) - { - case 0: - { - CCDBNodeLeaf *leafQt = NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:INVENTORY:TEMP:0:QUANTITY"); - uint16 qtX10 = (uint16)(leafQt->getValue16()); - qt = _DBForageQQObs[whichOne].FullValue = (((float)(uint)qtX10) / 10.0f); - leafQt->setValue16( (sint16)(sint)qt ); - ql = _DBForageQQObs[1-whichOne].FullValue; - } - break; - case 1: - { - CCDBNodeLeaf *leafQl = NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:INVENTORY:TEMP:0:QUALITY"); - uint16 qlX10 = (uint16)(leafQl->getValue16()); - ql = _DBForageQQObs[whichOne].FullValue = (((float)(uint)qlX10) / 10.0f); - leafQl->setValue16( (sint16)(sint)ql ); - qt = _DBForageQQObs[1-whichOne].FullValue; - } - break; - default:; - } - ucstring title = CI18N::get( WIN_TEMPINV_TITLE_FORAGING ); - strFindReplace( title, "%qt", toString( "%.1f", qt ) ); - strFindReplace( title, "%ql", toString( "%.1f", ql ) ); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(WIN_TEMPINV)); - pGC->setUCTitle( title ); - } - - isInUpdateForageQQ = false; -} - -// *************************************************************************** -void CTempInvManager::open(TEMP_INV_MODE::TInventoryMode m) -{ - _Mode = m; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(WIN_TEMPINV)); - - // In Foraging mode, we can call open() on the inventory with the same contents (e.g. when changing Forage action) - if ( _Mode != TEMP_INV_MODE::Forage ) - { - string sPath = string("LOCAL:INVENTORY:TEMP"); - for (uint i = 0; i < MAX_TEMPINV_ENTRIES; i++) - { - string sTmp = sPath + ":" + toString(i) + ":SHEET"; - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sTmp); - pNL->setValue32(0); - } - } - NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:INVENTORY:TEMP:TYPE")->setValue8((uint8)_Mode); - - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - if (pGC != NULL) - { - switch(_Mode) - { - case TEMP_INV_MODE::Loot: pGC->setTitle(WIN_TEMPINV_TITLE_WAIT_LOOT); break; - case TEMP_INV_MODE::Quarter: pGC->setTitle(WIN_TEMPINV_TITLE_WAIT_QUARTERING); break; - case TEMP_INV_MODE::Forage: pGC->setTitle(WIN_TEMPINV_TITLE_WAIT_FORAGING); break; - case TEMP_INV_MODE::BagFull: pGC->setTitle(WIN_TEMPINV_TITLE_WAIT_BAGFULL); break; - case TEMP_INV_MODE::Craft: pGC->setTitle(WIN_TEMPINV_TITLE_WAIT_CRAFT); break; - case TEMP_INV_MODE::MissionReward: pGC->setTitle(WIN_TEMPINV_TITLE_WAIT_MISSIONREWARD); break; - case TEMP_INV_MODE::Crystallize: pGC->setTitle(WIN_TEMPINV_TITLE_WAIT_CRYSTALLIZE); break; - - case TEMP_INV_MODE::Unknown: - default: pGC->setTitle(WIN_TEMPINV_TITLE_WAIT_ERROR); break; - }; - - pGC->setActive(true); - CAHManager::getInstance()->runActionHandler("phrase_update_all_memory_ctrl_regen_tick_range", NULL); - } -} - -// *************************************************************************** -void CTempInvManager::close() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - string sPath = string("LOCAL:INVENTORY:TEMP"); - - // Clear temp inventory if needed - for (uint i = 0; i < MAX_TEMPINV_ENTRIES; i++) - { - string sTmp = sPath + ":" + toString(i) + ":SHEET"; - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sTmp); - pNL->setValue32(0); - } - - CInterfaceGroup *pIG = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(WIN_TEMPINV)); - if (pIG != NULL) - { - pIG->setActive(false); - CAHManager::getInstance()->runActionHandler("phrase_update_all_memory_ctrl_regen_tick_range", NULL); - } -} - -// *************************************************************************** -bool CTempInvManager::isOpened() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(WIN_TEMPINV)); - if (pGC != NULL) - return pGC->getActive(); - return false; -} - -// *************************************************************************** -// BAG LISTS COMMON STUFF (sort, options ...) -// *************************************************************************** - -// *************************************************************************** -#define BAG_ITEM_NOT_SORTED 1000000 -// Used for sorting -void initStructForItemSort(vector&vTemp, sint32 sheetId, sint32 quality, sint32 indexInList, sint32 indexInDB) -{ - // Default value is the linear pos in the db (in case its not an item) - vTemp[indexInList].Pos = toString("%08d", indexInDB); - - // if not empty - if (sheetId != 0) - { - CEntitySheet *pItem = SheetMngr.get(CSheetId(sheetId)); - if ((pItem != NULL) && (pItem->Type == CEntitySheet::ITEM)) - { - CItemSheet *pIS = safe_cast(pItem); - vTemp[indexInList].Pos = toString("%02d", pIS->Family); - vTemp[indexInList].Pos += toString("%03d", pIS->ItemType); - - // add some specific sort for raw material - if (pIS->Family == ITEMFAMILY::RAW_MATERIAL) - vTemp[indexInList].Pos += toString("%010d", pIS->Mp.ItemPartBF); - else - vTemp[indexInList].Pos += toString("%010d", 0); - - // add some specific sort for teleport - if (pIS->Family == ITEMFAMILY::TELEPORT) - vTemp[indexInList].Pos += toString("%02d%02d", pIS->ItemOrigin, pIS->Teleport.Type); - else - vTemp[indexInList].Pos += toString("%02d%02d", 0, 0); - - - vTemp[indexInList].Pos += toString("%03d", quality); - - // add sort by name - vTemp[indexInList].Pos += CSheetId(sheetId).toString(); - - - // add at last the index in DB. to avoid resort for items that are exaclty the same - vTemp[indexInList].Pos += toString("%03d", indexInDB); - } - } -} - -// *************************************************************************** -// Used for common options -bool SBagOptions::parse(xmlNodePtr cur, CInterfaceGroup * /* parentGroup */) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - // read params - CXMLAutoPtr prop; - - // value - prop = xmlGetProp (cur, (xmlChar*)"inv_type"); - if (prop) - { - InvType = CInventoryManager::invTypeFromString(prop.str()); - } - else - { - InvType = CInventoryManager::InvUnknown; - nlwarning("cannot find inventory type"); - } - - prop = xmlGetProp (cur, (xmlChar*)"filter_armor"); - if (prop) DbFilterArmor = NLGUI::CDBManager::getInstance()->getDbProp(prop.str()); - - prop = xmlGetProp (cur, (xmlChar*)"filter_weapon"); - if (prop) DbFilterWeapon = NLGUI::CDBManager::getInstance()->getDbProp(prop.str()); - - prop = xmlGetProp (cur, (xmlChar*)"filter_tool"); - if (prop) DbFilterTool = NLGUI::CDBManager::getInstance()->getDbProp(prop.str()); - - prop = xmlGetProp (cur, (xmlChar*)"filter_pet"); - if (prop) DbFilterPet = NLGUI::CDBManager::getInstance()->getDbProp(prop.str()); - - prop = xmlGetProp (cur, (xmlChar*)"filter_mp"); - if (prop) DbFilterMP = NLGUI::CDBManager::getInstance()->getDbProp(prop.str()); - - prop = xmlGetProp (cur, (xmlChar*)"filter_missmp"); - if (prop) DbFilterMissMP = NLGUI::CDBManager::getInstance()->getDbProp(prop.str()); - - prop = xmlGetProp (cur, (xmlChar*)"filter_tp"); - if (prop) DbFilterTP = NLGUI::CDBManager::getInstance()->getDbProp(prop.str()); - - return true; -} - -// *************************************************************************** -void SBagOptions::setSearchFilter(const ucstring &s) -{ - SearchQualityMin = 0; - SearchQualityMax = 999; - SearchFilter.clear(); - SearchFilterChanged = true; - - if (!s.empty()) - { - std::vector words; - splitUCString(toLower(s), ucstring(" "), words); - - size_t pos; - for(int i = 0; igetValue8() != 0) != LastDbFilterArmor) - { - bRet = true; - LastDbFilterArmor = (DbFilterArmor->getValue8() != 0); - } - - if (DbFilterWeapon != NULL) - if ((DbFilterWeapon->getValue8() != 0) != LastDbFilterWeapon) - { - bRet = true; - LastDbFilterWeapon = (DbFilterWeapon->getValue8() != 0); - } - - if (DbFilterTool != NULL) - if ((DbFilterTool->getValue8() != 0) != LastDbFilterTool) - { - bRet = true; - LastDbFilterTool = (DbFilterTool->getValue8() != 0); - } - - if (DbFilterPet != NULL) - if ((DbFilterPet->getValue8() != 0) != LastDbFilterPet) - { - bRet = true; - LastDbFilterPet = (DbFilterPet->getValue8() != 0); - } - - if (DbFilterMP != NULL) - if ((DbFilterMP->getValue8() != 0) != LastDbFilterMP) - { - bRet = true; - LastDbFilterMP = (DbFilterMP->getValue8() != 0); - } - - if (DbFilterMissMP != NULL) - if ((DbFilterMissMP->getValue8() != 0) != LastDbFilterMissMP) - { - bRet = true; - LastDbFilterMissMP = (DbFilterMissMP->getValue8() != 0); - } - - if (DbFilterTP != NULL) - if ((DbFilterTP->getValue8() != 0) != LastDbFilterTP) - { - bRet = true; - LastDbFilterTP = (DbFilterTP->getValue8() != 0); - } - - if (SearchFilterChanged) - { - bRet = true; - SearchFilterChanged = false; - } - - return bRet; -} - -// *************************************************************************** -bool SBagOptions::canDisplay(CDBCtrlSheet *pCS) const -{ - bool bDisplay = true; - - bool bFilterArmor = getFilterArmor(); - bool bFilterWeapon = getFilterWeapon(); - bool bFilterTool = getFilterTool(); - bool bFilterPet = getFilterPet(); - bool bFilterMP = getFilterMP(); - bool bFilterMissMP = getFilterMissMP(); - bool bFilterTP = getFilterTP(); - - const CItemSheet *pIS = pCS->asItemSheet(); - if (pIS != NULL) - { - if (SearchFilter.size() > 0) - { - bool match = true; - ucstring lcName = toLower(pCS->getItemActualName()); - - // add item quality as a keyword to match - if (pCS->getQuality() > 1) - { - lcName += ucstring(" " + toString(pCS->getQuality())); - } - - for (uint i = 0; i< SearchFilter.size(); ++i) - { - if (lcName.find(SearchFilter[i]) == ucstring::npos) - { - return false; - } - } - } - - // Quality range - if (SearchQualityMin > pCS->getQuality() || SearchQualityMax < pCS->getQuality()) - return false; - - // Armor - if ((pIS->Family == ITEMFAMILY::ARMOR) || - (pIS->Family == ITEMFAMILY::JEWELRY)) - if (!bFilterArmor) bDisplay = false; - - // Weapon - if ((pIS->Family == ITEMFAMILY::SHIELD) || - (pIS->Family == ITEMFAMILY::MELEE_WEAPON) || - (pIS->Family == ITEMFAMILY::RANGE_WEAPON) || - (pIS->Family == ITEMFAMILY::AMMO) || - (pIS->Family == ITEMFAMILY::CRYSTALLIZED_SPELL) || - (pIS->Family == ITEMFAMILY::ITEM_SAP_RECHARGE) || - (pIS->Family == ITEMFAMILY::BRICK) ) - if (!bFilterWeapon) bDisplay = false; - - // Tool - if ((pIS->Family == ITEMFAMILY::CRAFTING_TOOL) || - (pIS->Family == ITEMFAMILY::HARVEST_TOOL) || - (pIS->Family == ITEMFAMILY::TAMING_TOOL) || - (pIS->Family == ITEMFAMILY::TRAINING_TOOL) || - (pIS->Family == ITEMFAMILY::BAG)) - if (!bFilterTool) bDisplay = false; - - // Pet - if (pIS->Family == ITEMFAMILY::PET_ANIMAL_TICKET) - if (!bFilterPet) bDisplay = false; - - // MP - if ((pIS->Family == ITEMFAMILY::RAW_MATERIAL) && pIS->canBuildSomeItemPart()) - if (!bFilterMP) bDisplay = false; - - // Mission MP - if ((pIS->Family == ITEMFAMILY::MISSION_ITEM) || - (pIS->Family == ITEMFAMILY::XP_CATALYSER) || - (pIS->Family == ITEMFAMILY::CONSUMABLE) || - ((pIS->Family == ITEMFAMILY::RAW_MATERIAL) && !pIS->canBuildSomeItemPart())) - if (!bFilterMissMP) bDisplay = false; - - // Teleporter Pacts - if ((pIS->Family == ITEMFAMILY::TELEPORT)) - if (!bFilterTP) bDisplay = false; - - // Jobs Items - if (pIS->Id.toString().substr(0, 6) == "rpjob_") - bDisplay = false; - } - - return bDisplay; -} - -// *************************************************************************** -// CDBGroupListSheetBag -// *************************************************************************** - - -// *************************************************************************** -bool CDBGroupListSheetBag::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - if(!CDBGroupListSheetText::parse(cur, parentGroup)) - return false; - - // Parse options (type, filters ...) - if (!_BO.parse(cur,parentGroup)) - return false; - - return true; -} - -// *************************************************************************** -void CDBGroupListSheetBag::checkCoords () -{ - CDBGroupListSheetText::checkCoords(); - if (_BO.isSomethingChanged()) - invalidateCoords(); -} - -// *************************************************************************** -void CDBGroupListSheetBag::CSheetChildBag::updateViewText(CDBGroupListSheetText * /* pFather */) -{ - // common method to update text as item - updateViewTextAsItem(); -} - -// *************************************************************************** -bool CDBGroupListSheetBag::CSheetChildBag::isSheetValid(CDBGroupListSheetText *pFather) -{ - if (CSheetChild::isSheetValid(pFather)) - { - // Check if the control match the filters ! - CDBGroupListSheetBag *pList = dynamic_cast(pFather); - if (pList) - return pList->canDisplay(Ctrl); - } - return false; -} - -// *************************************************************************** -void CDBGroupListSheetBag::CSheetChildBag::init(CDBGroupListSheetText *pFather, uint index) -{ - // init my parent - CSheetChild::init(pFather, index); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - // **** Bind the quality - { - // Basic quality - string db= Ctrl->getSheet()+":QUALITY"; - if( NLGUI::CDBManager::getInstance()->getDbProp(db, false) ) - CurrentQuality.link ( db.c_str() ); - else - { - // dummy link to ui:..... - CurrentQuality.link("UI:DUMMY:QUALITY"); - CurrentQuality.setSInt32(0); - } - } -} - -// *************************************************************************** -bool CDBGroupListSheetBag::CSheetChildBag::isInvalidated(CDBGroupListSheetText * /* pFather */) -{ - // quality change - if( CurrentQuality.getSInt32() != LastQuality ) - return true; - - return false; -} - -// *************************************************************************** -void CDBGroupListSheetBag::CSheetChildBag::update(CDBGroupListSheetText * /* pFather */) -{ - LastQuality= CurrentQuality.getSInt32(); -} - -// *************************************************************************** -void CDBGroupListSheetBag::onSwap (sint /* nDraggedSheet */, sint /* nDroppedSheet */) -{ - // No more used because automatic sort -} - -// *************************************************************************** -void CDBGroupListSheetBag::sort() -{ - vector vTemp; - - vTemp.resize (_MaxItems); - - uint i; - for (i = 0; i < _MaxItems; ++i) - { - vTemp[i].SheetText = _SheetChildren[i]; - - CDBCtrlSheet *ctrl= _SheetChildren[i]->Ctrl; - initStructForItemSort (vTemp, ctrl->getSheetId(), ctrl->getQuality(), i, ctrl->getIndexInDB()); - } - - std::sort(vTemp.begin(), vTemp.end()); - - for (i = 0; i < _MaxItems; ++i) - { - _SheetChildren[i] = vTemp[i].SheetText; - } -} - -// *************************************************************************** -// CDBGroupIconListBag -// *************************************************************************** - -// *************************************************************************** -bool CDBGroupIconListBag::parse (xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - if(!CDBGroupListSheet::parse(cur, parentGroup)) - return false; - - // Parse options (type, filters ...) - if (!_BO.parse(cur,parentGroup)) - return false; - - return true; -} - -// *************************************************************************** -void CDBGroupIconListBag::sort() -{ - vector vTemp; - - vTemp.resize (_MaxItems); - - uint i; - for (i = 0; i < _MaxItems; ++i) - { - vTemp[i].SheetIcon = _SheetChildren[i]; - - CDBCtrlSheet *ctrl= _SheetChildren[i]->Ctrl; - initStructForItemSort (vTemp, ctrl->getSheetId(), ctrl->getQuality(), i, ctrl->getIndexInDB()); - } - - std::sort(vTemp.begin(), vTemp.end()); - - for (i = 0; i < _MaxItems; ++i) - { - _SheetChildren[i] = vTemp[i].SheetIcon; - } -} - -// *************************************************************************** -void CDBGroupIconListBag::checkCoords () -{ - CDBGroupListSheet::checkCoords(); - if (_BO.isSomethingChanged()) - invalidateCoords(); -} - -// *************************************************************************** -bool CDBGroupIconListBag::CSheetChildBag::isSheetValid(CDBGroupListSheet *pFather) -{ - if (CSheetChild::isSheetValid(pFather)) - { - // Check if the control match the filters ! - CDBGroupIconListBag *pList = dynamic_cast(pFather); - if (pList) - return pList->canDisplay(Ctrl); - } - return false; -} - - - -// *************************************************************************** -// CDBGroupListSheetFilterCLMSlot -// *************************************************************************** - -// *************************************************************************** -bool CDBGroupListSheetFilterCLMSlot::CSheetChildFilter::isSheetValid(CDBGroupListSheet *pFather) -{ - if (CSheetChild::isSheetValid(pFather)) - { - /* This filter look the ctrl who launch the modal where this list is displayed. - If we can drop this ChildCtrl, on the CLM control, then ok, filtered - Plus the ChildControl must not be locked - */ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CDBCtrlSheet *clmCtrl = dynamic_cast(CWidgetManager::getInstance()->getCtrlLaunchingModal()); - if (!clmCtrl || !Ctrl) return false; - if (clmCtrl->getInventoryIndex() == INVENTORIES::exchange && - Ctrl->getInventoryIndex() == INVENTORIES::exchange) - { - return false; - } - if ((clmCtrl->getType() == CCtrlSheetInfo::SheetType_Item) && - (Ctrl->getType() == CCtrlSheetInfo::SheetType_Item) ) - { - // Ok if we can put in the slot Ctrl in clmCtrl - if ( clmCtrl->canDropItem(Ctrl)) - { - string sTmp = Ctrl->getSheet(); - // Look if the source is locked - sTmp = sTmp.substr(sTmp.rfind(':')+1,sTmp.size()); - sint32 nTmp; - fromString(sTmp, nTmp); - if (!getInventory().isBagItemWeared(nTmp)) - return true; - } - } - } - return false; -} - -// *************************************************************************** -// CDBGroupListSheetFilterExchangeable -// *************************************************************************** - -// *************************************************************************** -bool CDBGroupListSheetFilterExchangeable::CSheetChildFilter::isSheetValid(CDBGroupListSheet *pFather) -{ - if (CSheetChild::isSheetValid(pFather)) - { - if(!Ctrl) - return false; - extern bool checkCanExchangeItem(CDBCtrlSheet *); - return checkCanExchangeItem(Ctrl); - } - return false; -} - -// *************************************************************************** -void CDBGroupListSheetFilterExchangeable::sort() -{ - vector vTemp; - - vTemp.resize (_MaxItems); - - uint i; - for (i = 0; i < _MaxItems; ++i) - { - vTemp[i].SheetIcon = _SheetChildren[i]; - - CDBCtrlSheet *ctrl= _SheetChildren[i]->Ctrl; - initStructForItemSort (vTemp, ctrl->getSheetId(), ctrl->getQuality(), i, ctrl->getIndexInDB()); - } - - std::sort(vTemp.begin(), vTemp.end()); - - for (i = 0; i < _MaxItems; ++i) - { - _SheetChildren[i] = vTemp[i].SheetIcon; - } -} - -// *************************************************************************** -bool CDBGroupListSheetFilterExchangeable::parse(xmlNodePtr cur, CInterfaceGroup *parentGroup) -{ - if(!CDBGroupListSheet::parse(cur, parentGroup)) - return false; - - // Parse options (type, filters ...) - if (!_BO.parse(cur,parentGroup)) - return false; - - return true; -} - -// *************************************************************************** -// *************************************************************************** -// *************************************************************************** -// ACTION HANDLERS -// *************************************************************************** -// *************************************************************************** -// *************************************************************************** - -// *************************************************************************** -// COMMON INVENTORIES DRAG'N'DROP -// *************************************************************************** - -// *************************************************************************** -class CHandlerInvCanDrag : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &/* Params */) - { - CDBCtrlSheet *pCSSrc = dynamic_cast(pCaller); - if (pCSSrc == NULL) return; - - // Cannot drag an item if it is completely locked - if (pCSSrc->getNonLockedQuantity() == 0) - { - pCSSrc->setTempCanDrag(false); - return; - } - - // If the item comes from an animal list which is not available -> cannot move - if (strnicmp(pCSSrc->getSheet().c_str(), "LOCAL:INVENTORY:PACK_ANIMAL", 27) == 0) - { - string sTmp = pCSSrc->getSheet().substr(0, pCSSrc->getSheet().rfind(':')); - sTmp = sTmp.substr(27,sTmp.size()); - uint32 nAni; - fromString(sTmp, nAni); - INVENTORIES::TInventory inv = (INVENTORIES::TInventory)(INVENTORIES::pet_animal+nAni); - pCSSrc->setTempCanDrag(getInventory().isInventoryAvailable(inv)); - } - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvCanDrag, "inv_can_drag" ); - -// *************************************************************************** -class CHandlerInvDrag : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - CDBCtrlSheet *pCS = dynamic_cast(pCaller); - if (pCS == NULL) return; - if (Params == "from_text_list") - getInventory().beginDrag(pCS, CInventoryManager::TextList); - else if (Params == "from_slot") - getInventory().beginDrag(pCS, CInventoryManager::Slot); - else if (Params == "from_icon_list") - getInventory().beginDrag(pCS, CInventoryManager::IconList); - else - nlwarning("DND not binded"); - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvDrag, "inv_drag" ); - -// *************************************************************************** -// show/hide edit box, set keyboard focus if 'show' -class CHandlerInvSearchButton : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &sParams) - { - if (sParams.empty()) - { - nlwarning("inv_search_button: missing edit box shortid"); - return; - } - - CCtrlBaseButton* btn = dynamic_cast(pCaller); - if (!btn) - { - nlwarning("inv_search_button pCaller == NULL, caller must be CCtrlBaseButton with 'toggle_button' type"); - return; - } - - ucstring filter; - std::string id = btn->getParent()->getId() + ":" + sParams + ":eb"; - CGroupEditBox *eb = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(id)); - if (!eb) - { - nlwarning("inv_search_button: editbox (%s) not found\n", id.c_str()); - return; - } - - eb->getParent()->setActive(btn->getPushed()); - if (eb->getParent()->getActive()) - { - CWidgetManager::getInstance()->setCaptureKeyboard(eb); - eb->setSelectionAll(); - filter = eb->getInputString(); - } - - CDBGroupListSheetBag *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(btn->getParent()->getId() + ":bag_list")); - if (pList != NULL) pList->setSearchFilter(filter); - - CDBGroupIconListBag *pIcons = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(btn->getParent()->getId() + ":bag_icons")); - if (pIcons != NULL) pIcons->setSearchFilter(filter); - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvSearchButton, "inv_search_button" ); - -// *************************************************************************** -// if :eb is empty then hide edit box, unpush search button -class CHandlerInvSearchUnfocus : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &sParams) - { - if (!pCaller) return; - - CGroupEditBox *eb = dynamic_cast(pCaller); - if (!eb || !eb->getInputString().empty()) return; - - // ui:interface:inventory:content:bag:iil:inv_query_eb:eb - std::string id = pCaller->getParent()->getParent()->getId() + ":" + sParams; - CCtrlBaseButton *btn = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(id)); - if (btn) btn->setPushed(false); - - // hide :inv_query_eb - pCaller->getParent()->setActive(false); - - // clear filter - CAHManager::getInstance()->runActionHandler("inv_set_search", pCaller, ""); - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvSearchUnfocus, "inv_search_unfocus" ); - -// ********************************************************************************************************** -// set inventory search string -class CHandlerInvSetSearch : public IActionHandler -{ - void execute (CCtrlBase *pCaller, const std::string &sParams) - { - CGroupEditBox *eb = dynamic_cast(pCaller); - if (!eb) return; - - // ui:interface:inventory:content:bag:iil:inv_query_eb:eb - std::string id = pCaller->getParent()->getParent()->getId(); - - CDBGroupListSheetBag *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(id + ":bag_list")); - if (pList != NULL) pList->setSearchFilter(eb->getInputString()); - - CDBGroupIconListBag *pIcons = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(id + ":bag_icons")); - if (pIcons != NULL) pIcons->setSearchFilter(eb->getInputString()); - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvSetSearch, "inv_set_search" ); - -// *************************************************************************** -// COMMON INVENTORIES Test if we can drop an item to a slot or a list -class CHandlerInvCanDropTo : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - // pCSSrc is the current dragged item - // pCSDst is a slot or a list - - CInventoryManager *pInv = CInventoryManager::getInstance(); - if (!pInv->isDragging()) return; // To prevent other things to happens - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - string src = getParam(Params, "src"); - CInterfaceElement *pElt = CWidgetManager::getInstance()->getElementFromId(src); - CDBCtrlSheet *pCSSrc = dynamic_cast(pElt); - if (pCSSrc == NULL) return; // Cannot do anything if the incoming sheet is not a sheet - - // Special case if we want to DND an animal representation - // ------------------------------------------------------- - { - const CItemSheet *pIS = pCSSrc->asItemSheet(); - if ((pIS != NULL) && (pIS->Family == ITEMFAMILY::PET_ANIMAL_TICKET)) - { - CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - if (pCSDst != NULL) - { - // The destination must be exchange or gift - if (strnicmp(pCSDst->getSheet().c_str(),"LOCAL:EXCHANGE:GIVE", 19) == 0) - { - // The animal bag must be empty before giving it - if (pIS->Pet.Slot > 0) - if (pInv->isInventoryEmpty((INVENTORIES::TInventory)(INVENTORIES::pet_animal+(pIS->Pet.Slot-1)))) - pCSDst->setCanDrop (true); - } - // Or moving in the bag (user sort) - if (strnicmp(pCSDst->getSheet().c_str(),"LOCAL:INVENTORY:BAG", 19) == 0) - pCSDst->setCanDrop (true); - } - return; - } - } - - // The destination is a slot or something like that ? - // -------------------------------------------------- - CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - if (pCSDst != NULL) - { - // If we want to drop something on a reference slot (hand or equip) - if (!pInv->getDBIndexPath(pCSDst).empty()) - { - // We must drag'n'drop an item - if (pCSSrc && pCSSrc->getType() == CCtrlSheetInfo::SheetType_Item) - if (pCSDst && pCSDst->getType() == CCtrlSheetInfo::SheetType_Item) - { - if (!pInv->getDBIndexPath(pCSSrc).empty()) - { - // The item dragged comes from a slot check if this is the good type - if (pCSDst->canDropItem(pCSSrc)) - pCSDst->setCanDrop ( true ); - } - else - { - // The source must be from the bag - if (strnicmp(pCSSrc->getSheet().c_str(),"LOCAL:INVENTORY:BAG", 19) == 0) - pCSDst->setCanDrop ( true ); - } - } - } - else - { - // Does the source and destination are items ? - if (pCSSrc && pCSSrc->getType() == CCtrlSheetInfo::SheetType_Item) - if (pCSDst && pCSDst->getType() == CCtrlSheetInfo::SheetType_Item) - { - // Right Slot ? - if (pCSDst->canDropItem(pCSSrc)) - pCSDst->setCanDrop ( true ); - } - } - return; - } - - // The destination is a list of items ? - // ------------------------------------ - CDBGroupListSheetBag *pListDstText = dynamic_cast(pCaller); - CDBGroupIconListBag *pListDstIcon = dynamic_cast(pCaller); - if ((pListDstText != NULL) || (pListDstIcon != NULL)) - { - bool bCanDrop = true; - // WE CANT DND if we want to dnd from other bag than BAG to guild bag - if (pListDstIcon != NULL) - { - if (pListDstIcon->getInvType() == CInventoryManager::InvGuild) - if (strnicmp(pCSSrc->getSheet().c_str(),"LOCAL:INVENTORY:BAG", 19) != 0) - bCanDrop = false; - } - if (pListDstText != NULL) - { - if (pListDstText->getInvType() == CInventoryManager::InvGuild) - if (strnicmp(pCSSrc->getSheet().c_str(),"LOCAL:INVENTORY:BAG", 19) != 0) - bCanDrop = false; - } - // WE CANT DND if we want to dnd from guild bag to other bag than BAG - if (pListDstIcon != NULL) - { - if (pListDstIcon->getInvType() != CInventoryManager::InvBag) - if (strnicmp(pCSSrc->getSheet().c_str(),"SERVER:GUILD:INVENTORY", 19) == 0) - bCanDrop = false; - } - if (pListDstText != NULL) - { - if (pListDstText->getInvType() != CInventoryManager::InvBag) - if (strnicmp(pCSSrc->getSheet().c_str(),"SERVER:GUILD:INVENTORY", 19) == 0) - bCanDrop = false; - } - - // WE CANT DND when packer/mount is too far - if (pListDstIcon != NULL) - { - if ((pListDstIcon->getInvType() == CInventoryManager::InvPA0) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA1) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA2) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA3) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA4) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA5) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA6)) - { - INVENTORIES::TInventory e = (INVENTORIES::TInventory)(INVENTORIES::pet_animal1 + (pListDstIcon->getInvType()-CInventoryManager::InvPA0)); - if (!pInv->isInventoryAvailable(e)) - bCanDrop = false; - } - } - if (pListDstText != NULL) - { - if ((pListDstText->getInvType() == CInventoryManager::InvPA0) || - (pListDstText->getInvType() == CInventoryManager::InvPA1) || - (pListDstText->getInvType() == CInventoryManager::InvPA2) || - (pListDstText->getInvType() == CInventoryManager::InvPA3) || - (pListDstText->getInvType() == CInventoryManager::InvPA4) || - (pListDstText->getInvType() == CInventoryManager::InvPA5) || - (pListDstText->getInvType() == CInventoryManager::InvPA6)) - { - INVENTORIES::TInventory e = (INVENTORIES::TInventory)(INVENTORIES::pet_animal1 + (pListDstText->getInvType()-CInventoryManager::InvPA0)); - if (!pInv->isInventoryAvailable(e)) - bCanDrop = false; - } - } - - // If the source is the equipment - - if (pListDstText != NULL) pListDstText->setCanDrop(bCanDrop); - if (pListDstIcon != NULL) pListDstIcon->setCanDrop(bCanDrop); - } - - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvCanDropTo, "inv_can_drop" ); - -// *************************************************************************** -class CHandlerInvDropTo : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &Params) - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - // Check that we have drag'n'drop from inventory (list or slot) - // Or if we have launched the choose_bag modal - // To prevent other things to happens - if (!getInventory().isDragging()) - { - CInterfaceGroup *pIG = CWidgetManager::getInstance()->getModalWindow(); - if (pIG == NULL) return; - if (pIG->getId() != "ui:interface:bag_choose") return; - getInventory().beginDrag(NULL, CInventoryManager::TextList); - - // Special case for choose in bag dialog - string src = getParam(Params, "src"); - CInterfaceElement *pElt = CWidgetManager::getInstance()->getElementFromId(src); - CDBCtrlSheet *pCSSrc = dynamic_cast(pElt); - CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - - string invPath = getInventory().getDBIndexPath(pCSSrc); - string bagPath = pCSDst->getSheet(); - - if (bagPath == "UI:EMPTY") - getInventory().unequip (invPath); - else - getInventory().equip (bagPath, invPath); - - getInventory().endDrag(); - return; - } - - string src = getParam(Params, "src"); - CInterfaceElement *pElt = CWidgetManager::getInstance()->getElementFromId(src); - CDBCtrlSheet *pCSSrc = dynamic_cast(pElt); - CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - if (pCSSrc == NULL) return; - - // Is the dragged sheet comes from an inventory list - if (getInventory().isDraggingFromTextList() || getInventory().isDraggingFromIconList()) - { - // If the destination is an equipment slot ? - if (pCSDst != NULL) - { - string invPath = getInventory().getDBIndexPath(pCSDst); // Get the index in the equipment - if (!invPath.empty()) - { - // Drop to the slot ie write the database with the index of the slot - string bagPath = pCSSrc->getSheet(); // Get the database branch of the dragged sheet - - if (pCSSrc && pCSSrc->getType() == CCtrlSheetInfo::SheetType_Item) - if (pCSDst && pCSDst->getType() == CCtrlSheetInfo::SheetType_Item) - { - // If the destination slot match with the type of incoming item - if (pCSDst->canDropItem(pCSSrc)) - { - // So directly equip - getInventory().equip(bagPath, invPath); - } - else - { - // Else try to auto equip the player with the incoming item - const string sTmp = bagPath.substr(bagPath.rfind(':')+1,bagPath.size()); - sint index; - fromString(sTmp, index); - if (!getInventory().autoEquip(index, false)) - getInventory().autoEquip(index, true); - } - } - getInventory().endDrag(); - return; - } - } - - // If the destination is a list sheet - IListSheetBase *pListDst = dynamic_cast(pCaller); - if ((pListDst == NULL) && (pCSDst != NULL)) - pListDst = IListSheetBase::getListContaining(pCSDst); - IListSheetBase *pListSrc = IListSheetBase::getListContaining(pCSSrc); - if ((pListDst != NULL) && (pListSrc != NULL)) - { - // If the source list and destination list are the same - if (pListDst == pListSrc) - { - // no op - getInventory().endDrag(); - return; - } - else // Source list and destination list are not the same - { - // Move the item to the destination list using the procedure move_to_xxx - CDBGroupListSheetBag *pListDstText = dynamic_cast(pListDst); - CDBGroupIconListBag *pListDstIcon = dynamic_cast(pListDst); - - if (((pListDstText != NULL) && (pListDstText->getInvType() == CInventoryManager::InvBag)) || - ((pListDstIcon != NULL) && (pListDstIcon->getInvType() == CInventoryManager::InvBag))) - { - CAHManager::getInstance()->runActionHandler("proc", pCSSrc, "move_to_bag"); - } - else if (((pListDstText != NULL) && ((pListDstText->getInvType() == CInventoryManager::InvPA0) || - (pListDstText->getInvType() == CInventoryManager::InvPA1) || - (pListDstText->getInvType() == CInventoryManager::InvPA2) || - (pListDstText->getInvType() == CInventoryManager::InvPA3) || - (pListDstText->getInvType() == CInventoryManager::InvPA4) || - (pListDstText->getInvType() == CInventoryManager::InvPA5) || - (pListDstText->getInvType() == CInventoryManager::InvPA6) - )) || - ((pListDstIcon != NULL) && ((pListDstIcon->getInvType() == CInventoryManager::InvPA0) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA1) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA2) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA3) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA4) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA5) || - (pListDstIcon->getInvType() == CInventoryManager::InvPA6) - ))) - { - string sTmp; - if (pListDstText != NULL) sTmp = toString("%d",pListDstText->getInvType()-CInventoryManager::InvPA0); - if (pListDstIcon != NULL) sTmp = toString("%d",pListDstIcon->getInvType()-CInventoryManager::InvPA0); - nlinfo("ici :%s", sTmp.c_str()); - CAHManager::getInstance()->runActionHandler("proc", pCSSrc, "move_to_pa|"+sTmp); - } - else if (((pListDstText != NULL) && (pListDstText->getInvType() == CInventoryManager::InvGuild)) || - ((pListDstIcon != NULL) && (pListDstIcon->getInvType() == CInventoryManager::InvGuild))) - { - if (strnicmp(pCSSrc->getSheet().c_str(), "LOCAL:INVENTORY:BAG", 19) == 0) - CAHManager::getInstance()->runActionHandler("proc", pCSSrc, "move_to_guild"); - } - else if (((pListDstText != NULL) && (pListDstText->getInvType() == CInventoryManager::InvRoom)) || - ((pListDstIcon != NULL) && (pListDstIcon->getInvType() == CInventoryManager::InvRoom))) - { - CAHManager::getInstance()->runActionHandler("proc", pCSSrc, "move_to_room"); - } - } - } - } - - // Is the dragged sheet comes from another slot - if (pCSDst != NULL) - if (getInventory().isDraggingFromSlot()) - { - // Yes swap the 2 indices - // Get the database branch of the dragged sheet - string invPath1 = getInventory().getDBIndexPath(pCSSrc); - // Get the index in the equipment - string invPath2 = getInventory().getDBIndexPath(pCSDst); - - sint32 i1 = NLGUI::CDBManager::getInstance()->getDbProp(invPath1+":INDEX_IN_BAG")->getValue16(); - sint32 i2 = NLGUI::CDBManager::getInstance()->getDbProp(invPath2+":INDEX_IN_BAG")->getValue16(); - - getInventory().unequip(invPath1); - getInventory().unequip(invPath2); - - string sBag = LOCAL_INVENTORY ":BAG:"; - if (i2 != 0) getInventory().equip(sBag + toString(i2-1), invPath1); - if (i1 != 0) getInventory().equip(sBag + toString(i1-1), invPath2); - } - - CAHManager::getInstance()->runActionHandler("inv_cannot_drop", pCSSrc); - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvDropTo, "inv_drop" ); - - -// *************************************************************************** -// EQUIPMENT -class CHandlerInvCannotDrop : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &/* Params */) - { - // Is the dragged sheet comes from a slot - if (!getInventory().isDraggingFromTextList()) - { - // Unequip - CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - string invPath = getInventory().getDBIndexPath(pCSDst); - getInventory().unequip(invPath); - } - getInventory().endDrag(); - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvCannotDrop, "inv_cannot_drop" ); - - -// *************************************************************************** -class CHandlerInvAutoEquip : public IActionHandler -{ -public: - virtual void execute (CCtrlBase *pCaller, const string &/* Params */) - { - CDBCtrlSheet *cs = dynamic_cast(pCaller); - if(cs) - { - uint index= cs->getIndexInDB(); - if (!getInventory().autoEquip(index, false)) - getInventory().autoEquip(index, true); - } - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvAutoEquip, "inv_auto_equip" ); - - -// ********************************************************************************************************** -class CHandlerLockInvItem : public IActionHandler -{ - void execute (CCtrlBase *pCaller, const std::string &sParams) - { - // get the calling item - CDBCtrlSheet *item = CDBCtrlSheet::getCurrSelSheet(); - if ( ! item) - { - nlwarning(" no caller sheet found"); - return; - } - - string lock = "1"; - if (item->getLockedByOwner()) - { - lock = "0"; - } - - uint32 slot = item->getIndexInDB(); - uint32 inv = item->getInventoryIndex(); - INVENTORIES::TInventory inventory = INVENTORIES::UNDEFINED; - inventory = (INVENTORIES::TInventory)(inv); - if (inventory == INVENTORIES::UNDEFINED) - { - return; - } - NLMISC::ICommand::execute("a lockItem " + INVENTORIES::toString(inventory) + " " + toString(slot) + " " + lock, g_log); - } -}; -REGISTER_ACTION_HANDLER( CHandlerLockInvItem, "lock_inv_item" ); - -// *************************************************************************** -// Inventory Temporary -// *************************************************************************** - -// *************************************************************************** -class CHandlerInvTempToBag : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &/* Params */) - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - // Disable the direct click on item in Forage mode and Can't take all - if ( (CTempInvManager::getInstance()->getMode() == TEMP_INV_MODE::Forage) && - (NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:INVENTORY:TEMP:ENABLE_TAKE")->getValue32() == 0) ) - return; - - CDBCtrlSheet *pCSDst = dynamic_cast(pCaller); - if (!pCSDst->isSheetValid()) return; - string sTmp = pCSDst->getSheet(); - - sTmp = sTmp.substr(sTmp.rfind(':')+1, sTmp.size()); - uint16 index; - fromString(sTmp, index); - - // If we cant find place display a message and dont send the request to the server - if (!getInventory().isSpaceInAllBagsForItem(pCSDst)) - { - ucstring msg = CI18N::get("msgCantPutItemInBag"); - string cat = getStringCategory(msg, msg); - pIM->displaySystemInfo(msg, cat); - return; - } - - sTmp = pCSDst->getSheet(); - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(sTmp+":SHEET",false); - pNL->setValue32(0); - - CBitMemStream out; - if (!GenericMsgHeaderMngr.pushNameToStream("ITEM:TEMP_TO_BAG", out)) - { - nlwarning ("don't know message name ITEM:TEMP_TO_BAG"); - } - else - { - // Fill the message (temporary inventory slot) - out.serial(index); - NetMngr.push (out); - //nlinfo("impulseCallBack : ITEM:TEMP_TO_BAG %d sent", index); - } - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvTempToBag, "inv_temp_to_bag" ); - -// *************************************************************************** -class CHandlerInvTempAll : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - if (!CTempInvManager::getInstance()->isOpened()) return; - if (NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP_INV:ALL_EMPTY")->getValue32() != 0) return; - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInventoryManager *pInv = CInventoryManager::getInstance(); - - // Try to put all items in the DB order in all the bags of the player : (bag, pa0-3, steed) - vector > BagsBulk; - BagsBulk.push_back(pair (pInv->getBagBulk(0), pInv->getMaxBagBulk(0))); - - nlctassert(MAX_INVENTORY_ANIMAL==7); - if (pInv->isInventoryAvailable(INVENTORIES::pet_animal1)) - BagsBulk.push_back(pair (pInv->getBagBulk(1), pInv->getMaxBagBulk(1))); - if (pInv->isInventoryAvailable(INVENTORIES::pet_animal2)) - BagsBulk.push_back(pair (pInv->getBagBulk(2), pInv->getMaxBagBulk(2))); - if (pInv->isInventoryAvailable(INVENTORIES::pet_animal3)) - BagsBulk.push_back(pair (pInv->getBagBulk(3), pInv->getMaxBagBulk(3))); - if (pInv->isInventoryAvailable(INVENTORIES::pet_animal4)) - BagsBulk.push_back(pair (pInv->getBagBulk(4), pInv->getMaxBagBulk(4))); - if (pInv->isInventoryAvailable(INVENTORIES::pet_animal5)) - BagsBulk.push_back(pair (pInv->getBagBulk(5), pInv->getMaxBagBulk(4))); - if (pInv->isInventoryAvailable(INVENTORIES::pet_animal6)) - BagsBulk.push_back(pair (pInv->getBagBulk(6), pInv->getMaxBagBulk(4))); - if (pInv->isInventoryAvailable(INVENTORIES::pet_animal7)) - BagsBulk.push_back(pair (pInv->getBagBulk(7), pInv->getMaxBagBulk(4))); - - bool bPlaceFound = true; - - for (uint32 itemNb = 0; itemNb < MAX_TEMPINV_ENTRIES; ++itemNb) - { - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":TEMP:" + toString(itemNb) + ":SHEET"); - CCDBNodeLeaf *pNLquantity = NLGUI::CDBManager::getInstance()->getDbProp(LOCAL_INVENTORY ":TEMP:" + toString(itemNb) + ":QUANTITY"); - if (pNL == NULL || pNLquantity == NULL) continue; - if (pNL->getValue32() == 0 || pNLquantity->getValue32() == 0) continue; - double itemBulk = pNLquantity->getValue32() * pInv->getItemBulk(pNL->getValue32()); - - bool bLocalPlaceFound = false; - for (uint32 i = 0; i < BagsBulk.size(); ++i) - { - if ((BagsBulk[i].first + itemBulk) <= BagsBulk[i].second) - { - BagsBulk[i].first += itemBulk; - bLocalPlaceFound = true; - break; - } - } - if (!bLocalPlaceFound) - { - bPlaceFound = false; - break; - } - } - - if (!bPlaceFound) - { - ucstring msg = CI18N::get("msgCantPutItemInBag"); - string cat = getStringCategory(msg, msg); - CInterfaceManager::getInstance()->displaySystemInfo(msg, cat); - return; - } - - CBitMemStream out; - if (!GenericMsgHeaderMngr.pushNameToStream("ITEM:ALL_TEMP", out)) - { - nlwarning ("don't know message name ITEM:ALL_TEMP"); - } - else - { - NetMngr.push (out); - //nlinfo("impulseCallBack : ITEM:ALL_TEMP sent"); - } - CTempInvManager::getInstance()->close(); - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvTempAll, "inv_temp_all" ); - -// *************************************************************************** -class CHandlerInvTempNone : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - CBitMemStream out; - if (!GenericMsgHeaderMngr.pushNameToStream("ITEM:NO_TEMP", out)) - { - nlwarning ("don't know message name ITEM:NO_TEMP"); - } - else - { - NetMngr.push (out); - //nlinfo("impulseCallBack : ITEM:NO_TEMP sent"); - } - CTempInvManager::getInstance()->close(); - } -}; -REGISTER_ACTION_HANDLER( CHandlerInvTempNone, "inv_temp_none" ); - - -// *************************************************************************** -// *************************************************************************** -// ItemInfo System -// *************************************************************************** -// *************************************************************************** - -// *************************************************************************** -void CClientItemInfo::readFromImpulse(const CItemInfos &itemInfo) -{ - *(CItemInfos*)this= itemInfo; - - // Read now the version in the impulse - InfoVersionFromMsg= itemInfo.versionInfo; -} - -// *************************************************************************** -uint16 CInventoryManager::getItemSlotId(CDBCtrlSheet *ctrl) -{ - return getItemSlotId(ctrl->getSheet(), ctrl->getIndexInDB()); -} - -// *************************************************************************** -uint16 CInventoryManager::getItemSlotId(const std::string &itemDb, uint slotIndex) -{ - // then compare to all possible inventories (ugly) - uint inventoryIndex= 0; - for(uint i=0;i>CItemInfos::SlotIdIndexBitSize) ) - { - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp( toString( "SERVER:%s:%d:SHEET", InventoryDBs[i].c_str(), (slotId&CItemInfos::SlotIdIndexBitMask)), false); - if(node) - return node->getValue32(); - else - return 0; - } - } - - return 0; -} - -// *************************************************************************** -const CClientItemInfo *CInventoryManager::getItemInfoCache(uint32 serial, uint32 createTime) const -{ - return _ItemInfoCache.getItemInfo(serial, createTime); -} - -// *************************************************************************** -const CClientItemInfo &CInventoryManager::getItemInfo(uint slotId) const -{ - TItemInfoMap::const_iterator it= _ItemInfoMap.find(slotId); - static CClientItemInfo empty; - if (it == _ItemInfoMap.end() || !isItemInfoUpToDate(slotId)) - { - // if slot has not been populated yet or out of date, then return info from cache if possible - const CItemImage *item = getServerItem(slotId); - if (item && item->getItemId() > 0) { - const CClientItemInfo *ret = _ItemInfoCache.getItemInfo(item->getItemId()); - if (ret != NULL) - { - return *ret; - } - } - } - - if (it == _ItemInfoMap.end()) - { - return empty; - } - - return it->second; -} - -// *************************************************************************** -bool CInventoryManager::isItemInfoAvailable(uint slotId) const -{ - TItemInfoMap::const_iterator it= _ItemInfoMap.find(slotId); - return it != _ItemInfoMap.end(); -} -// *************************************************************************** -bool CInventoryManager::isItemInfoUpToDate(uint slotId) const -{ - TItemInfoMap::const_iterator it= _ItemInfoMap.find(slotId); - if (it == _ItemInfoMap.end()) - return true; - - // true if the version already matches - return it->second.InfoVersionFromMsg == it->second.InfoVersionFromSlot; -} - -// *************************************************************************** -void CInventoryManager::addItemInfoWaiter(IItemInfoWaiter *waiter) -{ - if(!waiter) - return; - - // first remove the waiter if already here - removeItemInfoWaiter(waiter); - - // Then push_front (stack) - _ItemInfoWaiters.push_front(waiter); - - // update server msg - updateItemInfoQueue(); -} - -// *************************************************************************** -void CInventoryManager::removeItemInfoWaiter(IItemInfoWaiter *waiter) -{ - TItemInfoWaiters::iterator it; - for(it= _ItemInfoWaiters.begin();it!=_ItemInfoWaiters.end();it++) - { - if(waiter==*it) - { - _ItemInfoWaiters.erase(it); - break; - } - } -} - -// *************************************************************************** -void CInventoryManager::updateItemInfoWaiters(uint itemSlotId) -{ - // First verify if the versions matches. If differ, no need to update waiters since not good. - if (!isItemInfoUpToDate(itemSlotId)) - { - return; - } - - bool isItemFromTrading= (itemSlotId>>CItemInfos::SlotIdIndexBitSize)==INVENTORIES::trading; - - // For all waiters that wait for this item slot - TItemInfoWaiters::iterator it; - for(it= _ItemInfoWaiters.begin();it!=_ItemInfoWaiters.end();) - { - TItemInfoWaiters::iterator itNext=it; - itNext++; - IItemInfoWaiter *waiter=*it; - // callback. NB: only ig the waiter agree the Sheet in the current slot id - if(waiter->ItemSlotId == itemSlotId && - (isItemFromTrading || waiter->ItemSheet == getItemSheetForSlotId(itemSlotId)) ) - { - waiter->infoReceived(); - } - - // in case it is erased in infoReceived() - it= itNext; - } -} - -// *************************************************************************** -void CInventoryManager::CItemInfoSlotVersionObs::update(ICDBNode* node) -{ - getInventory().onReceiveItemInfoSlotVersion(node); -} - -// *************************************************************************** -void CInventoryManager::CItemSheetObs::update(ICDBNode* node) -{ - getInventory().onReceiveItemSheet(node); -} - -// *************************************************************************** -void CInventoryManager::CItemInfoTradeObs::update(ICDBNode* /* node */) -{ - getInventory().onTradeChangeSession(); -} - -// *************************************************************************** -void CInventoryManager::onReceiveItemInfoSlotVersion(ICDBNode* node) -{ - uint itemSlotId; - - // valid only if of form 0:INFO_VERSION - if( !dynamic_cast(node) || !node->getParent() || !node->getParent()->getName()) - return; - - // get the slot in inventory of the item - uint slot; - fromString(*node->getParent()->getName(), slot); - - // get the slotId for this DB - itemSlotId= getItemSlotId(node->getFullName(), slot); - - // update the InfoVersionFromSlot - _ItemInfoMap[itemSlotId].InfoVersionFromSlot= ((CCDBNodeLeaf*)node)->getValue8(); - - // Look for Waiters that match this item slot => update - updateItemInfoWaiters(itemSlotId); - - // new msg to send, because version updated? - updateItemInfoQueue(); -} - -// *************************************************************************** -void CInventoryManager::onReceiveItemSheet(ICDBNode* node) -{ - // When a SHEET change, it may unblock some ITEM_INFO:GET calls or some info waiters update. - uint itemSlotId; - - // valid only if of form 0:INFO_VERSION - if( !dynamic_cast(node) || !node->getParent() || !node->getParent()->getName()) - return; - - // get the slot in inventory of the item - uint slot; - fromString(*node->getParent()->getName(), slot); - - // get the slotId for this DB - itemSlotId= getItemSlotId(node->getFullName(), slot); - - // Look for Waiters that match this item slot => update - updateItemInfoWaiters(itemSlotId); - - // new msg to send, because sheet ok? - updateItemInfoQueue(); -} - -// *************************************************************************** -void CInventoryManager::onReceiveItemInfo(const CItemInfos &itemInfo) -{ - // update the Info - uint itemSlotId = itemInfo.slotId; - - const CItemImage *item = getServerItem(itemSlotId); - if (item && item->getItemId() > 0) - { - _ItemInfoCache.readFromImpulse(item->getItemId(), itemInfo); - } - - // write in map, from DB. - _ItemInfoMap[itemSlotId].readFromImpulse(itemInfo); - - // Look for Waiters that match this item slot => update - updateItemInfoWaiters(itemSlotId); - - // new msg to send? - updateItemInfoQueue(); -} - -// *************************************************************************** -void CInventoryManager::onRefreshItemInfoVersion(uint16 slotId, uint8 infoVersion) -{ - _ItemInfoMap[slotId].refreshInfoVersion(infoVersion); -} - -// *************************************************************************** -void CInventoryManager::onTradeChangeSession() -{ - // Dummy set a 255 InfoVersionMsg for all items in trade. Because Server cannot do the code. - for(uint i=0;iItemSlotId; - TItemInfoMap::iterator it= _ItemInfoMap.find(itemSlotId); - bool isItemFromTrading= (itemSlotId>>CItemInfos::SlotIdIndexBitSize)==INVENTORIES::trading; - if(it!=_ItemInfoMap.end()) - { - CClientItemInfo &itemInfo= it->second; - // If versions differ, and if a msg was not already sent to get the new version, then ask server - // SheetId must also match - if( itemInfo.InfoVersionFromSlot != itemInfo.InfoVersionFromMsg && - itemInfo.InfoVersionFromSlot != itemInfo.InfoVersionSlotServerWaiting && - ( isItemFromTrading || waiter->ItemSheet == getItemSheetForSlotId(itemSlotId)) ) - { - // Send a msg to server - if(!ClientCfg.Local) - { - CBitMemStream out; - if (GenericMsgHeaderMngr.pushNameToStream("ITEM_INFO:GET", out)) - { - uint16 slotId= itemSlotId; - out.serial( slotId ); - NetMngr.push(out); - //nlinfo("impulseCallBack : ITEM_INFO:GET %d sent", slotId); - } - else - { - nlwarning(" unknown message name 'ITEM_INFO:GET'"); - } - } - // Debug - else - { - // debug: - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - pIM->displaySystemInfo( toString("ITEM_INFO:GET, slotId: %d, slotVersion: %d", - itemSlotId, itemInfo.InfoVersionFromSlot) ); - } - - itemInfo.InfoVersionSlotServerWaiting= itemInfo.InfoVersionFromSlot; - } - } - } -} - -// *************************************************************************** -void CInventoryManager::debugItemInfoWaiters() -{ - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - - // For All waiters, log. - TItemInfoWaiters::iterator it; - for(it= _ItemInfoWaiters.begin();it!=_ItemInfoWaiters.end();it++) - { - IItemInfoWaiter *waiter=*it; - uint itemSlotId= waiter->ItemSlotId; - TItemInfoMap::iterator itMap= _ItemInfoMap.find(itemSlotId); - if(itMap!=_ItemInfoMap.end()) - { - CClientItemInfo &itemInfo= itMap->second; - pIM->displaySystemInfo( toString("ItemInfoWaiter: slotId: %d, slotVersion: %d, msgVersion: %d, msgVersionWait: %d", - itemSlotId, itemInfo.InfoVersionFromSlot, itemInfo.InfoVersionFromMsg, itemInfo.InfoVersionSlotServerWaiting) ); - } - } -} - -// *************************************************************************** -void CInventoryManager::debugItemInfoCache() const -{ - _ItemInfoCache.debugItemInfoCache(); -} - -// *************************************************************************** -void CInventoryManager::sortBag() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CDBGroupIconListBag *pIconList; - CDBGroupListSheetBag *pList; - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_BAG_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_BAG_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_ROOM_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_ROOM_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_GUILD_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_GUILD_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA0_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA0_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA1_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA1_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA2_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA2_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA3_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA3_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA4_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA4_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA5_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA5_TEXT)); - if (pList != NULL) pList->needToSort(); - - pIconList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA6_ICONS)); - if (pIconList != NULL) pIconList->needToSort(); - pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(LIST_PA6_TEXT)); - if (pList != NULL) pList->needToSort(); -} - -// *************************************************************************** -bool CInventoryManager::isInventoryPresent(INVENTORIES::TInventory invId) -{ - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - - // PA present? - if(invId>=INVENTORIES::pet_animal && invIdgetDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:STATUS", invId-INVENTORIES::pet_animal), false); - if(!node) return false; - uint status= node->getValue32(); - - return ANIMAL_STATUS::isSpawned((ANIMAL_STATUS::EAnimalStatus)status); - } - else if (invId == INVENTORIES::guild) - { - return (NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:INVENTORY_GUILD_OPENED", true)->getValue8() != 0); - } - else if (invId == INVENTORIES::player_room) - { - return (NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:INVENTORY_ROOM_OPENED", true)->getValue8() != 0); - } - // other inventories (Bag...) are always present - else - return true; -} - - -// *************************************************************************** -bool CInventoryManager::isInventoryAvailable(INVENTORIES::TInventory invId) -{ - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - - // PA available? - if(invId>=INVENTORIES::pet_animal && invIdgetDbProp(toString("SERVER:PACK_ANIMAL:BEAST%d:STATUS", invId-INVENTORIES::pet_animal), false); - if(!node) return false; - uint status= node->getValue32(); - - return ANIMAL_STATUS::isInventoryAvailable((ANIMAL_STATUS::EAnimalStatus)status); - } - else if (invId == INVENTORIES::guild) - { - return (NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:INVENTORY_GUILD_OPENED", true)->getValue8() != 0); - } - else if (invId == INVENTORIES::player_room) - { - return (NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:INVENTORY_ROOM_OPENED", true)->getValue8() != 0); - } - // other inventories (Bag...) are always available - else - return true; -} - -// *************************************************************************** -bool CInventoryManager::isInventoryEmpty(INVENTORIES::TInventory invId) -{ - if (!isInventoryPresent(invId)) return true; - - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - - string sPath = "SERVER:INVENTORY"; - sint32 nNbEntries = 256; - - // PA present? - if(invId>=INVENTORIES::pet_animal && invIdgetDbProp(sPath+toString(":%d:SHEET", i), false); - if (pNL == NULL) return true; - if (pNL->getValue32() != 0) - return false; - } - return true; -} - -// *************************************************************************** -CItemImage &CInventoryManager::getPAItem(uint beastIndex, uint index) -{ - nlassert(beastIndex < MAX_INVENTORY_ANIMAL); - nlassert(index < MAX_ANIMALINV_ENTRIES); - return PAInv[beastIndex][index]; -} - -// *************************************************************************** -CItemImage &CInventoryManager::getServerPAItem(uint beastIndex, uint index) -{ - nlassert(beastIndex < MAX_INVENTORY_ANIMAL); - nlassert(index < MAX_ANIMALINV_ENTRIES); - return ServerPAInv[beastIndex][index]; -} - -const CItemImage &CInventoryManager::getServerPAItem(uint beastIndex, uint index) const -{ - nlassert(beastIndex < MAX_INVENTORY_ANIMAL); - nlassert(index < MAX_ANIMALINV_ENTRIES); - return ServerPAInv[beastIndex][index]; -} - - -// *************************************************************************** -CItemImage &CInventoryManager::getLocalItem(uint inv, uint index) -{ - if(inv==INVENTORIES::bag) - return getBagItem(index); - if(inv>=INVENTORIES::pet_animal && inv=INVENTORIES::pet_animal && inv= INVENTORIES::pet_animal && inv getDbBranch("SERVER:GUILD:INVENTORY:" + toString(index)); - if (itemBranch) - { - static CItemImage image; - image.build(itemBranch); - return ℑ - } - } - return NULL; - } - else if (inv == INVENTORIES::player_room) - { - // player is in their room - if (getInventory().isInventoryAvailable(INVENTORIES::player_room)) - { - CCDBNodeBranch *itemBranch = NLGUI::CDBManager::getInstance()->getDbBranch(SERVER_INVENTORY ":ROOM:" + toString(index)); - if (itemBranch) - { - static CItemImage image; - image.build(itemBranch); - return ℑ - } - } - return NULL; - } - else if (inv == INVENTORIES::trading) - { - CCDBNodeBranch *itemBranch = NLGUI::CDBManager::getInstance()->getDbBranch("LOCAL:TRADING:" + toString(index)); - if (itemBranch) - { - static CItemImage image; - image.build(itemBranch); - return ℑ - } - } - else if (inv == INVENTORIES::exchange) - { - CCDBNodeBranch *itemBranch = NLGUI::CDBManager::getInstance()->getDbBranch("LOCAL:EXCHANGE:GIVE:" + toString(index)); - if (itemBranch) - { - static CItemImage image; - image.build(itemBranch); - return ℑ - } - } - else if (inv == INVENTORIES::exchange_proposition) - { - CCDBNodeBranch *itemBranch = NLGUI::CDBManager::getInstance()->getDbBranch("LOCAL:EXCHANGE:RECEIVE:" + toString(index)); - if (itemBranch) - { - static CItemImage image; - image.build(itemBranch); - return ℑ - } - } - else - { - nlwarning("getServerItem: invalid inventory %d for slotId %d", inv, slotId); - } - - // invalid inventory - return NULL; -} - -// *************************************************************************** -CInventoryManager::TInvType CInventoryManager::invTypeFromString(const string &str) -{ - string sTmp = toLower(str); - if (sTmp == "inv_bag") return InvBag; - if (sTmp == "inv_pa0") return InvPA0; - if (sTmp == "inv_pa1") return InvPA1; - if (sTmp == "inv_pa2") return InvPA2; - if (sTmp == "inv_pa3") return InvPA3; - if (sTmp == "inv_pa4") return InvPA4; - if (sTmp == "inv_pa5") return InvPA5; - if (sTmp == "inv_pa6") return InvPA6; - if (sTmp == "inv_guild") return InvGuild; - if (sTmp == "inv_room") return InvRoom; - return InvUnknown; -} - -// *************************************************************************** -void CInventoryManager::getSlotInvIndex(uint slotId, uint &inv, uint &index) const -{ - inv = slotId >> CItemInfos::SlotIdIndexBitSize; - index = slotId & CItemInfos::SlotIdIndexBitMask; -} - diff --git a/code/ryzom/client/src/login.cpp b/code/ryzom/client/src/login.cpp deleted file mode 100644 index 244bb593c..000000000 --- a/code/ryzom/client/src/login.cpp +++ /dev/null @@ -1,3331 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010-2019 Winch Gate Property Limited -// -// This source file has been modified by the following contributors: -// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014-2019 Jan BOON (Kaetemi) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - -////////////// -// Includes // -////////////// -#include "stdpch.h" - -#include "login.h" -#include "login_patch.h" - -#include "nel/misc/common.h" -#include "nel/misc/debug.h" -#include "nel/misc/path.h" -#include "nel/misc/thread.h" -#include "nel/misc/big_file.h" -#include "nel/misc/system_utils.h" -#include "nel/misc/streamed_package_manager.h" - -#include "nel/net/tcp_sock.h" -#include "nel/3d/u_driver.h" -#include "nel/misc/big_file.h" - -#include "interface_v3/interface_manager.h" -#include "interface_v3/input_handler_manager.h" -#include "nel/gui/group_editbox.h" -#include "interface_v3/group_quick_help.h" -#include "nel/gui/view_text.h" -#include "nel/gui/ctrl_button.h" -#include "nel/gui/ctrl_text_button.h" -#include "nel/gui/dbgroup_combo_box.h" -#include "sound_manager.h" -#include "far_tp.h" - -#include "actions_client.h" -#include "time_client.h" -#include "client_cfg.h" -#include "global.h" -#include "input.h" -#include "nel/gui/libwww.h" -#include "nel/web/http_client_curl.h" -#include "login_progress_post_thread.h" - -#include "init.h" -#include "release.h" -#include "bg_downloader_access.h" - -#include "game_share/crypt.h" -#include "game_share/bg_downloader_msg.h" - -#include "misc.h" -#include "user_agent.h" - -void ConnectToShard(); - -// *************************************************************************** - -using namespace NLMISC; -using namespace NLWEB; -using namespace NLNET; -using namespace NL3D; -using namespace std; - -#ifdef DEBUG_NEW -#define new DEBUG_NEW -#endif - -// *************************************************************************** - -extern bool SetMousePosFirstTime; - -vector Shards; - -string LoginLogin, LoginPassword, ClientApp, Salt, LoginCustomParameters; -uint32 LoginShardId = 0xFFFFFFFF; - - -// Completed only after that ryzom downloader has run its 'check' task : -// It is a bitfield indexed by BGDownloader::TDownloadID that indicate the parts that are available for patch -uint32 AvailablePatchs = 0; -// next wanted patch for the background downloader -BGDownloader::TDownloadID BGDownloaderWantedPatch = BGDownloader::DownloadID_RoS; - - - -// R2 mode var --------------- - -/// domain server version for patch -string R2ServerVersion; -/// name of the version (used to alias many version under the same name), -/// the value is used to get the release not if not empty -string VersionName; -/// Backup patch server to use in case of failure of all other servers -string R2BackupPatchURL; -/// a list of patch server to use randomly -vector R2PatchURLs; - - -#define CTRL_EDITBOX_LOGIN "ui:login:checkpass:content:eb_login:eb" -#define CTRL_EDITBOX_PASSWORD "ui:login:checkpass:content:eb_password:eb" -#define GROUP_LIST_SHARD "ui:login:sharddisp:content:shard_list" -#define CTRL_BUTTON_CONNECT "ui:login:sharddisp:content:but_con" -#define GROUP_LIST_CAT "ui:login:catdisp:content:cat_list" -#define CTRL_BUTTON_CLOSE_PATCH "ui:login:patching:content:but_close" -#define VIEW_TOTAL_SIZE "ui:login:catdisp:content:global_patch:size" -#define VIEW_NON_OPTIONAL_SIZE "ui:login:catdisp:content:nonopt_patch:size" -#define VIEW_TOTAL_SIZE_PATCH "ui:login:patching:content:global_patch:size" -#define CTRL_BUTTON_BACKTOLOGIN "ui:login:webstart:content:back_to_login" -#define CTRL_BUTTON_RELOADTESTPAGE "ui:login:webstart:content:reload_test_page" -#define CTRL_EDITBOX_CREATEACCOUNT_LOGIN "ui:login:create_account:content:submit_gr:eb_login:eb" -#define CTRL_EDITBOX_CREATEACCOUNT_PASSWORD "ui:login:create_account:content:submit_gr:eb_password:eb" -#define CTRL_EDITBOX_CREATEACCOUNT_CONFIRMPASSWORD "ui:login:create_account:content:submit_gr:eb_confirm_password:eb" -#define CTRL_EDITBOX_CREATEACCOUNT_EMAIL "ui:login:create_account:content:submit_gr:eb_email:eb" - -#define UI_VARIABLES_SCREEN_CHECKPASS 0 -#define UI_VARIABLES_SCREEN_SHARDDISP 1 -#define UI_VARIABLES_SCREEN_CHECKING 2 -#define UI_VARIABLES_SCREEN_CATDISP 3 -#define UI_VARIABLES_SCREEN_PATCHING 4 -#define UI_VARIABLES_SCREEN_REBOOT 5 -#define UI_VARIABLES_SCREEN_EULA 6 -#define UI_VARIABLES_SCREEN_DATASCAN 7 -#define UI_VARIABLES_SCREEN_CREATE_ACCOUNT 9 - - -// *************************************************************************** -// *************************************************************************** -// *************************************************************************** -// INTERFACE -// *************************************************************************** -// *************************************************************************** -// *************************************************************************** - -bool loginFinished = false; -bool loginOK = false; -sint32 ShardSelected = -1; -CPatchManager::SPatchInfo InfoOnPatch; -uint32 TotalPatchSize; - -CLoginStateMachine LoginSM; - -// TODO : nico : put this in an external file, this way it isn't included by the background downloader -#ifndef RY_BG_DOWNLOADER - -bool CStartupHttpClient::connectToLogin() -{ - bool checkConnect = connect(ClientCfg.ConfigFile.getVar("StartupHost").asString(0)); - - if (ClientCfg.ConfigFile.exists("StartupVerify")) - checkConnect = checkConnect && verifyServer(ClientCfg.ConfigFile.getVar("StartupVerify").asBool(0)); - - return checkConnect; -} - -CStartupHttpClient HttpClient; -#endif // RY_BG_DOWNLOADER - - -// *************************************************************************** -#define WIN_COMBO_BOX_SELECT_MENU "ui:interface:combo_box_select_menu" -#define WIN_COMBO_BOX_MEASURE_MENU "ui:interface:combo_box_measure_menu" -#define WIN_COMBO_BOX_SELECT_MENU_OUTGAME "ui:outgame:combo_box_select_menu" -#define WIN_COMBO_BOX_SELECT_MENU_LOGIN "ui:login:combo_box_select_menu" -#define WIN_COMBO_BOX_MEASURE_MENU_LOGIN "ui:login:combo_box_measure_menu" - -bool isLoginFinished() -{ - return loginFinished; -} - -void setLoginFinished( bool f ) -{ - loginFinished = f; - if( loginFinished ) - { - CDBGroupComboBox::measureMenu.assign( WIN_COMBO_BOX_MEASURE_MENU ); - CDBGroupComboBox::selectMenu.assign( WIN_COMBO_BOX_SELECT_MENU ); - } - else - { - CDBGroupComboBox::measureMenu.assign( WIN_COMBO_BOX_MEASURE_MENU_LOGIN ); - CDBGroupComboBox::selectMenu.assign( WIN_COMBO_BOX_SELECT_MENU_LOGIN ); - } -} - - -// *************************************************************************** -// Pop a fatal error message box, giving the option to 'quit' the client, plus a help button -static void fatalMessageBox(const ucstring &msg) -{ - CInterfaceManager *im = CInterfaceManager::getInstance(); - im->messageBoxWithHelp(msg, "ui:login", "login_quit"); -} - -// *************************************************************************** -// Pop an error message box, giving the option to go back to main menu, plus a help button -static void errorMessageBox(const ucstring &msg) -{ - CInterfaceManager *im = CInterfaceManager::getInstance(); - im->messageBoxWithHelp(msg, "ui:login", "on_back_to_login"); -} - -// *************************************************************************** -void createOptionalCatUI() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CAT)); - if (pList == NULL) - { - nlwarning("element " GROUP_LIST_CAT " not found probably bad login_main.xml"); - return; - } - - // Update optional categories - - CInterfaceGroup *pPrevLine = NULL; - for(uint i = 0; i < InfoOnPatch.OptCat.size(); i++) - { - vector< pair < string, string > > params; - params.clear(); - params.push_back(pair("id", "c"+toString(i))); - if (i>0) - params.push_back(pair("posref", "BL TL")); - - CInterfaceGroup *pNewLine = CWidgetManager::getInstance()->getParser()->createGroupInstance("t_cat", GROUP_LIST_CAT, params); - if (pNewLine != NULL) - { - CViewText *pVT = dynamic_cast(pNewLine->getView("name")); - if (pVT != NULL) pVT->setText(InfoOnPatch.OptCat[i].Name); - pVT = dynamic_cast(pNewLine->getView("size")); - if (pVT != NULL) - { - pVT->setText(BGDownloader::getWrittenSize(InfoOnPatch.OptCat[i].Size)); - } - - // Add to the list - pNewLine->setParent(pList); - pNewLine->setParentSize(pList); - pNewLine->setParentPos(pPrevLine); - pList->addGroup(pNewLine); - - pPrevLine = pNewLine; - } - } - pList->invalidateCoords(); -} - -// *************************************************************************** -void initEula() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - if (!ClientCfg.SkipEULA && CFile::fileExists(getLogDirectory() + "show_eula")) - { - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_EULA); - - // if we display the eula, it means we make a patch so we clean the cache directory - // (clear cache after each patch) - nlinfo("Deleting cached files"); - vector cached; - CPath::getPathContent("cache", true, false, true, cached); - for(uint i = 0; i < cached.size(); i++) - CFile::deleteFile(cached[i]); - } - else - { - CAHManager::getInstance()->runActionHandler("accept_eula", NULL); - } -} - -// *************************************************************************** -static void setDataScanLog(const ucstring &text) -{ - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:datascan:content:log_txt:log")); - if (pVT != NULL) - { - pVT->setText(text); - } -} - -// *************************************************************************** -static void setDataScanState(const ucstring &text, ucstring progress= ucstring()) -{ - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:datascan:content:state")); - if (pVT != NULL) pVT->setText(text); - - pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:datascan:content:progress")); - if (pVT != NULL) pVT->setText(progress); -} - -void initCatDisplay() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CPatchManager *pPM = CPatchManager::getInstance(); - - // Check is good now ask the player if he wants to apply the patch - pPM->getInfoToDisp(InfoOnPatch); - - if ((!InfoOnPatch.NonOptCat.empty()) || - (!InfoOnPatch.OptCat.empty()) || - (!InfoOnPatch.ReqCat.empty())) - { - createOptionalCatUI(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CATDISP); - } - else - { - LoginSM.pushEvent(CLoginStateMachine::ev_run_patch); -// CAHManager::getInstance()->runActionHandler("login_patch", NULL); - } -} - -void initReboot() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_REBOOT); -} - - -// *************************************************************************** -static void setPatcherStateText(const std::string &baseUIPath, const ucstring &str) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(baseUIPath + ":content:state")); - if (pVT != NULL) - { - pVT->setText(str); - } -} - -// *************************************************************************** -static void setPatcherProgressText(const std::string &baseUIPath, const ucstring &str) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(baseUIPath + ":content:progress")); - if (pVT != NULL) - { - pVT->setText(str); - } -} - -// *************************************************************************** -static void updatePatchingInfoText(const std::string &baseUIPath) -{ - CPatchManager *pPM = CPatchManager::getInstance(); - CBGDownloaderAccess &bgDownloader = CBGDownloaderAccess::getInstance(); - if (isBGDownloadEnabled()) - { - bgDownloader.update(); - if (bgDownloader.getDownloadThreadPriority() == BGDownloader::ThreadPriority_Paused) - { - setPatcherStateText(baseUIPath, CI18N::get("uiBGD_Paused")); - setPatcherProgressText(baseUIPath, ucstring()); - } - else - { - setPatcherStateText(baseUIPath, bgDownloader.getCurrentMessage()); - if (bgDownloader.getTotalFilesToGet() != 0) - { - setPatcherProgressText(baseUIPath, toString("%d/%d", (int) bgDownloader.getCurrentFilesToGet(), (int) bgDownloader.getTotalFilesToGet())); - } - else - { - setPatcherProgressText(baseUIPath, ucstring()); - } - } - } - else - { - ucstring state; - vector log; - if(pPM->getThreadState(state, log)) - { - setPatcherStateText(baseUIPath, state); - if (pPM->getTotalFilesToGet() != 0) - { - setPatcherProgressText(baseUIPath, toString("%d/%d", pPM->getCurrentFilesToGet(), pPM->getTotalFilesToGet())); - } - else - { - setPatcherProgressText(baseUIPath, ucstring()); - } - } - } -} - -// *************************************************************************** -// Main loop of the login step -void loginMainLoop() -{ - CDBGroupComboBox::selectMenuOut.assign( WIN_COMBO_BOX_SELECT_MENU_OUTGAME ); - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CPatchManager *pPM = CPatchManager::getInstance(); - - CBGDownloaderAccess &bgDownloader = CBGDownloaderAccess::getInstance(); - - bool windowBlinkDone = false; - bool fatalMessageBoxShown = false; - - while (LoginSM.getCurrentState() != CLoginStateMachine::st_connect - && LoginSM.getCurrentState() != CLoginStateMachine::st_end - && LoginSM.getCurrentState() != CLoginStateMachine::st_ingame) -// while (loginFinished == false) - { - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - // Update the DT T0 and T1 global variables - updateClientTime(); - - - - CInputHandlerManager::getInstance()->pumpEvents(); - Driver->clearBuffers(CRGBA::Black); - Driver->setMatrixMode2D11(); - - // Update sound - if (SoundMngr != NULL) - SoundMngr->update(); - - // Interface handling & displaying - pIM->updateFrameEvents(); - pIM->updateFrameViews(NULL); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - - -// if (::GetAsyncKeyState(VK_SPACE)) -// { -// pIM->displayUIViewBBoxs(""); -// pIM->displayUICtrlBBoxs(""); -// pIM->displayUIGroupBBoxs(""); -// } - - // Force the client to sleep a bit. - if(ClientCfg.Sleep >= 0) - { - nlSleep(ClientCfg.Sleep); - } - // Display - Driver->swapBuffers(); - -// sint32 screen = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->getValue32(); - if (LoginSM.getCurrentState() == CLoginStateMachine::st_check_patch) -// if (screen == UI_VARIABLES_SCREEN_CHECKING) // If we are in checking mode - { - nlSleep(10); // For the checking thread - bool res = false; - BGDownloader::TTaskResult taskResult = BGDownloader::TaskResult_Unknown; - bool finished = false; - ucstring bgDownloaderError; - if (isBGDownloadEnabled()) - { - finished = bgDownloader.isTaskEnded(taskResult, bgDownloaderError); - } - else - { - finished = pPM->isCheckThreadEnded(res); - } - - if (finished) - { - setPatcherStateText("ui:login:checking", ucstring()); - setPatcherProgressText("ui:login:checking", ucstring()); - - if (isBGDownloadEnabled()) - { - AvailablePatchs = bgDownloader.getAvailablePatchs(); - #ifdef NL_OS_WINDOWS - { - // Get the window - HWND hWnd = Driver->getDisplay(); - nlassert (hWnd); - // Show the window, unless it has been minimized, in - // which case we don't pop it unexpectedly - if (!windowBlinkDone) - { - bgDownloader.hideDownloader(); - ShowWindow (hWnd, SW_RESTORE); - windowBlinkDone = true; - } - - } - #endif - switch(taskResult) - { - case BGDownloader::TaskResult_Success: - if (AvailablePatchs & (1 << BGDownloaderWantedPatch)) // is there a patch for what we want now ? - { - LoginSM.pushEvent(CLoginStateMachine::ev_patch_needed); - } - else - { - LoginSM.pushEvent(CLoginStateMachine::ev_no_patch); - } - break; - case BGDownloader::TaskResult_Error: - { - if (!fatalMessageBoxShown) - { - fatalMessageBox(bgDownloaderError); - fatalMessageBoxShown = true; - } - } - break; - default: - if (!fatalMessageBoxShown) - { - fatalMessageBox(CI18N::get("uiErrChecking")); - fatalMessageBoxShown = true; - } - break; - } - - } - else - { - if(res) - { - // Check is good now ask the player if he wants to apply the patch - pPM->getInfoToDisp(InfoOnPatch); - - AvailablePatchs = InfoOnPatch.getAvailablePatchsBitfield(); - - if ((!InfoOnPatch.NonOptCat.empty()) || - (!InfoOnPatch.OptCat.empty()) || - (!InfoOnPatch.ReqCat.empty())) - { - LoginSM.pushEvent(CLoginStateMachine::ev_patch_needed); - // createOptionalCatUI(); - // NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CATDISP); - } - else - { - LoginSM.pushEvent(CLoginStateMachine::ev_no_patch); - // CAHManager::getInstance()->runActionHandler("login_patch", NULL); - } - } - else - { - ucstring errMsg = CI18N::get("uiErrChecking"); - if (!pPM->getLastErrorMessage().empty()) - { - errMsg = pPM->getLastErrorMessage(); - } - if (!fatalMessageBoxShown) - { - fatalMessageBox(errMsg); - fatalMessageBoxShown = true; - } - } - } - } - else - { - // update interface content - updatePatchingInfoText("ui:login:checking"); - } - } -// else if (screen == UI_VARIABLES_SCREEN_DATASCAN) // If we are in ScanData mode - else if (LoginSM.getCurrentState() == CLoginStateMachine::st_scan_data) - { - nlSleep(10); // For the checking thread - - bool res; - if (pPM->isScanDataThreadEnded(res)) - { - // if interface consider it was running before - if(NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:DATASCAN_RUNNING")->getValue32()!=0) - { - // no more running - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:DATASCAN_RUNNING")->setValue32(0); - - if(res) - { - // touch any file with checksum error, and get their number - uint numFiles= pPM->applyScanDataResult(); - - // Report result - if(numFiles==0) - setDataScanState(CI18N::get("uiScanDataSucess")); - else - { - ucstring fmt= CI18N::get("uiScanDataErrors"); - strFindReplace(fmt, "%d", toString(numFiles)); - setDataScanState(fmt); - } - } - else - { - ucstring errMsg = CI18N::get("uiErrDataScanning"); - if (!pPM->getLastErrorMessage().empty()) - { - errMsg = pPM->getLastErrorMessage(); - } - pIM->messageBoxWithHelp(errMsg, "ui:login"); - } - - // the log may have changed - ucstring dsLog; - if(pPM->getDataScanLog(dsLog)) - setDataScanLog(dsLog); - } - } - else - { - // update inteface content - ucstring state; - vector log; - // get state - if(pPM->getThreadState(state, log)) - { - // set state - setDataScanState(state, toString("%d/%d", pPM->getCurrentFilesToGet(), pPM->getTotalFilesToGet())); - } - // set special data scan log - ucstring dsLog; - if(pPM->getDataScanLog(dsLog)) - setDataScanLog(dsLog); - } - } -// else if (screen == UI_VARIABLES_SCREEN_PATCHING) // If we are in patching mode - else if (LoginSM.getCurrentState() == CLoginStateMachine::st_patch) - { - nlSleep(30); // For the patching thread - - int currentPatchingSize; - int totalPatchSize; - - - if (isBGDownloadEnabled()) - { - currentPatchingSize = bgDownloader.getPatchingSize(); - totalPatchSize = bgDownloader.getTotalSize(); - BGDownloader::TTaskResult taskResult; - bool finished = false; - ucstring bgDownloaderError; - finished = bgDownloader.isTaskEnded(taskResult, bgDownloaderError); - if (finished) - { - //bgDownloader.hideDownloader(); - // restore the search paths (all bnp files were removed from CPath to allows - // the patcher to overwrite them) - - // create a file to prompt eula next time - CFile::createEmptyFile(getLogDirectory() + "show_eula"); - - if (taskResult == BGDownloader::TaskResult_Error) - { - setPatcherStateText("ui:login:patching", ucstring()); - setPatcherProgressText("ui:login:patching", ucstring()); - - if (!fatalMessageBoxShown) - { - fatalMessageBox(bgDownloaderError); - fatalMessageBoxShown = true; - } - } - else - { - bgDownloader.getPatchCompletionFlag(true /* clear flag */); - LoginSM.pushEvent(CLoginStateMachine::ev_close_patch); - } - } - else - { - updatePatchingInfoText("ui:login:patching"); - } - } - else - { - totalPatchSize = TotalPatchSize; - currentPatchingSize = pPM->getPatchingSize(); - bool res; - if (pPM->isPatchThreadEnded(res)) - { - if(res) - { - LoginSM.pushEvent(CLoginStateMachine::ev_close_patch); - } - else - { - ucstring errMsg = CI18N::get("uiErrPatchApply"); - if (!pPM->getLastErrorMessage().empty()) - { - errMsg = pPM->getLastErrorMessage(); - } - if (!fatalMessageBoxShown) - { - fatalMessageBox(errMsg); - fatalMessageBoxShown = true; - } - } - } - else - { - updatePatchingInfoText("ui:login:patching"); - } - } - - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(VIEW_TOTAL_SIZE_PATCH)); - ucstring sTmp; - sTmp = BGDownloader::getWrittenSize(currentPatchingSize); - sTmp += " / " + BGDownloader::getWrittenSize(totalPatchSize); - if (pVT != NULL) pVT->setText(sTmp); - } -// else if (screen == UI_VARIABLES_SCREEN_CATDISP) // If we are displaying patch info - else if (LoginSM.getCurrentState() == CLoginStateMachine::st_display_cat) - { - // Non optional stuff (non opt cat and req cat) - - // Add req cat size : given the optional cat we determines the required cat - uint32 nNonOptSize = 0; - TotalPatchSize = 0; - vector ReqCat; - CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CAT)); - if (pList != NULL) - { - for(uint i = 0; i < InfoOnPatch.OptCat.size(); i++) - { - CInterfaceGroup *pLine = pList->getGroup("c"+toString(i)); - if (pLine != NULL) - { - CCtrlButton *pCB = dynamic_cast(pLine->getCtrl("on_off")); - if ((pCB != NULL) && (pCB->getPushed())) - { - TotalPatchSize += InfoOnPatch.OptCat[i].Size; - if (InfoOnPatch.OptCat[i].Req != -1) - { - uint32 j; - for (j = 0; j < ReqCat.size(); ++j) - if (ReqCat[j] == InfoOnPatch.OptCat[i].Req) - break; - // Add just once the req cat size to the non optional size - if (j == ReqCat.size()) - { - ReqCat.push_back(InfoOnPatch.OptCat[i].Req); - nNonOptSize += InfoOnPatch.ReqCat[InfoOnPatch.OptCat[i].Req].Size; - } - } - } - } - } - } - - // Add non optional cats - for (uint32 i = 0; i < InfoOnPatch.NonOptCat.size(); ++i) - nNonOptSize += InfoOnPatch.NonOptCat[i].Size; - - TotalPatchSize += nNonOptSize; - // Total size of the patches is optional cats + required cat (f(optCat)) + non opt cat - - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(VIEW_TOTAL_SIZE)); - if (pVT != NULL) pVT->setText(BGDownloader::getWrittenSize(TotalPatchSize)); - - pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(VIEW_NON_OPTIONAL_SIZE)); - if (pVT != NULL) pVT->setText(BGDownloader::getWrittenSize(nNonOptSize)); - } - } -} - -void initLoginScreen() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CPatchManager *pPM = CPatchManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKPASS); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:DISPLAY_ACCOUNT_BUTTONS")->setValue32(ClientCfg.DisplayAccountButtons); - - // Active inputs - Actions.enable(true); - EditActions.enable(true); - - if(ClientCfg.ConfigFile.exists("VerboseLog")) - pPM->setVerboseLog(ClientCfg.ConfigFile.getVar("VerboseLog").asInt() == 1); - if(pPM->isVerboseLog()) nlinfo("Using verbose log mode"); - - ClientApp = ClientCfg.ConfigFile.getVar("Application").asString(0); - - // version - std::string ext; - if (ClientApp.find("ryzom_") != ucstring::npos) - ext = " (" + ClientApp.substr(6) + ")"; - - CViewText *pV = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:checkpass:content:ver_value")); - if (pV) - pV->setHardText(getDisplayVersion() + (ext.empty() ? "" : ext)); - - // give priority to login specified as argument - string l = !LoginLogin.empty() ? LoginLogin:ClientCfg.LastLogin; - - if(!l.empty()) - { - CGroupEditBox *pGEB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN)); - if (pGEB != NULL && (pGEB->getInputString().empty())) - { - pGEB->setInputString(l); - } - CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_PASSWORD "|select_all=false"); - } - else - { - CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_LOGIN "|select_all=false"); - } - - - CCtrlTextButton *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_BUTTON_CONNECT)); - if (pCB != NULL) pCB->setActive(false); - - setLoginFinished( false ); - loginOK = false; -} - -void initAutoLogin() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupEditBox *pGEBLog = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN)); - CGroupEditBox *pGEBPwd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_PASSWORD)); - pGEBLog->setInputString(LoginLogin); - pGEBPwd->setInputString(LoginPassword); - CAHManager::getInstance()->runActionHandler("on_login", NULL, ""); - - if (ClientCfg.R2Mode) - { - LoginSM.pushEvent(CLoginStateMachine::ev_login_ok); - } - else - { - // Select good shard - ShardSelected = -1; - for (uint32 i = 0; i < Shards.size(); ++i) - { - if (Shards[i].ShardId == LoginShardId) - { - ShardSelected = i; - break; - } - } - - if (ShardSelected == -1) - { - pIM->messageBoxWithHelp(CI18N::get("uiErrServerLost"), "ui:login"); - LoginSM.pushEvent(CLoginStateMachine::ev_quit); - } - else - { - LoginSM.pushEvent(CLoginStateMachine::ev_login_ok); - // CAHManager::getInstance()->runActionHandler("login_connect_2", NULL); - } - } -} - -void initAltLogin() -{ - // Check the alt param - if (!LoginCustomParameters.empty() && LoginCustomParameters != "&dbg=1") - { - // don't use login and password for alternate login - string res = checkLogin("", "", ClientApp, LoginCustomParameters); - if (res.empty()) - { - if (ClientCfg.R2Mode) - { - LoginSM.pushEvent(CLoginStateMachine::ev_login_ok); - } - else - { - // Select good shard - ShardSelected = -1; - for (uint32 i = 0; i < Shards.size(); ++i) - { - if (Shards[i].ShardId == LoginShardId) - { - ShardSelected = i; - break; - } - } - - if (ShardSelected == -1) - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - pIM->messageBoxWithHelp(CI18N::get("uiErrServerLost"), "ui:login"); - LoginSM.pushEvent(CLoginStateMachine::ev_quit); - } - else - { - LoginSM.pushEvent(CLoginStateMachine::ev_login_ok); - } - } - - return; - } - } - - // close the socket in case of error - HttpClient.disconnect(); - - // ignore error - LoginSM.pushEvent(CLoginStateMachine::ev_login_not_alt); -} - - -// *************************************************************************** -// Called from client.cpp -bool login() -{ - CLoginProgressPostThread::getInstance().step(CLoginStep(LoginStep_LoginScreen, "login_step_login_screen")); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CPatchManager *pPM = CPatchManager::getInstance(); - - if (LoginLogin.empty()) - loginIntro(); - - pIM->initLogin(); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - - SetMousePosFirstTime = true; - InitMouseWithCursor(false); - Driver->showCursor (false); - SetMouseFreeLook (); - SetMouseCursor (false); - SetMouseSpeed (ClientCfg.CursorSpeed); - SetMouseAcceleration (ClientCfg.CursorAcceleration); - SetMousePosFirstTime = true; - InitMouseWithCursor (ClientCfg.HardwareCursor && !StereoDisplayAttached); - -// if (ClientCfg.TestBrowser) -// { -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_WEBSTART); -// -// // hide 'back to login' button -// CInterfaceElement *backToLogin = CWidgetManager::getInstance()->getElementFromId(CTRL_BUTTON_BACKTOLOGIN); -// if (backToLogin) -// backToLogin->setActive(false); -// -// // show 'reload test page' button -// CInterfaceElement *reloadTest = CWidgetManager::getInstance()->getElementFromId(CTRL_BUTTON_RELOADTESTPAGE); -// if (reloadTest) -// reloadTest->setActive(true); -// -// // start the browser -// CGroupHTML *pGH = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_BROWSER)); -// -// pGH->browse(ClientCfg.TestBrowserUrl.c_str()); -// -// } -// else -// { -//// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKPASS); -//// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:DISPLAY_ACCOUNT_BUTTONS")->setValue32(ClientCfg.DisplayAccountButtons); -// } - - // Active inputs - Actions.enable(true); - EditActions.enable(true); - - if(ClientCfg.ConfigFile.exists("VerboseLog")) - pPM->setVerboseLog(ClientCfg.ConfigFile.getVar("VerboseLog").asInt() == 1); - if(pPM->isVerboseLog()) nlinfo("Using verbose log mode"); - - ClientApp = ClientCfg.ConfigFile.getVar("Application").asString(0); - -// string l = getRegKeyValue("Login").c_str(); -// -// if(!l.empty()) -// { -// CGroupEditBox *pGEB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN)); -// if (pGEB != NULL) -// pGEB->setInputString(l); -// CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_PASSWORD "|select_all=false"); -// } -// else -// { -// CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_LOGIN "|select_all=false"); -// } - - ShardSelected = -1; -// CCtrlTextButton *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_BUTTON_CONNECT)); -// if (pCB != NULL) pCB->setActive(false); -// -// setLoginFinished( false ); -// loginFinished = false; -// loginOK = false; - - // Comes from a current patch -// if (!LoginLogin.empty()) -// { -// CInterfaceManager *pIM = CInterfaceManager::getInstance(); -// CGroupEditBox *pGEBLog = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN)); -// CGroupEditBox *pGEBPwd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_PASSWORD)); -// pGEBLog->setInputString(LoginLogin); -// pGEBPwd->setInputString(LoginPassword); -// CAHManager::getInstance()->runActionHandler("on_login", NULL, ""); -// // Select good shard -// ShardSelected = -1; -// for (uint32 i = 0; i < Shards.size(); ++i) -// { -// if (Shards[i].ShardId == LoginShardId) -// { -// ShardSelected = i; -// break; -// } -// } -// -// if (ShardSelected == -1) -// pIM->messageBox(CI18N::get("uiErrServerLost"), "ui:login"); -// else -// CAHManager::getInstance()->runActionHandler("login_connect_2", NULL); -// } - - // start the login state machine - LoginSM.pushEvent(CLoginStateMachine::ev_init_done); - - // run the main loop - loginMainLoop(); - - // Uninit all - pIM->uninitLogin(); - - // Disable inputs - Actions.enable(false); - EditActions.enable(false); - - return loginOK; -} - -// *************************************************************************** -// INTERFACE HELPERS -// *************************************************************************** - -// *************************************************************************** -void removeSpace(string &s) -{ - uint i = 0; - while (!s.empty()) - { - if (s[i] == ' ') - s.erase(i, 1); - else - i++; - if (i >= s.size()) break; - } -} - -// *************************************************************************** -static void getPatchParameters(std::string &url, std::string &ver, std::vector &patchURIs) -{ - if (ClientCfg.R2Mode) - { - url = ClientCfg.PatchUrl; - ver = ClientCfg.PatchVersion; - - // if PatchUrl is forced, don't use URLs returned by server - if (url.empty()) - { - patchURIs = R2PatchURLs; - url = R2BackupPatchURL; - ver = R2ServerVersion; - } - } - else - { - nlassert(ShardSelected != -1); - patchURIs = Shards[ShardSelected].PatchURIs; - url = Shards[ShardSelected].EmergencyPatchURL; - ver = Shards[ShardSelected].Version; - - if (!ClientCfg.PatchUrl.empty()) - url = ClientCfg.PatchUrl; - - if (!ClientCfg.PatchVersion.empty()) - ver = ClientCfg.PatchVersion; - } -} - -// *************************************************************************** -std::string getBGDownloaderCommandLine() -{ - #ifdef NL_DEBUG - CConfigFile::CVar *bgdCommandLine = ClientCfg.ConfigFile.getVarPtr("BackgroundDownloaderCommandLine"); - if (bgdCommandLine != NULL && !bgdCommandLine->asString().empty()) - { - return bgdCommandLine->asString(); - } - #endif - string url; - string ver; - std::vector patchURIs; - getPatchParameters(url, ver, patchURIs); - std::string commandLine = /*R2ServerVersion + " " + VersionName + " " + */ url + " " + ver; - for (uint i = 0; i < patchURIs.size(); ++i) - { - commandLine += " " + patchURIs[i]; - } - return commandLine; -} - -// *************************************************************************** -void initPatchCheck() -{ - // start the patching system - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CPatchManager *pPM = CPatchManager::getInstance(); - - string url; - string ver; - std::vector patchURIs; - - if (!ClientCfg.R2Mode) - { - // nb Nico : refactored this code. - // In previous code, the following was not set in R2Mode, possible bug ?...let as before anyway ... - // store the selected shard for restarting after patch - LoginShardId = Shards[ShardSelected].ShardId; - } - - if (!isBGDownloadEnabled()) - { - getPatchParameters(url, ver, patchURIs); - pPM->init(patchURIs, url, ver); - pPM->startCheckThread(true /* include background patchs */); - } - else - { - BGDownloader::CTaskDesc taskDesc(BGDownloader::DLState_CheckPatch); - CBGDownloaderAccess::getInstance().requestDownloadThreadPriority(BGDownloader::ThreadPriority_Normal, false); - CBGDownloaderAccess::getInstance().startTask(taskDesc, getBGDownloaderCommandLine(), true /* showDownloader */); - } - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKING); - - setPatcherStateText("ui:login:checking", ucstring()); - setPatcherProgressText("ui:login:checking", ucstring()); -} - -void initShardDisplay() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_SHARDDISP); - - CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_SHARD)); - if (pList == NULL) - { - nlwarning("element " GROUP_LIST_SHARD " not found probably bad login_main.xml"); - return; - } - /* // To test more servers - for (uint fff = 0; fff < 20; ++fff) - { - CShard s ( toString("%05d",fff), fff%3, fff+32, toString("%s%d","pipo",fff), - 32*fff%46546, "32.32.32.32", "http://www.ryzom.com" ); - Shards.push_back(s); - }*/ - - CInterfaceGroup *pPrevLine = NULL; - for(uint i = 0; i < Shards.size(); i++) - { - vector< pair < string, string > > params; - params.clear(); - params.push_back(pair("id", "s"+toString(i))); - if (i>0) - params.push_back(pair("posref", "BL TL")); - - CInterfaceGroup *pNewLine = CWidgetManager::getInstance()->getParser()->createGroupInstance("t_shard", GROUP_LIST_SHARD, params); - if (pNewLine != NULL) - { - CViewText *pVT = dynamic_cast(pNewLine->getView("name")); - if (pVT != NULL) pVT->setText(Shards[i].Name); - - pVT = dynamic_cast(pNewLine->getView("version")); - if (pVT != NULL) pVT->setText(Shards[i].Version); - - CViewBase *pVBon = pNewLine->getView("online"); - CViewBase *pVBoff = pNewLine->getView("offline"); - if ((pVBon != NULL) && (pVBoff != NULL)) - { - pVBon->setActive (Shards[i].Online); - pVBoff->setActive (!Shards[i].Online); - } - - pVT = dynamic_cast(pNewLine->getView("nbplayer")); - if (pVT != NULL) pVT->setText(toString(Shards[i].NbPlayers)); - - - // Add to the list - pNewLine->setParent(pList); - pNewLine->setParentSize(pList); - pNewLine->setParentPos(pPrevLine); - pList->addGroup(pNewLine); - - pPrevLine = pNewLine; - } - } - // UI Patch - if (!Shards.empty()) - { - CCtrlButton *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_SHARD ":s0:but")); - if (pCB != NULL) - pCB->setPushed(true); - CAHManager::getInstance()->runActionHandler (pCB->getActionOnLeftClick(), pCB, pCB->getParamsOnLeftClick()); - - } - pList->invalidateCoords(); -} - -// *************************************************************************** - -void onlogin(bool vanishScreen = true) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - // Remove space before and after each string login & password - removeSpace(LoginLogin); - removeSpace(LoginPassword); - - if(!LoginLogin.empty()) - { - ClientCfg.LastLogin = LoginLogin; - ClientCfg.writeString("LastLogin", ClientCfg.LastLogin, true); - } - - if(vanishScreen) - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(-1); - - // Check the login/pass - - // main menu page for r2mode - string res = checkLogin(LoginLogin, LoginPassword, ClientApp, LoginCustomParameters); - if (res.empty()) - { - // if not in auto login, push login ok event - if (LoginSM.getCurrentState() != CLoginStateMachine::st_auto_login) - LoginSM.pushEvent(CLoginStateMachine::ev_login_ok); - - return; - // Ok there is something ! Display next window - - if (ClientCfg.R2Mode) - { -// if (ClientCfg.PatchWanted) -// { -// // start the patching system -// CPatchManager *pPM = CPatchManager::getInstance(); -// -// pPM->init(R2PatchURLs, R2BackupPatchURL, R2ServerVersion); -// -// pPM->startCheckThread(); -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKING); -// } -// else -// { -// // go directly to web browser -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_WEBSTART); -// -// CInterfaceManager *pIM = CInterfaceManager::getInstance(); -// // start the browser -// CGroupHTML *pGH = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_BROWSER)); -// -// pGH->browse(RingMainURL.c_str()); -// } -// return; - } - else - { -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_SHARDDISP); - } - -// CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_SHARD)); -// if (pList == NULL) -// { -// nlwarning("element "GROUP_LIST_SHARD" not found probably bad login_main.xml"); -// return; -// } -// /* // To test more servers -// for (uint fff = 0; fff < 20; ++fff) -// { -// CShard s ( toString("%05d",fff), fff%3, fff+32, toString("%s%d","pipo",fff), -// 32*fff%46546, "32.32.32.32", "http://www.ryzom.com" ); -// Shards.push_back(s); -// }*/ -// -// CInterfaceGroup *pPrevLine = NULL; -// for(uint i = 0; i < Shards.size(); i++) -// { -// vector< pair < string, string > > params; -// params.clear(); -// params.push_back(pair("id", "s"+toString(i))); -// if (i>0) -// params.push_back(pair("posref", "BL TL")); -// -// CInterfaceGroup *pNewLine =pIM->createGroupInstance("t_shard", GROUP_LIST_SHARD, params); -// if (pNewLine != NULL) -// { -// CViewText *pVT = dynamic_cast(pNewLine->getView("name")); -// if (pVT != NULL) pVT->setText(Shards[i].Name); -// -// pVT = dynamic_cast(pNewLine->getView("version")); -// if (pVT != NULL) pVT->setText(Shards[i].Version); -// -// CViewBase *pVBon = pNewLine->getView("online"); -// CViewBase *pVBoff = pNewLine->getView("offline"); -// if ((pVBon != NULL) && (pVBoff != NULL)) -// { -// pVBon->setActive (Shards[i].Online); -// pVBoff->setActive (!Shards[i].Online); -// } -// -// pVT = dynamic_cast(pNewLine->getView("nbplayer")); -// if (pVT != NULL) pVT->setText(toString(Shards[i].NbPlayers)); -// -// -// // Add to the list -// pNewLine->setParent(pList); -// pNewLine->setParentSize(pList); -// pNewLine->setParentPos(pPrevLine); -// pList->addGroup(pNewLine); -// -// pPrevLine = pNewLine; -// } -// } -// // UI Patch -// if (!Shards.empty()) -// { -// CCtrlButton *pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_SHARD ":s0:but")); -// if (pCB != NULL) -// pCB->setPushed(true); -// CAHManager::getInstance()->runActionHandler (pCB->getActionOnLeftClick(), pCB, pCB->getParamsOnLeftClick()); -// -// } -// pList->invalidateCoords(); - } - else - { - // close the socket in case of error - HttpClient.disconnect(); - - pIM->messageBoxWithHelp("Error : " + res, "ui:login"); - - LoginSM.pushEvent(CLoginStateMachine::ev_bad_login); -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKPASS); -// -// if (LoginLogin.empty()) -// CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_LOGIN "|select_all=false"); -// else -// CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_PASSWORD "|select_all=false"); - - } -} - -class CAHOnLogin : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - //nlinfo("CAHOnLogin called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - CGroupEditBox *pGEBLog = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN)); - CGroupEditBox *pGEBPwd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_PASSWORD)); - if ((pGEBLog == NULL) || (pGEBPwd == NULL)) - { - nlwarning("element " CTRL_EDITBOX_LOGIN " or " CTRL_EDITBOX_PASSWORD " not found probably bad login_main.xml"); - return; - } - - LoginLogin = pGEBLog->getInputStringAsStdString(); - LoginPassword = pGEBPwd->getInputStringAsStdString(); - - onlogin(); - } -}; -REGISTER_ACTION_HANDLER (CAHOnLogin, "on_login"); - - -// *************************************************************************** -class CAHOnGameConfiguration : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHOnGameConfiguration called"); - - static string Configurator = "ryzom_configuration_rd.exe"; - - if (CFile::fileExists (Configurator)) - { - // launch the ryzom configurator - launchProgram(Configurator, ""); - setLoginFinished( true ); - loginOK = false; - - LoginSM.pushEvent(CLoginStateMachine::ev_quit); - } - else - { - nlwarning(" can't find ryzom configurator : %s",Configurator.c_str()); - } - } -}; -REGISTER_ACTION_HANDLER (CAHOnGameConfiguration, "on_game_configuration"); - - -// *************************************************************************** -class CAHLoginQuit : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHLoginQuit called"); - - setLoginFinished( true ); - loginOK = false; - - LoginSM.pushEvent(CLoginStateMachine::ev_quit); - } -}; -REGISTER_ACTION_HANDLER (CAHLoginQuit, "login_quit"); - - -// *************************************************************************** -class CAHLoginTab : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHLoginTab called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - if (NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->getValue32() == UI_VARIABLES_SCREEN_CHECKPASS) - { - CCtrlBase *pCB = CWidgetManager::getInstance()->getCaptureKeyboard(); - if (pCB != NULL) - { - CCtrlBase *pNewCB; - string sID = pCB->getId(); - if (sID == CTRL_EDITBOX_LOGIN) - pNewCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_PASSWORD)); - else - pNewCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN)); - CWidgetManager::getInstance()->setCaptureKeyboard(pNewCB); - } - } - else if (NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->getValue32() == UI_VARIABLES_SCREEN_CREATE_ACCOUNT) - { - CCtrlBase *pCB = CWidgetManager::getInstance()->getCaptureKeyboard(); - if (pCB != NULL) - { - CCtrlBase *pNewCB; - string sID = pCB->getId(); - if (sID == CTRL_EDITBOX_CREATEACCOUNT_LOGIN) - pNewCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_CREATEACCOUNT_PASSWORD)); - else if (sID == CTRL_EDITBOX_CREATEACCOUNT_PASSWORD) - pNewCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_CREATEACCOUNT_CONFIRMPASSWORD)); - else if (sID == CTRL_EDITBOX_CREATEACCOUNT_CONFIRMPASSWORD) - pNewCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_CREATEACCOUNT_EMAIL)); - else - pNewCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_CREATEACCOUNT_LOGIN)); - CWidgetManager::getInstance()->setCaptureKeyboard(pNewCB); - } - } - } -}; -REGISTER_ACTION_HANDLER (CAHLoginTab, "login_tab"); - - -// *************************************************************************** -class CAHShardSelect : public IActionHandler -{ - virtual void execute (CCtrlBase *pCaller, const string &/* Params */) - { - nlinfo("CAHShardSelect called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - CCtrlButton *pCB = NULL; - // Unselect - if (ShardSelected != -1) - { - pCB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_SHARD ":s"+toString(ShardSelected)+":but")); - if (pCB != NULL) - pCB->setPushed(false); - } - - pCB = dynamic_cast(pCaller); - if (pCB != NULL) - { - string name = pCB->getId(); - name = name.substr(0,name.rfind(':')); - name = name.substr(name.rfind(':')+2,name.size()); - fromString(name, ShardSelected); - - pCB->setPushed(true); - } - - CCtrlTextButton *pCTB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_BUTTON_CONNECT)); - if (pCTB != NULL) - pCTB->setActive(true); - } -}; -REGISTER_ACTION_HANDLER (CAHShardSelect, "shard_select"); - -// *************************************************************************** -void ConnectToShard() -{ - //nlinfo("ConnectToShard called"); - - if (ClientCfg.R2Mode) - { - // r2 mode - setLoginFinished( true ); - loginOK = true; - - LoginSM.pushEvent(CLoginStateMachine::ev_enter_game); - } - else - { - // legacy mode - nlassert(ShardSelected != -1); - - string res = selectShard(Shards[ShardSelected].ShardId, Cookie, FSAddr); - - if(res.empty()) - { - setLoginFinished( true ); - loginOK = true; - - LoginSM.pushEvent(CLoginStateMachine::ev_enter_game); - } - else - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - pIM->messageBoxWithHelp("Error :" + res, "ui:login"); - - LoginSM.pushEvent(CLoginStateMachine::ev_conn_failed); - } - - } - -} - -// *************************************************************************** -class CAHLoginConnect : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHLoginConnect called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - if (ShardSelected == -1) - return; - - if (!Shards[ShardSelected].Online) - { - pIM->messageBoxWithHelp(CI18N::get("uiErrOffLineShard"), "ui:login"); - return; - } - - LoginSM.pushEvent(CLoginStateMachine::ev_shard_selected); - -// std::vector patchURIs = Shards[ShardSelected].PatchURIs; -// string url = Shards[ShardSelected].EmergencyPatchURL; -// string ver = Shards[ShardSelected].Version; -// -// if (!ClientCfg.PatchUrl.empty()) -// url = ClientCfg.PatchUrl; -// -// if (!ClientCfg.PatchVersion.empty()) -// ver = ClientCfg.PatchVersion; -// -// pPM->init(patchURIs, url, ver); -// -// LoginShardId = Shards[ShardSelected].ShardId; -// -// if (ClientCfg.PatchWanted) -// { -// pPM->startCheckThread(); -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKING); -// } -// else -// { -// CAHManager::getInstance()->runActionHandler("login_patch",NULL); -// } - } -}; -REGISTER_ACTION_HANDLER (CAHLoginConnect, "login_connect"); - -// *************************************************************************** -// Can be called after a patching process (ryzom relaunch and call this AH to -// see if we have to continue patching or directly go ingame) -class CAHLoginConnect2 : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHLoginConnect2 called"); - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - if (Shards[ShardSelected].PatchURIs.empty() && Shards[ShardSelected].EmergencyPatchURL.empty()) - { - pIM->messageBoxWithHelp(CI18N::get("uiErrCantPatch"), "ui:login"); - return; - } - - LoginSM.pushEvent(CLoginStateMachine::ev_shard_selected); - -// std::vector patchURIs = Shards[ShardSelected].PatchURIs; -// string url = Shards[ShardSelected].EmergencyPatchURL; -// string ver = Shards[ShardSelected].Version; -// -// if (!ClientCfg.PatchUrl.empty()) -// url = ClientCfg.PatchUrl; -// -// if (!ClientCfg.PatchVersion.empty()) -// ver = ClientCfg.PatchVersion; -// -// pPM->init(patchURIs, url, ver); -// -// if ((ClientCfg.PatchWanted) && -// (!Shards[ShardSelected].Version.empty()) && -// (Shards[ShardSelected].Version != pPM->getClientVersion())) -// { -// pPM->startCheckThread(); -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKING); -// } -// else -// { -// // Version is good, eula then connect and launch the client -// showEULA(); -// } - } -}; -REGISTER_ACTION_HANDLER (CAHLoginConnect2, "login_connect_2"); - -void initPatch() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CPatchManager *pPM = CPatchManager::getInstance(); - - - if (!isBGDownloadEnabled()) - { - // Get the list of optional categories to patch - vector vCategories; - - CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CAT)); - if (pList == NULL) - { - nlwarning("element " GROUP_LIST_CAT " not found probably bad login_main.xml"); - return; - } - - for(uint i = 0; i < InfoOnPatch.OptCat.size(); i++) - { - // Ok for the moment all optional categories must be patched even if the player - // does not want it. Because we cant detect that a continent have to be patched ingame. - vCategories.push_back(InfoOnPatch.OptCat[i].Name); - - /* - // Code to check if the player wants an optional category or not - CInterfaceGroup *pLine = pList->getGroup("c"+toString(i)); - if (pLine != NULL) - { - CCtrlButton *pCB = dynamic_cast(pLine->getCtrl("on_off")); - if (pCB != NULL) - { - if (pCB->getPushed()) - vCategories.push_back(rAllCats[i]); - } - } - */ - - } - pPM->startPatchThread(vCategories, true); - } - else - { - // NB : here we only do a part of the download each time - BGDownloader::CTaskDesc taskDesc(BGDownloader::DLState_GetAndApplyPatch, (1 << BGDownloaderWantedPatch)); - CBGDownloaderAccess::getInstance().startTask(taskDesc, string(), true /* showDownloader */); // no command line since bg downloader should already be started - // release lock on bnp, so that they can be written - NLMISC::CBigFile::getInstance().removeAll(); - NLMISC::CStreamedPackageManager::getInstance().unloadAll(); - } - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_PATCHING); - - CInterfaceElement *closeBtn = CWidgetManager::getInstance()->getElementFromId(CTRL_BUTTON_CLOSE_PATCH); - if (closeBtn) - closeBtn->setActive(false); - - setPatcherStateText("ui:login:patching", ucstring()); - setPatcherProgressText("ui:login:patching", ucstring()); -} - -// *************************************************************************** -// Called after the check has been done. The page is full of optional categories that must be selected for patching -class CAHLoginPatch : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHLoginPatch called"); - - LoginSM.pushEvent(CLoginStateMachine::ev_run_patch); - -// CInterfaceManager *pIM = CInterfaceManager::getInstance(); -// CPatchManager *pPM = CPatchManager::getInstance(); -// -// // Get the list of optional categories to patch -// vector vCategories; -// -// CInterfaceGroup *pList = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_LIST_CAT)); -// if (pList == NULL) -// { -// nlwarning("element "GROUP_LIST_CAT" not found probably bad login_main.xml"); -// return; -// } -// -// for(uint i = 0; i < InfoOnPatch.OptCat.size(); i++) -// { -// // Ok for the moment all optional categories must be patched even if the player -// // does not want it. Because we cant detect that a continent have to be patched ingame. -// vCategories.push_back(InfoOnPatch.OptCat[i].Name); -// -// /* -// // Code to check if the player wants an optional category or not -// CInterfaceGroup *pLine = pList->getGroup("c"+toString(i)); -// if (pLine != NULL) -// { -// CCtrlButton *pCB = dynamic_cast(pLine->getCtrl("on_off")); -// if (pCB != NULL) -// { -// if (pCB->getPushed()) -// vCategories.push_back(rAllCats[i]); -// } -// } -// */ -// } -// -// // Start patching -// if (ClientCfg.PatchWanted) -// { -// pPM->startPatchThread(vCategories); -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_PATCHING); -// } -// else -// { -// ConnectToShard(); -// } - } -}; -REGISTER_ACTION_HANDLER (CAHLoginPatch, "login_patch"); - -// *************************************************************************** -// Called after the check has been done. The page is full of optional categories that must be selected for patching -class CAHClosePatch : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHClosePatch called"); - - LoginSM.pushEvent(CLoginStateMachine::ev_close_patch); - } -}; -REGISTER_ACTION_HANDLER (CAHClosePatch, "close_patch"); - - -// *************************************************************************** -// Called after pushing the read note at the opening of the modal window -class CAHSetReleaseNote : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &sParams) - { - nlinfo("CAHSetReleaseNote called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - string sShard = getParam(sParams, "shard"); - string sGroupHtml = getParam(sParams, "group"); - - CGroupHTML *pQH = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(sGroupHtml)); - if (pQH == NULL) - return; - - string sURL; - if (ClientCfg.R2Mode) - { - // ring release note - sURL = ClientCfg.RingReleaseNotePath + - "?version=" + (VersionName.empty() ? R2ServerVersion : VersionName)+ - "&lang=" + ClientCfg.LanguageCode + - "&ca=" + ClientCfg.ConfigFile.getVar("Application").asString(0); - "&startPage="+RingMainURL; - } - else - { - // legacy ryzom release note - uint32 nShardId; - if (sShard == "selected") - nShardId = ShardSelected; - else - fromString(sShard.substr(1), nShardId); - - sURL = ClientCfg.ReleaseNotePath + - "?version=" + Shards[nShardId].Version + - "&lang=" + ClientCfg.LanguageCode + - "&id=" + toString(Shards[nShardId].ShardId) + - "&ca=" + ClientCfg.ConfigFile.getVar("Application").asString(0); - - } - - pQH->browse(sURL.c_str()); - } -}; -REGISTER_ACTION_HANDLER (CAHSetReleaseNote, "set_release_note"); - -// *************************************************************************** -// Called after pushing the read note at the opening of the modal window -class CAHReboot : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* sParams */) - { - nlinfo("CAHReboot called"); - - // create a file to prompt eula next time - CFile::createEmptyFile(getLogDirectory() + "show_eula"); - - CInterfaceManager *im = CInterfaceManager::getInstance(); - try - { - if (isBGDownloadEnabled()) - { - CBGDownloaderAccess::getInstance().reboot(); - } - else - { - CPatchManager::getInstance()->reboot(); - } - LoginSM.pushEvent(CLoginStateMachine::ev_reboot); - } - catch (const NLMISC::EDiskFullError &) - { - im->messageBoxWithHelp(CI18N::get("uiPatchDiskFull"), "ui:login"); - } - catch (const NLMISC::EWriteError &) - { - im->messageBoxWithHelp(CI18N::get("uiPatchWriteError"), "ui:login"); - } - catch (const std::exception &e) - { - im->messageBoxWithHelp(ucstring::makeFromUtf8(e.what()), "ui:login", "login_quit"); - } - } -}; -REGISTER_ACTION_HANDLER (CAHReboot, "reboot"); - - - -// *************************************************************************** -class CAHAcceptEula : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* sParams */) - { - //nlinfo("CAHAcceptEula called"); - if(CFile::fileExists(getLogDirectory() + "show_eula")) - CFile::deleteFile(getLogDirectory() + "show_eula"); - LoginSM.pushEvent(CLoginStateMachine::ev_accept_eula); - -// if (ClientCfg.R2Mode) -// { -// // open web browser -// CInterfaceManager *pIM = CInterfaceManager::getInstance(); -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_WEBSTART); -// -// // start the browser -// CGroupHTML *pGH = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(GROUP_BROWSER)); -// -// pGH->browse(RingMainURL.c_str()); -// } -// else -// { -// ConnectToShard(); -// } - } -}; -REGISTER_ACTION_HANDLER (CAHAcceptEula, "accept_eula"); - -// *************************************************************************** -class CAHOpenURL : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &sParams) - { - nlinfo("CAHOpenURL called"); - - string url; - - string installTag; - -#ifdef NL_OS_WINDOWS - - // Check for special install tag - const char *KeyName = "InstallTag"; - - installTag = CSystemUtils::getRegKey(KeyName); - - if (installTag.length() > 1) - { - nldebug("Found install tag '%s'", url.c_str()); - } - else - { - // Process any inserts in lpMsgBuf. - // ... - // Display the string. - nlwarning("RegQueryValue for '%s' : %s", KeyName, NLMISC::formatErrorMessage(0).c_str()); - } -#else - // TODO: for Linux and Mac OS -#endif - if (sParams == "cfg_CreateAccountURL") - { - url = ClientCfg.CreateAccountURL; - } - else if (sParams == "cfg_EditAccountURL") - { - url = ClientCfg.EditAccountURL; - } - else if (sParams == "cfg_BetaAccountURL") - { - url = ClientCfg.BetaAccountURL; - } - else if (sParams == "cfg_ForgetPwdURL") - { - url = ClientCfg.ForgetPwdURL; - } - else if (sParams == "cfg_LoginSupportURL") - { - url= ClientCfg.LoginSupportURL; - } - else if (sParams == "cfg_FreeTrialURL") - { - url = ClientCfg.FreeTrialURL; - - if (!installTag.empty()) - { - url += string("&from=")+installTag; - } - } - else if (sParams == "cfg_ConditionsTermsURL") - { - url = ClientCfg.ConditionsTermsURL; - } - else if (sParams == "cfg_NamingPolicyURL") - { - url = ClientCfg.NamingPolicyURL; - } - else - { - nlwarning("no URL found"); - return; - } - - if(sParams != "cfg_ConditionsTermsURL" && sParams != "cfg_NamingPolicyURL") - { - // modify existing languages - - // old site - string::size_type pos_lang = url.find("/en/"); - - // or new forums - if (pos_lang == string::npos) - pos_lang = url.find("=en#"); - - if (pos_lang != string::npos) - { - url.replace(pos_lang + 1, 2, ClientCfg.getHtmlLanguageCode()); - } - else - { - // append language - if (url.find('?') != string::npos) - url += "&"; - else - url += "?"; - - url += "language=" + ClientCfg.LanguageCode; - - if (!LoginCustomParameters.empty()) - url += LoginCustomParameters; - } - } - - openURL(url); - - nlinfo("openURL %s", url.c_str()); - } -}; -REGISTER_ACTION_HANDLER (CAHOpenURL, "open_url"); - -static vector VideoModes; -vector StringModeList; -vector StringPresetList; -vector< pair > CfgPresetList; -sint CurrentMode = -1; -sint CurrentPreset = -1; - -// *************************************************************************** -class CAHInitResLod : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* sParams */) - { - //nlinfo("CAHInitResLod called"); - if (Driver == NULL) return; - - VideoModes.clear(); - StringModeList.clear(); - - std::vector stringFreqList; - sint currentFreq; - - getRyzomModes(VideoModes, StringModeList, stringFreqList, CurrentMode, currentFreq); - - // getRyzomModes() expects empty list, so we need to insert 'Windowed' after mode list is filled - StringModeList.insert(StringModeList.begin(), "uiConfigWindowed"); - - // If the client is in windowed mode, still in windowed mode and do not change anything - if (ClientCfg.Windowed) - CurrentMode = 0; - // If we have not found the mode so it can be an error or machine change, so propose the first available - else if (CurrentMode == -1) - CurrentMode = 1; - // We inserted 'Windowed' as first mode, so index needs to move too - else - ++CurrentMode; - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:checkpass:content:res_value")); - if (pVT != NULL) - pVT->setHardText(StringModeList[CurrentMode]); - - StringPresetList.clear(); - StringPresetList.push_back("uiLodValueLow"); - StringPresetList.push_back("uiLodValueMedium"); - StringPresetList.push_back("uiLodValueNormal"); - StringPresetList.push_back("uiLodValueHigh"); - StringPresetList.push_back("uiLodValueCustom"); - CurrentPreset = 4; // CInterfaceDDX::CustomPreset - - // first indicates the preset-able cfg-variable - // second indicates if its a double variable (else it's an int) - CfgPresetList.clear(); - CfgPresetList.push_back(pair("LandscapeTileNear", true)); - CfgPresetList.push_back(pair("LandscapeThreshold", true)); - CfgPresetList.push_back(pair("Vision", true)); - CfgPresetList.push_back(pair("MicroVeget", false)); - CfgPresetList.push_back(pair("MicroVegetDensity", true)); - CfgPresetList.push_back(pair("FxNbMaxPoly", false)); - CfgPresetList.push_back(pair("Cloud", false)); - CfgPresetList.push_back(pair("CloudQuality", true)); - CfgPresetList.push_back(pair("CloudUpdate", false)); - CfgPresetList.push_back(pair("Shadows", false)); - CfgPresetList.push_back(pair("SkinNbMaxPoly", false)); - CfgPresetList.push_back(pair("NbMaxSkeletonNotCLod", false)); - CfgPresetList.push_back(pair("CharacterFarClip", true)); - - CfgPresetList.push_back(pair("FXAA", false)); - CfgPresetList.push_back(pair("Bloom", false)); - CfgPresetList.push_back(pair("SquareBloom", false)); - CfgPresetList.push_back(pair("DensityBloom", true)); - - // Check if all the preset-able cfg-variable are in a preset mode - sint nPreset = -1; - for (uint32 i = 0; i < CfgPresetList.size(); ++i) - { - CConfigFile::CVar *cfgVarPtr = ClientCfg.ConfigFile.getVarPtr(CfgPresetList[i].first); - if (cfgVarPtr == NULL) continue; - // Get the preset of the variable i - sint nVarPreset = 0; - for (uint32 j = 0; j < 4; ++j) // CInterfaceDDX::NumPreset - { - string sPresetName = CfgPresetList[i].first + "_ps" + toString(j); - CConfigFile::CVar *presetVarPtr = ClientCfg.ConfigFile.getVarPtr(sPresetName); - if(presetVarPtr) - { - if (CfgPresetList[i].second) // Is it a double ? - { - if (cfgVarPtr->asDouble() == presetVarPtr->asDouble()) - nVarPreset |= (1 << j); - } - else - { - if (cfgVarPtr->asInt() == presetVarPtr->asInt()) - nVarPreset |= (1 << j); - } - } - } - - if (nPreset == -1) - nPreset = nVarPreset; - else - nPreset &= nVarPreset; - - if (nPreset == 0) - break; - } - - if (nPreset != 0) - { - if (nPreset&1) CurrentPreset = 0; - else if (nPreset&2) CurrentPreset = 1; - else if (nPreset&4) CurrentPreset = 2; - else if (nPreset&8) CurrentPreset = 3; - } - - pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:checkpass:content:lod_value")); - if (pVT != NULL) - pVT->setHardText(StringPresetList[CurrentPreset]); - } -}; -REGISTER_ACTION_HANDLER (CAHInitResLod, "init_res_lod"); - -// *************************************************************************** -class CAHMoreRes : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* sParams */) - { - nlinfo("CAHMoreRes called"); - if (CurrentMode < ((sint)StringModeList.size()-1)) - CurrentMode++; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:checkpass:content:res_value")); - if (pVT != NULL) - pVT->setHardText(StringModeList[CurrentMode]); - } -}; -REGISTER_ACTION_HANDLER (CAHMoreRes, "more_res"); - -// *************************************************************************** -class CAHLessRes : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* sParams */) - { - nlinfo("CAHLessRes called"); - if (CurrentMode > 0) - CurrentMode--; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:checkpass:content:res_value")); - if (pVT != NULL) - pVT->setHardText(StringModeList[CurrentMode]); - } -}; -REGISTER_ACTION_HANDLER (CAHLessRes, "less_res"); - -// *************************************************************************** -class CAHMoreLod : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* sParams */) - { - nlinfo("CAHMoreLod called"); - if (CurrentPreset < ((sint)StringPresetList.size()-1)) - CurrentPreset++; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:checkpass:content:lod_value")); - if (pVT != NULL) - pVT->setHardText(StringPresetList[CurrentPreset]); - } -}; -REGISTER_ACTION_HANDLER (CAHMoreLod, "more_lod"); - -// *************************************************************************** -class CAHLessLod : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* sParams */) - { - nlinfo("CAHMoreLod called"); - if (CurrentPreset > 0) - CurrentPreset--; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CViewText *pVT = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:checkpass:content:lod_value")); - if (pVT != NULL) - pVT->setHardText(StringPresetList[CurrentPreset]); - } -}; -REGISTER_ACTION_HANDLER (CAHLessLod, "less_lod"); - -// *************************************************************************** -class CAHUninitResLod : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* sParams */) - { - //nlinfo("CAHUninitResLod called"); - - // If the mode requested is a windowed mode do nothnig - if (CurrentMode == 0) - { - ClientCfg.Windowed = true; - ClientCfg.writeBool("FullScreen", false); - } - else - { - ClientCfg.Windowed = false; - // Get W, H - uint16 w = 0, h = 0; - { - string vidModeStr = StringModeList[CurrentMode]; - string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1); - fromString(tmp, w); - tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size()); - fromString(tmp, h); - } - ClientCfg.Width = w; - ClientCfg.Height = h; - - ClientCfg.writeBool("FullScreen", true); - ClientCfg.writeInt("Width", w); - ClientCfg.writeInt("Height", h); - } - - if (CurrentPreset != 4) // CInterfaceDDX::CustomPreset - { - for (uint32 i = 0; i < CfgPresetList.size(); ++i) - { - CConfigFile::CVar *cfgVarPtr = ClientCfg.ConfigFile.getVarPtr(CfgPresetList[i].first); - if (cfgVarPtr == NULL) continue; - - string sPresetName = CfgPresetList[i].first + "_ps" + toString(CurrentPreset); - CConfigFile::CVar *presetVarPtr = ClientCfg.ConfigFile.getVarPtr(sPresetName); - if(presetVarPtr) - { - if (CfgPresetList[i].second) // Is it a double ? - cfgVarPtr->setAsDouble(presetVarPtr->asDouble()); - else - cfgVarPtr->setAsInt(presetVarPtr->asInt()); - } - } - } - - // **** Save the config - if (ClientCfg.SaveConfig) - ClientCfg.ConfigFile.save (); - ClientCfg.IsInvalidated = true; - } -}; -REGISTER_ACTION_HANDLER (CAHUninitResLod, "uninit_res_lod"); - - -void initDataScan() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CPatchManager *pPM = CPatchManager::getInstance(); - - // reset the log - setDataScanLog(ucstring()); - - // Start Scanning - pPM->startScanDataThread(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_DATASCAN); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:DATASCAN_RUNNING")->setValue32(1); -} - -// *************************************************************************** -// Called after the check has been done. The page is full of optional categories that must be selected for patching -class CAHOnScanDataStart : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHOnScanDataStart called"); - - LoginSM.pushEvent(CLoginStateMachine::ev_data_scan); - - } -}; -REGISTER_ACTION_HANDLER (CAHOnScanDataStart, "on_scan_data_start"); - -// *************************************************************************** -// Called when the user cancel the scan -class CAHOnScanDataClose : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHOnScanDataClose called"); - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CPatchManager *pPM = CPatchManager::getInstance(); - - // if the scan is still running - if(NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:DATASCAN_RUNNING")->getValue32()!=0) - { - // request to stop the thread - pPM->askForStopScanDataThread(); - - // Log. - setDataScanState(CI18N::get("uiCancelingScanData")); - } - else - { - LoginSM.pushEvent(CLoginStateMachine::ev_close_data_scan); - // Come Back to Login Screen. -// NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKPASS); -// -// // Give focus to password if some login entered -// string loginEB; -// CGroupEditBox *pGEB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CTRL_EDITBOX_LOGIN)); -// if(pGEB) -// loginEB= pGEB->getInputStringAsStdString(); -// // if none entered -// if (loginEB.empty()) -// CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_LOGIN "|select_all=false"); -// else -// CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_PASSWORD "|select_all=false"); - } - } -}; -REGISTER_ACTION_HANDLER (CAHOnScanDataClose, "on_scan_data_close"); - -// *************************************************************************** - -inline string parseTooltip(const string & initString, const string & tagName) -{ - string tooltip; - - string::size_type tooltipPos = initString.find(tagName); - if(tooltipPos != string::npos) - { - tooltip = initString.substr(tooltipPos); - - // start of tooltip - tooltip = tooltip.substr(tooltip.find(">")+1); - - // end of tooltip - tooltip = tooltip.substr(0, tooltip.find("<")); - } - - ucstring uc; - uc.fromUtf8(tooltip);; - tooltip = uc.toString(); - - return tooltip; -} - -inline string parseCommentError(const string & initString, const string & tagName) -{ - string error; - - string::size_type errorPos = initString.find(tagName); - if(errorPos != string::npos) - { - error = initString.substr(errorPos); - - // start of comment - error = error.substr(error.find(">")+1); - - // end of comment - error = error.substr(0, error.find("<")); - } - - ucstring uc; - uc.fromUtf8(error);; - error = uc.toString(); - - return error; -} - -bool initCreateAccount() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - // reset UI - CInterfaceGroup *createAccountUI = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:create_account")); - if(createAccountUI) - { - // show "submit interface", hide "login interface" - CInterfaceGroup * grSubmit = dynamic_cast(createAccountUI->findFromShortId("submit_gr")); - if(grSubmit) - grSubmit->setActive(true); - - CInterfaceGroup * grLogin = dynamic_cast(createAccountUI->findFromShortId("login_gr")); - if(grLogin) - grLogin->setActive(false); - - // empty edit boxes - std::vector< std::string > editBoxes(4); - editBoxes[0] = "eb_login"; - editBoxes[1] = "eb_password"; - editBoxes[2] = "eb_confirm_password"; - editBoxes[3] = "eb_email"; - - for(uint i=0; i(createAccountUI->findFromShortId(editBoxes[i] + ":eb")); - if(eb) - eb->setInputString(ucstring("")); - } - - // conditions button - CCtrlBaseButton * but = dynamic_cast(createAccountUI->findFromShortId("accept_cond")); - if(but) - but->setPushed(true); - - // get rules from url - string url = ClientCfg.CreateAccountURL; - CPatchManager *pPM = CPatchManager::getInstance(); - - if (!CurlHttpClient.connect(url)) - { - nlwarning("Can't connect"); - return false; - } - - std::string lang = ClientCfg.LanguageCode; - if(lang=="wk") lang = "uk"; - - CurlHttpClient.verifyServer(true); // set this to false if you need to connect to the test environment - - std::string params = "language=" + lang; - - if (!LoginCustomParameters.empty()) - params += LoginCustomParameters; - - if(!CurlHttpClient.sendGet(url, params, pPM->isVerboseLog())) - { - ucstring errorMessage("Can't send (error code 60)"); - errorMessageBox(errorMessage); - nlwarning(errorMessage.toString().c_str()); - return false; - } - - string res; - if(!CurlHttpClient.receive(res, pPM->isVerboseLog())) - { - ucstring errorMessage("Can't receive (error code 61)"); - errorMessageBox(errorMessage); - nlwarning(errorMessage.toString().c_str()); - return false; - } - - if(res.empty()) - { - ucstring errorMessage("Empty result (error code 13)"); - errorMessageBox(errorMessage); - nlwarning(errorMessage.toString().c_str()); - return false; - } - - CurlHttpClient.disconnect(); - - // initialize rules in interface - std::vector< std::pair< std::string , std::string > > rules(5); - rules[0] = std::pair("rules_login", "id=tooltip-Username"); - rules[1] = std::pair("rules_password", "id=tooltip-Password"); - rules[2] = std::pair("rules_password_conf", "id=tooltip-ConfirmPass"); - rules[3] = std::pair("rules_email", "id=tooltip-Email"); - rules[4] = std::pair("rules_conditions", "id=tooltip-TaC"); - - for(uint i=0; i(createAccountUI->findFromShortId(rules[i].first)); - if(text) - { - string tooltip = parseTooltip(res, rules[i].second); - text->setHardText(tooltip); - text->setActive(false); - } - } - - // welcome text - CViewText * text = dynamic_cast(createAccountUI->findFromShortId("errors_list")); - if(text) - { - text->setHardText(toString(CI18N::get("uiCreateAccountWelcome"))); - text->setColor(CRGBA(255, 255, 255, 255)); - - CInterfaceGroup * group = dynamic_cast(createAccountUI->findFromShortId("erros_txt")); - if(group) - { - group->updateCoords(); - - CInterfaceGroup * groupScroll = dynamic_cast(createAccountUI->findFromShortId("err_back_scrollbar")); - if(groupScroll) groupScroll->setActive(group->getHReal() > group->getMaxHReal()); - CCtrlScroll * scroll = dynamic_cast(createAccountUI->findFromShortId("err_scroll_bar")); - if(scroll) - scroll->setTrackPos(scroll->getHReal()); - } - } - - // hide rules - CInterfaceGroup * rulesGr = dynamic_cast(createAccountUI->findFromShortId("rules_gr")); - if(rulesGr) - rulesGr->setActive(false); - - // must be done after hide rules - CAHManager::getInstance()->runActionHandler("set_keyboard_focus", NULL, "target=" CTRL_EDITBOX_CREATEACCOUNT_LOGIN "|select_all=false"); - } - - - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CREATE_ACCOUNT); - - return true; -} - -// *************************************************************************** -// Called when the user focus one of the edit boxes during the account creation -class CAHCreateAccountRules : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - nlinfo("CAHCreateAccountRules called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceGroup *createAccountUI = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:create_account")); - if(createAccountUI) - { - CInterfaceGroup * rulesGr = dynamic_cast(createAccountUI->findFromShortId("rules_gr")); - if(rulesGr) - rulesGr->setActive(false); - - std::vector< std::string > rules(4); - rules[0] = "rules_login"; - rules[1] = "rules_password"; - rules[2] = "rules_password_conf"; - rules[3] = "rules_email"; - - for(uint i=0; i(createAccountUI->findFromShortId(rules[i])); - if(text) - { - text->setActive(Params==rules[i]); - if(Params==rules[i]) - { - if(rulesGr) - rulesGr->setActive(!text->getText().empty()); - } - } - } - } - } -}; -REGISTER_ACTION_HANDLER (CAHCreateAccountRules, "create_account_rules"); - -// *************************************************************************** -// Called when the user choose the account creation -class CAHOnCreateAccount : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHOnCreateAccount called"); - - LoginSM.pushEvent(CLoginStateMachine::ev_create_account); - } -}; -REGISTER_ACTION_HANDLER (CAHOnCreateAccount, "on_create_account"); - -// *************************************************************************** -// Called when the user submit the account creation -class CAHOnCreateAccountSubmit : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHOnCreateAccountSubmit called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - CInterfaceGroup *createAccountUI = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:create_account")); - if(createAccountUI) - { - // recover data from UI - std::vector< std::string > editBoxes(4); - editBoxes[0] = "eb_login"; - editBoxes[1] = "eb_password"; - editBoxes[2] = "eb_confirm_password"; - editBoxes[3] = "eb_email"; - std::vector< std::string > results(4); - - for(uint i=0; i(createAccountUI->findFromShortId(editBoxes[i] + ":eb")); - if(eb) - results[i] = eb->getInputString().toUtf8(); - } - - // text - CViewText * text = dynamic_cast(createAccountUI->findFromShortId("email_adress")); - if(text) - text->setHardText(results[3]); - - // conditions button - bool conditionsPushed = false; - CCtrlBaseButton * but = dynamic_cast(createAccountUI->findFromShortId("accept_cond")); - if(but) - conditionsPushed = !but->getPushed(); - - string url = ClientCfg.CreateAccountURL; - CPatchManager *pPM = CPatchManager::getInstance(); - - if (!CurlHttpClient.connect(url)) - { - ucstring errorMessage("Can't connect"); - errorMessageBox(errorMessage); - nlwarning(errorMessage.toString().c_str()); - return; - } - - std::string params = "Username=" + results[0] + "&Password=" + results[1] - + "&ConfirmPass=" + results[2] + "&Email=" + results[3]; - - if(conditionsPushed) - params += "&TaC=1"; - - if (!LoginCustomParameters.empty()) - params += LoginCustomParameters; - - std::string md5 = results[0] + results[1] + "" + results[3]; - md5 = NLMISC::getMD5((uint8*)md5.data(), (uint32)md5.size()).toString(); - - params += "&SC=" + md5; - std::string lang = ClientCfg.LanguageCode; - if(lang=="wk") lang = "uk"; - params += "&Language=" + lang; - - CurlHttpClient.verifyServer(true); // set this to false if you need to connect to the test environment - - if(!CurlHttpClient.sendPost(url, params, pPM->isVerboseLog())) - { - ucstring errorMessage("Can't send (error code 60)"); - errorMessageBox(errorMessage); - nlwarning(errorMessage.toString().c_str()); - return; - } - - string res; - if(!CurlHttpClient.receive(res, pPM->isVerboseLog())) - { - ucstring errorMessage("Can't receive (error code 61)"); - errorMessageBox(errorMessage); - nlwarning(errorMessage.toString().c_str()); - return; - } - - if(res.empty()) - { - ucstring errorMessage("Empty result (error code 13)"); - errorMessageBox(errorMessage); - nlwarning(errorMessage.toString().c_str()); - return; - } - - CurlHttpClient.disconnect(); - - // parse html - string::size_type okPos = res.find("email_sent"); - if(okPos != string::npos) - { - // show "submit interface", hide "login interface" - CInterfaceGroup * grSubmit = dynamic_cast(createAccountUI->findFromShortId("submit_gr")); - if(grSubmit) - grSubmit->setActive(false); - - CInterfaceGroup * grLogin = dynamic_cast(createAccountUI->findFromShortId("login_gr")); - if(grLogin) - grLogin->setActive(true); - } - else - { - // initialize error comments in interface - CViewText * text = dynamic_cast(createAccountUI->findFromShortId("errors_list")); - if(text) - { - text->setColor(CRGBA(250, 30, 30, 255)); - - std::vector< std::string > errors(5); - errors[0] = "id=\"comment-Username\""; - errors[1] = "id=\"comment-Password\""; - errors[2] = "id=\"comment-ConfirmPass\""; - errors[3] = "id=\"comment-Email\""; - errors[4] = "id=\"comment-TaC\""; - - string error; - for(uint i=0; isetHardText(error); - - CInterfaceGroup * group = dynamic_cast(createAccountUI->findFromShortId("erros_txt")); - if(group) - { - group->updateCoords(); - - CInterfaceGroup * groupScroll = dynamic_cast(createAccountUI->findFromShortId("err_back_scrollbar")); - if(groupScroll) groupScroll->setActive(group->getHReal() > group->getMaxHReal()); - CCtrlScroll * scroll = dynamic_cast(createAccountUI->findFromShortId("err_scroll_bar")); - if(scroll) - scroll->setTrackPos(scroll->getHReal()); - } - } - } - } - } -}; -REGISTER_ACTION_HANDLER (CAHOnCreateAccountSubmit, "on_create_account_submit"); - -// *************************************************************************** -// Called when the user cancel the account creation -class CAHOnCreateAccountClose : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHOnCreateAccountClose called"); - - LoginSM.pushEvent(CLoginStateMachine::ev_close_create_account); - } -}; -REGISTER_ACTION_HANDLER (CAHOnCreateAccountClose, "on_create_account_close"); - -// *************************************************************************** -class CAHCreateAccountLogin : public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &/* Params */) - { - nlinfo("CAHCreateAccountLogin called"); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - CInterfaceGroup *createAccountUI = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:login:create_account")); - if(createAccountUI) - { - CGroupEditBox * eb = dynamic_cast(createAccountUI->findFromShortId("eb_login:eb")); - if(eb) - LoginLogin = eb->getInputString().toUtf8(); - - eb = dynamic_cast(createAccountUI->findFromShortId("eb_password:eb")); - if(eb) - LoginPassword = eb->getInputString().toUtf8(); - - onlogin(false); - } - } -}; -REGISTER_ACTION_HANDLER (CAHCreateAccountLogin, "create_account_login"); - -// *************************************************************************** -// Called by html embeded lua script -class CAHOnConnectToShard: public IActionHandler -{ - virtual void execute (CCtrlBase * /* pCaller */, const string &Params) - { - // warning : pCaller is null when event come from lua scrip embeded in HTML - Cookie = getParam(Params, "cookie"); - FSAddr = getParam(Params, "fsAddr"); - - // replace the '_' with '|' in the cookie string - for (uint i=0; igetDbProp("UI:VARIABLES:SCREEN")->setValue32(UI_VARIABLES_SCREEN_CHECKPASS); - } -}; -REGISTER_ACTION_HANDLER (CAHOnBackToLogin, "on_back_to_login"); - -// *************************************************************************** -// *************************************************************************** -// *************************************************************************** -// NETWORK CONNECTION -// *************************************************************************** -// *************************************************************************** -// *************************************************************************** - - -// *************************************************************************** -string checkLogin(const string &login, const string &password, const string &clientApp, const std::string &customParameters) -{ - CPatchManager *pPM = CPatchManager::getInstance(); - Shards.clear(); - - if(ClientCfg.ConfigFile.exists("VerboseLog")) - pPM->setVerboseLog(ClientCfg.ConfigFile.getVar("VerboseLog").asInt() == 1); - if(pPM->isVerboseLog()) nlinfo("Using verbose log mode"); - - if(!HttpClient.connectToLogin()) - return "Can't connect (error code 1)"; - - if(pPM->isVerboseLog()) nlinfo("Connected"); - - string res; - - std::string url = ClientCfg.ConfigFile.getVar("StartupHost").asString() + ClientCfg.ConfigFile.getVar("StartupPage").asString(); - - // don't use login with alt method - if (!login.empty()) - { - // ask server for salt - if(!HttpClient.sendGet(url + "?cmd=ask&cp=2&login=" + login + "&lg=" + ClientCfg.LanguageCode, "", pPM->isVerboseLog())) - return "Can't send (error code 60)"; - - if(pPM->isVerboseLog()) nlinfo("Sent request for password salt"); - - if(!HttpClient.receive(res, pPM->isVerboseLog())) - return "Can't receive (error code 61)"; - - if(pPM->isVerboseLog()) nlinfo("Received request login check"); - - if(res.empty()) - return "Empty answer from server (error code 62)"; - - size_t first = res.find("\n\n"); - if (first == std::string::npos) - { - first = res.find("\r\r"); - if (first == std::string::npos) - { - first = res.find("\r\n\r\n"); - if (first != std::string::npos) - { - res = res.substr(first + 4); - } - } - else - { - res = res.substr(first + 2); - } - } - else - { - res = res.substr(first + 2); - } - - nldebug("res1: %s", res.c_str()); - - if (res[0] == 'H') - { - nlwarning("missing response body: %s", res.c_str()); - return "missing response body (error code 64)"; - } - else if(res[0] == '0') - { - // server returns an error - nlwarning("server error: %s", res.substr(2).c_str()); - return res.substr(2); - } - else if(res[0] == '1') - { - Salt = res.substr(2); - } - else - { - // server returns ??? - nlwarning("%s", res.c_str()); - return res; - } - - // send login + crypted password + client app and cp=2 (as crypted password) - if(!HttpClient.connectToLogin()) - return "Can't connect (error code 63)"; - - if(pPM->isVerboseLog()) nlinfo("Connected"); - } - - if (ClientCfg.R2Mode) - { - // R2 login sequence - - if (!login.empty()) - { - std::string cryptedPassword = CCrypt::crypt(password, Salt); - - if(!HttpClient.sendGet(url + "?cmd=login&login=" + login + "&password=" + cryptedPassword + "&clientApplication=" + clientApp + "&cp=2" + "&lg=" + ClientCfg.LanguageCode + customParameters)) - return "Can't send (error code 2)"; - } - else - { - // don't send login and password if empty - if(!HttpClient.sendGet(url + "?cmd=login&clientApplication=" + clientApp + "&cp=2" + "&lg=" + ClientCfg.LanguageCode + customParameters)) - return "Can't send (error code 2)"; - } - - // the response should contains the result code and the cookie value - if(pPM->isVerboseLog()) nlinfo("Sent request login check"); - - if(!HttpClient.receive(res, pPM->isVerboseLog())) - return "Can't receive (error code 3)"; - - if(pPM->isVerboseLog()) nlinfo("Received request login check"); - - if(res.empty()) - return "Empty answer from server (error code 4)"; - - size_t first = res.find("\n\n"); - if (first == std::string::npos) - { - first = res.find("\r\r"); - if (first == std::string::npos) - { - first = res.find("\r\n\r\n"); - if (first != std::string::npos) - { - res = res.substr(first + 4); - } - } - else - { - res = res.substr(first + 2); - } - } - else - { - res = res.substr(first + 2); - } - - nldebug("res2: %s", res.c_str()); - - if (res[0] == 'H') - { - nlwarning("missing response body: %s", res.c_str()); - return "missing response body (error code 65)"; - } - else if(res[0] == '0') - { - // server returns an error - nlwarning("server error: %s", res.substr(2).c_str()); - return res.substr(2); - } - else if(res[0] == '1') - { - //nlwarning(res.c_str()); - vector lines; - explode(res, std::string("\n"), lines, false); - if (lines.size() != 2) - { - return toString("Invalid server return, found %u lines, want 2", lines.size()); - } - - vector parts; - explode(lines[0], std::string("#"), parts, false); - if (parts.size() < 5) - return "Invalid server return, missing cookie and/or Ring URLs"; - - // server returns ok, we have the cookie - - // store the cookie value and FS address for next page request - CurrentCookie = parts[1]; - Cookie = CurrentCookie; - FSAddr = parts[2]; - - // store the ring startup page - RingMainURL = parts[3]; - FarTP.setURLBase(parts[4]); - - if(parts.size() >= 6 && parts[5] == "1") - { - // we want stats - extern bool startStat; - startStat = true; - } - - // parse the second line (contains the domain info) - parts.clear(); - explode(lines[1], std::string("#"), parts, false); - if (parts.size() < 3) - return "Invalid server return, missing patch URLs"; - - R2ServerVersion = parts[0].c_str(); - R2BackupPatchURL = parts[1]; - explode(parts[2], std::string(" "), R2PatchURLs, true); - } - else - { - // unexpected content -#if !FINAL_VERSION - string ret = toString("DEV : Invalid server return, missing return code in \n%s", res.c_str()); - return ret; -#else - return "Invalid server return, missing return code"; -#endif - } - - } - else - { - // standard ryzom login sequence - std::string cryptedPassword = CCrypt::crypt(password, Salt); - - if(!HttpClient.sendGet(url + "?login=" + login + "&password=" + cryptedPassword + "&clientApplication=" + clientApp + "&cp=2")) - return "Can't send (error code 2)"; - /* - if(!send(ClientCfg.ConfigFile.getVar("StartupPage").asString()+"?login="+login+"&password="+password+"&clientApplication="+clientApp)) - return "Can't send (error code 2)"; - */ - if(pPM->isVerboseLog()) nlinfo("Sent request login check"); - - if(!HttpClient.receive(res, pPM->isVerboseLog())) - return "Can't receive (error code 3)"; - - if(pPM->isVerboseLog()) nlinfo("Received request login check"); - - if(res.empty()) - return "Empty answer from server (error code 4)"; - - size_t first = res.find("\n\n"); - if (first == std::string::npos) - { - first = res.find("\r\r"); - if (first == std::string::npos) - { - first = res.find("\r\n\r\n"); - if (first != std::string::npos) - { - res = res.substr(first + 4); - } - } - else - { - res = res.substr(first + 2); - } - } - else - { - res = res.substr(first + 2); - } - - nldebug("res2: %s", res.c_str()); - - if (res[0] == 'H') - { - nlwarning("missing response body: %s", res.c_str()); - return "missing response body (error code 66)"; - } - else if(res[0] == '0') - { - // server returns an error - nlwarning("server error: %s", res.substr(2).c_str()); - return res.substr(2); - } - else if(res[0] == '1') - { - // server returns ok, we have the list of shard - uint nbs; - fromString(res.substr(2), nbs); - vector lines; - - explode(res, std::string("\n"), lines, true); - - if(pPM->isVerboseLog()) - { - nlinfo ("Exploded, with nl, %u res", (uint)lines.size()); - /* for (uint i = 0; i < lines.size(); i++) - { - nlinfo (" > '%s'", lines[i].c_str()); - }*/ - } - - if(lines.size() != nbs+1) - { - nlwarning("bad shard lines number %u != %d", (uint)lines.size(), nbs+1); - nlwarning("'%s'", res.c_str()); - return "bad lines numbers (error code 5)"; - } - - for(uint i = 1; i < lines.size(); i++) - { - vector res; - explode(lines[i], std::string("|"), res); - - if(pPM->isVerboseLog()) - { - nlinfo ("Exploded with '%s', %u res", "|", (uint)res.size()); - /* for (uint i = 0; i < res.size(); i++) - { - nlinfo (" > '%s'", res[i].c_str()); - }*/ - } - - if (res.size() < 7 && res.size() > 8) - { - nlwarning("bad | numbers %u != %d", (uint)res.size(), 8); - nlwarning("'%s'", lines[i].c_str()); - return "bad pipe numbers (error code 6)"; - } - bool online; - fromString(res[1], online); - uint32 shardId; - fromString(res[2], shardId); - uint32 nbPlayers; - fromString(res[4], nbPlayers); - Shards.push_back(CShard(res[0], online, shardId, res[3], nbPlayers, res[5], res[6])); - nlinfo("Shard %u, addr = %s, id = %u, name = %s, PatchURIs = %s", i, res[5].c_str(), shardId, res[3].c_str(), res[6].c_str()); - if (res.size() == 8) - { - explode(res[7], std::string(" "), Shards.back().PatchURIs); - } - } - } - else - { - // server returns ??? - nlwarning("%s", res.c_str()); - return res; - } - } - - return ""; -} - -// *************************************************************************** -string selectShard(uint32 shardId, string &cookie, string &addr) -{ - cookie.clear(); - addr.clear(); - - if(!HttpClient.connectToLogin()) return "Can't connect (error code 7)"; - - if(LoginLogin.empty()) return "Empty Login (error code 8)"; - if(LoginPassword.empty()) return "Empty Password (error code 9)"; - if(ClientApp.empty()) return "Empty Client Application (error code 10)"; - - // send login + crypted password + client app and cp=2 (as crypted password) - std::string cryptedPassword = CCrypt::crypt(LoginPassword, Salt); - - std::string url = ClientCfg.ConfigFile.getVar("StartupHost").asString() + ClientCfg.ConfigFile.getVar("StartupPage").asString(); - - if(!HttpClient.sendGet(url + "?cmd=login&shardid=" + toString(shardId) + "&login=" + LoginLogin + "&password=" + cryptedPassword + "&clientApplication=" + ClientApp + "&cp=2")) - return "Can't send (error code 11)"; - - string res; - - CPatchManager *pPM = CPatchManager::getInstance(); - if(!HttpClient.receive(res, pPM->isVerboseLog())) - return "Can't receive (error code 12)"; - - if(res.empty()) - return "Empty result (error code 13)"; - - size_t first = res.find("\n\n"); - if (first == std::string::npos) - { - first = res.find("\r\r"); - if (first == std::string::npos) - { - first = res.find("\r\n\r\n"); - if (first != std::string::npos) - { - res = res.substr(first + 4); - } - } - else - { - res = res.substr(first + 2); - } - } - else - { - res = res.substr(first + 2); - } - - nldebug("res2: %s", res.c_str()); - - if (res[0] == 'H') - { - nlwarning("missing response body: %s", res.c_str()); - return "missing response body (error code 66)"; - } - else if(res[0] == '0') - { - // server returns an error - nlwarning("server error: %s", res.substr(2).c_str()); - return res.substr(2); - } - else if(res[0] == '1') - { - // server returns ok, we have the access - - vector line; - explode(res, std::string(" "), line, true); - - if (line.size() < 2 || line.size() > 3) - { - nlwarning("bad launch lines number %d != %d", line.size(), 2); - return "bad launch line number (error code 14)"; - } - - cookie = line[0].substr(2); - addr = line[1]; - - std::vector patchURIs; - - CShard* shard = NULL; - uint i; - for (i=0; i= 3) - { - explode(line[2], "|", shard->PatchURIs, true); - - nlinfo("received %d main patch server URIs:", shard->PatchURIs.size()); - uint i; - for (i=0; iPatchURIs.size(); ++i) - nlinfo("%d: '%s'", i, shard->PatchURIs[i].c_str()); - } -*/ - } - else - { - // server returns ??? - nlwarning("%s", res.c_str()); - return res; - } - - return ""; -} - - -/*void mainLandPatch() -{ - if (!AvailablePatchs) return; - nlassert(AvailablePatchs & (1 << BGDownloader::DownloadID_MainLand)); // only handled case for now - // no-op - BGDownloaderWantedPatch = BGDownloader::DownloadID_MainLand; - CInterfaceManager *im = CInterfaceManager::getInstance(); - im->initLogin(); - // login machine should be in the 'end' state !! - nlassert(LoginSM.getCurrentState() == CLoginStateMachine::st_end); - LoginSM.pushEvent(CLoginStateMachine::ev_mainland_patch); - loginMainLoop(); // patch is handled in the login mainloop - // there should have been a reboot there, so quit if something went wrong... - release(); - exit(0); -} -*/ - - - -// *************************************************************************** -// *************************************************************************** -// INTRO HANDLING -// *************************************************************************** -// *************************************************************************** - -#include "init_main_loop.h" - -bool loginIntroSkip; - -void loginIntro() -{ - // Display of nevrax logo is done at init time (see init.cpp) just before addSearchPath (second one) - for (uint i = 0; i < 1; i++) // previously display nevrax then nvidia - { - if (i != 0) - { - beginLoading(IntroNVidia); - ucstring nmsg(""); - ProgressBar.newMessage (nmsg); - } - - Driver->AsyncListener.reset(); - updateClientTime(); - CInputHandlerManager::getInstance()->pumpEventsNoIM(); - updateClientTime(); - - loginIntroSkip = false; - - sint64 CurTime = T0; - - while (loginIntroSkip == false) - { - updateClientTime(); - if ((T0 - CurTime) > 5000) // 5s before quiting - break; - // Update messages - CInputHandlerManager::getInstance()->pumpEventsNoIM(); - - // Exit ? - if (Driver->AsyncListener.isKeyPushed (KeyESCAPE) || Driver->AsyncListener.isKeyPushed (KeyRETURN) || - Driver->AsyncListener.isKeyPushed (KeySPACE)) - break; - - const ucstring nmsg(""); - ProgressBar.newMessage (nmsg); - IngameDbMngr.flushObserverCalls(); - NLGUI::CDBManager::getInstance()->flushObserverCalls(); - } - } - beginLoading(StartBackground); - ProgressBar.finish(); -} diff --git a/code/ryzom/client/src/net_manager.cpp b/code/ryzom/client/src/net_manager.cpp deleted file mode 100644 index ada437ec7..000000000 --- a/code/ryzom/client/src/net_manager.cpp +++ /dev/null @@ -1,4414 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010-2019 Winch Gate Property Limited -// -// This source file has been modified by the following contributors: -// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2014-2019 Jan BOON (Kaetemi) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - - -///////////// -// INCLUDE // -///////////// -#include "stdpch.h" -// Game Share -#include "game_share/generic_xml_msg_mngr.h" -#include "game_share/msg_client_server.h" -#include "game_share/bot_chat_types.h" -#include "game_share/mode_and_behaviour.h" -#include "game_share/chat_group.h" -#include "game_share/character_summary.h" -#include "game_share/sphrase_com.h" -#include "game_share/outpost.h" -#include "game_share/msg_client_server.h" -#include "game_share/ryzom_database_banks.h" -#include "game_share/msg_encyclopedia.h" -#include "game_share/prerequisit_infos.h" -#include "game_share/permanent_ban_magic_number.h" -#include "game_share/item_special_effect.h" -#include "game_share/combat_flying_text.h" -#include "game_share/shard_names.h" -// Client. -#include "nel/gui/group_list.h" -#include "interface_v3/interface_manager.h" -#include "net_manager.h" -#include "client_cfg.h" -#include "entities.h" -#include "client_chat_manager.h" -#include "world_database_manager.h" -#include "continent_manager.h" -#include "motion/user_controls.h" -#include "interface_v3/bot_chat_manager.h" -#include "interface_v3/bot_chat_page_all.h" -#include "interface_v3/bot_chat_page_trade.h" -#include "interface_v3/bot_chat_page_create_guild.h" -#include "interface_v3/obs_huge_list.h" -#include "string_manager_client.h" -#include "interface_v3/people_interraction.h" -#include "interface_v3/bot_chat_manager.h" -#include "interface_v3/bot_chat_page_all.h" -#include "nel/gui/view_text_id.h" -#include "nel/gui/ctrl_text_button.h" -#include "interface_v3/input_handler_manager.h" -#include "interface_v3/guild_manager.h" -#include "interface_v3/skill_manager.h" -#include "misc.h" -#include "interface_v3/inventory_manager.h" -#include "interface_v3/sphrase_manager.h" -#include "outpost_manager.h" -#include "interface_v3/encyclopedia_manager.h" -#include "user_entity.h" -#include "init_main_loop.h" -#include "interface_v3/group_map.h" -#include "sound_manager.h" -#include "interface_v3/group_compas.h" -#include "interface_v3/group_html_webig.h" -#include "interface_v3/bar_manager.h" -#include "permanent_ban.h" -#include "global.h" -#include "connection.h" -#include "faction_war_manager.h" -#include "far_tp.h" -#include "input.h" -#include "r2/editor.h" -#include "game_share/r2_share_itf.h" -#include "game_share/r2_types.h" -#include "npc_icon.h" -#include "interface_v3/action_handler_base.h" - -// Std. -#include - -#ifdef DEBUG_NEW -#define new DEBUG_NEW -#endif - -#define OLD_STRING_SYSTEM -#define BAR_STEP_TP 2 - -/////////// -// USING // -/////////// -using namespace NLMISC; -using namespace NL3D; -using namespace std; - - -extern bool FirstFrame; -extern void selectTipsOfTheDay (uint tips); - - -//////////// -// GLOBAL // -//////////// -CGenericXmlMsgHeaderManager GenericMsgHeaderMngr; // Manage messages -#ifdef CLIENT_MULTI -CNetManagerMulti NetMngr; // Manage the connection. -#else -CNetManager NetMngr; // Manage the connection. -#endif - -bool UseFemaleTitles = false; - -bool serverReceivedReady = false; - -static const std::string PLAYER_EXCHANGE_INVITATION_DIALOG = "ui:interface:accept_trade_invitation"; - -// Hierarchical timer -H_AUTO_DECL ( RZ_Client_Net_Mngr_Update ) - -//////////// -// EXTERN // -//////////// -extern bool noUserChar; // \todo GUIGUI : do this better. -extern bool userChar; // \todo GUIGUI : do this better. -extern std::vector CharacterSummaries; -extern uint8 ServerPeopleActive; -extern uint8 ServerCareerActive; -extern vector Mainlands; -extern bool UserCharPosReceived; -extern CGenericXmlMsgHeaderManager GenericMsgHeaderMngr; -extern CClientChatManager ChatMngr; - -extern bool CharNameValidArrived; -extern bool CharNameValid; -bool IsInRingSession = false; -TSessionId HighestMainlandSessionId; // highest in the position stack -ucstring lastUniversMessage; - -extern const char *CDBBankNames[INVALID_CDB_BANK+1]; - -void cbImpulsionGatewayOpen(NLMISC::CBitMemStream &bms); -void cbImpulsionGatewayMessage(NLMISC::CBitMemStream &bms); -void cbImpulsionGatewayClose(NLMISC::CBitMemStream &bms); - - - -/////////////// -// FUNCTIONS // -/////////////// - -void impulseDatabaseInitPlayer(NLMISC::CBitMemStream &impulse) -{ - try - { - sint32 p = impulse.getPos(); - - // get the egs tick of this change - TGameCycle serverTick; - impulse.serial(serverTick); - - // read delta - IngameDbMngr.readDelta( serverTick, impulse, CDBPlayer ); - IngameDbMngr.setInitPacketReceived(); - nlinfo( "DB_INIT:PLR done (%u bytes)", impulse.getPos()-p ); - } - catch (const Exception &e) - { - BOMB( NLMISC::toString( "Problem while decoding a DB_INIT:PLR msg, skipped: %s", e.what() ), return ); - } -} - -void impulseDatabaseUpdatePlayer(NLMISC::CBitMemStream &impulse) -{ - try - { - // get the egs tick of this change - TGameCycle serverTick; - impulse.serial(serverTick); - - // read delta - IngameDbMngr.readDelta( serverTick, impulse, CDBPlayer ); // unlike on the server, here there is only one unified CCDBSynchronized object - } - catch (const Exception &e) - { - - BOMB( NLMISC::toString( "Problem while decoding a DB_UPDATE_PLR msg, skipped: %s", e.what() ), return ); - } -} - -template -void updateInventoryFromStream(NLMISC::CBitMemStream &impulse, const CInventoryCategoryTemplate *templ, bool notifyItemSheetChanges); - -void impulseDatabaseUpdateBank(NLMISC::CBitMemStream &impulse) -{ - uint32 bank = INVALID_CDB_BANK; - try - { - // get the egs tick of this change - TGameCycle serverTick; - impulse.serial(serverTick); - - // decode bank - uint nbits; - FILL_nbits_WITH_NB_BITS_FOR_CDBBANK - impulse.serial( bank, nbits ); - - // read delta - IngameDbMngr.readDelta( serverTick, impulse, (TCDBBank)bank ); - - // read guild inventory update - if ( bank == CDBGuild ) - { - updateInventoryFromStream( impulse, (INVENTORIES::CInventoryCategoryForGuild*)NULL, false ); - } - } - catch (const Exception &e) - { - BOMB( NLMISC::toString( "Problem while decoding a DB_GROUP:UPDATE_BANK %s msg, skipped: %s", CDBBankNames[bank], e.what() ), return ); - } -} - -void impulseDatabaseInitBank(NLMISC::CBitMemStream &impulse) -{ - uint32 bank = INVALID_CDB_BANK; - try - { - // get the egs tick of this change - TGameCycle serverTick; - impulse.serial(serverTick); - - // decode bank - uint nbits; - FILL_nbits_WITH_NB_BITS_FOR_CDBBANK - impulse.serial( bank, nbits ); - - // read delta - IngameDbMngr.readDelta( serverTick, impulse, (TCDBBank)bank ); - nldebug( "CDB: DB_GROUP:INIT_BANK %s", CDBBankNames[bank] ); - - // read guild inventory update - if ( bank == CDBGuild ) - { - updateInventoryFromStream( impulse, (INVENTORIES::CInventoryCategoryForGuild*)NULL, false ); - } - } - catch (const Exception &e) - { - BOMB( NLMISC::toString( "Problem while decoding a DB_GROUP:INIT_BANK %s msg, skipped: %s", CDBBankNames[bank], e.what() ), return ); - } -} - -void impulseDatabaseResetBank(NLMISC::CBitMemStream &impulse) -{ - uint32 bank = INVALID_CDB_BANK; - try - { - // get the egs tick of this change - TGameCycle serverTick; - impulse.serial(serverTick); - - // read the bank to reset - uint nbits; - FILL_nbits_WITH_NB_BITS_FOR_CDBBANK - impulse.serial( bank, nbits ); - - // reset the bank - IngameDbMngr.resetBank( serverTick, bank ); - nldebug( "CDB: DB_GROUP:RESET_BANK %s", CDBBankNames[bank] ); - } - catch (const Exception &e) - { - BOMB( NLMISC::toString( "Problem while decoding a DB_GROUP:RESET_BANK %s msg, skipped: %s", CDBBankNames[bank], e.what() ), return ); - } -} - -static void readPrivileges(NLMISC::CBitMemStream &impulse) -{ - nlassert(impulse.isReading()); - // nico : temporarily uses a try block here to avoid prb with people having updated client and not the server - try - { - impulse.serial(UserPrivileges); - } - catch(const EStreamOverflow &) - { - nlwarning("User privileges not serialised, assuming none"); - UserPrivileges.clear(); - } -} - -void impulseNoUserChar(NLMISC::CBitMemStream &impulse) -{ - // received NO_USER_CHAR - //nlinfo("impulseCallBack : Received CONNECTION:NO_USER_CHAR"); - - impulse.serial(ServerPeopleActive); - impulse.serial(ServerCareerActive); - readPrivileges(impulse); - impulse.serialCont(Mainlands); - CharacterSummaries.clear(); - noUserChar = true; - - LoginSM.pushEvent(CLoginStateMachine::ev_no_user_char); - - updatePatcherPriorityBasedOnCharacters(); -} - -void impulseFarTP(NLMISC::CBitMemStream &impulse) -{ - // received FAR_TP - TSessionId sessionId; - impulse.serial(sessionId); - //nlinfo("impulseCallback : Received CONNECTION:FAR_TP %u", sessionId.asInt()); - bool bailOutIfSessionVanished; - impulse.serial(bailOutIfSessionVanished); - FarTP.requestFarTPToSession(sessionId, PlayerSelectedSlot, CFarTP::JoinSession, bailOutIfSessionVanished); -} - - -static std::string lookupSrcKeyFile(const std::string &src) -{ - if (CFile::isExists("save/" + src)) return "save/" + src; - return CPath::lookup(src, false); -} - -void copyKeySet(const std::string &srcPath, const std::string &destPath) -{ - // can't use CFile copyFile here, because src may be in a bnp file - std::string srcStr; - srcStr.resize(CFile::getFileSize(srcPath)); - if (srcStr.empty()) - { - nlwarning("Can't copy keys from %s : file not found or empty"); - return; - } - try - { - CIFile ifile(srcPath); - ifile.serialBuffer((uint8 *) &srcStr[0], (uint)srcStr.size()); - COFile ofile(destPath); - ofile.serialBuffer((uint8 *) &srcStr[0], (uint)srcStr.size()); - } - catch(const EStream &) - { - nlwarning("Couldn't copy %s to %s to create new character keyset", srcPath.c_str(), destPath.c_str()); - } -} - -void impulseUserChars(NLMISC::CBitMemStream &impulse) -{ - // received USER_CHARS - //nlinfo("impulseCallBack : Received CONNECTION:USER_CHARS"); - - impulse.serial(ServerPeopleActive); - impulse.serial(ServerCareerActive); - // read characters summary - CharacterSummaries.clear(); - impulse.serialCont (CharacterSummaries); - // read shard name summaries - std::vector shardNames; - impulse.serialCont (shardNames); - CShardNames::getInstance().loadShardNames(shardNames); - // read privileges - readPrivileges(impulse); - impulse.serial(FreeTrial); - FreeTrial = false; - impulse.serialCont(Mainlands); - userChar = true; - - LoginSM.pushEvent(CLoginStateMachine::ev_chars_received); - - // Create the message for the server to select the first character. -/* CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream("CONNECTION:SELECT_CHAR", out)) - { - CSelectCharMsg SelectCharMsg; - SelectCharMsg.c = 0; //TODO set here the character choosen by player - out.serial( SelectCharMsg ); - NetMngr.push(out); - NetMngr.send(NetMngr.getCurrentServerTick()); - // send CONNECTION:USER_CHARS - nldebug("impulseCallBack : CONNECTION:SELECT_CHAR sent"); - } - else - nlwarning("impulseCallBack : unknown message name : 'CONNECTION:SELECT_CHAR'."); - - noUserChar = true; - */ - - if (!NewKeysCharNameValidated.empty()) - { - // if there's a new char for which a key set was wanted, create it now - for (uint k = 0; k < CharacterSummaries.size(); ++k) - { - if (toLower(CharacterSummaries[k].Name) == toLower(NewKeysCharNameValidated)) - { - // first, stripes server name - copyKeySet(lookupSrcKeyFile(GameKeySet), "save/keys_" + buildPlayerNameForSaveFile(NewKeysCharNameValidated) + ".xml"); - copyKeySet(lookupSrcKeyFile(RingEditorKeySet), "save/keys_r2ed_" + buildPlayerNameForSaveFile(NewKeysCharNameValidated) + ".xml"); - break; - } - } - } - updatePatcherPriorityBasedOnCharacters(); -} - -void impulseUserChar(NLMISC::CBitMemStream &impulse) -{ - // received USER_CHAR - //nlinfo("impulseCallBack : Received CONNECTION:USER_CHAR"); - - // Serialize the message - COfflineEntityState posState; - extern uint8 ServerSeasonValue; - extern bool ServerSeasonReceived; - uint32 userRole; - CUserCharMsg::read( impulse, posState, ServerSeasonValue, userRole, IsInRingSession, HighestMainlandSessionId, CharFirstConnectedTime, CharPlayedTime ); - ServerSeasonReceived = true; // set the season that will be used when selecting the continent from the position - - if (UserEntity) - { - UserEntity->pos(CVectorD((float)posState.X/1000.0f, (float)posState.Y/1000.0f, (float)posState.Z/1000.0f)); - UserEntity->front(CVector((float)cos(posState.Heading), (float)sin(posState.Heading), 0.f)); - UserEntity->dir(UserEntity->front()); - UserEntity->setHeadPitch(0); - UserControls.resetCameraDeltaYaw(); - //nldebug(" pos : %f %f %f heading : %f",UserEntity->pos().x,UserEntity->pos().y,UserEntity->pos().z,posState.Heading); - - // Update the position for the vision. - NetMngr.setReferencePosition(UserEntity->pos()); - } - else - { - UserEntityInitPos = CVectorD((float)posState.X/1000.0f, (float)posState.Y/1000.0f, (float)posState.Z/1000.0f); - UserEntityInitFront = CVector((float)cos(posState.Heading), (float)sin(posState.Heading), 0.f); - //nldebug(" pos : %f %f %f heading : %f",UserEntityInitPos.x,UserEntityInitPos.y,UserEntityInitPos.z,posState.Heading); - - // Update the position for the vision. - NetMngr.setReferencePosition(UserEntityInitPos); - } - - UserCharPosReceived = true; - - // Configure the ring editor - extern R2::TUserRole UserRoleInSession; - UserRoleInSession = R2::TUserRole::TValues(userRole); - ClientCfg.R2EDEnabled = IsInRingSession /*&& (UserRoleInSession.getValue() != R2::TUserRole::ur_player)*/; - // !!!Do NOT uncomment the following line do the ClientCfg.R2EDEnabled = IsInRingSession && (UserRoleInSession != R2::TUserRole::ur_player); - // even with UserRoleInSession R2::TUserRole::ur_player the ring features must be activated - // because if the ring is not activated the dss do not know the existence of the player - // So we can not kick him, tp to him, tp in to next act .... - nldebug( "EnableR2Ed = %u, IsInRingSession = %u, UserRoleInSession = %u", (uint)ClientCfg.R2EDEnabled, (uint)IsInRingSession, userRole ); - - updatePatcherPriorityBasedOnCharacters(); -} - -void impulseCharNameValid(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallBack : Received CONNECTION:VALID_NAME"); - uint8 nTmp; - impulse.serial(nTmp); - CharNameValid = ((nTmp != 0) ? true : false); - CharNameValidArrived = true; - if (CharNameValid) NewKeysCharNameValidated = NewKeysCharNameWanted; -} - - -void checkHandshake( NLMISC::CBitMemStream &impulse ) -{ - // Decode handshake to check versions - uint16 handshakeVersion; - uint16 itemSlotVersion; - impulse.serial( handshakeVersion ); - if ( handshakeVersion > 0 ) - nlerror( "Server handshake version is more recent than client one" ); - impulse.serial( itemSlotVersion ); - if ( itemSlotVersion != INVENTORIES::CItemSlot::getVersion() ) - nlerror( "Handshake: itemSlotVersion mismatch (S:%hu C:%hu)", itemSlotVersion, INVENTORIES::CItemSlot::getVersion() ); -} - - -void impulseServerReady(NLMISC::CBitMemStream &impulse) -{ - // received CONNECTION:READY - //nlinfo("impulseCallBack : Received CONNECTION:READY"); - - serverReceivedReady = true; - - checkHandshake( impulse ); - - LoginSM.pushEvent(CLoginStateMachine::ev_ready_received); -} - -void impulseShardId(NLMISC::CBitMemStream &impulse) -{ - // received SHARD_ID - - uint32 shardId; - impulse.serial(shardId); - ShardId = shardId; - - string webHost; - impulse.serial(webHost); - if (!webHost.empty()) - { - WebServer = webHost; - } - - nlinfo("WEB: Received SHARD_ID %d, web hosted at '%s', using '%s'", shardId, webHost.c_str(), WebServer.c_str()); -} - -void impulseServerQuitOk(NLMISC::CBitMemStream &impulse) -{ - // receive CONNECTION:SERVER_QUIT_OK - if (FarTP.isFarTPInProgress()) - { - FarTP.onServerQuitOk(); - } - else - { - // ensure first a quit request is really asked - if(game_exit_request) - { - // quit! - game_exit= true; - ryzom_exit= true; - } - } -} - -void impulseServerQuitAbort(NLMISC::CBitMemStream &impulse) -{ - // receive CONNECTION:SERVER_QUIT_ABORT - if (FarTP.isFarTPInProgress()) - { - FarTP.onServerQuitAbort(); - } - else - { - // abort any quit request - game_exit_request= false; - ryzom_exit_request= false; - } -} - -void impulseMailNotification(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - // receive CONNECTION:MAIL_AVAILABLE - CInterfaceManager::getInstance()->notifyMailAvailable(); -} - -void impulseForumNotification(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - // receive CONNECTION:GUILD_MESSAGE_AVAILABLE - CInterfaceManager::getInstance()->notifyForumUpdated(); - -} - -void impulsePermanentBan(NLMISC::CBitMemStream &impulse) -{ - uint64 magicNumber; - impulse.serial(magicNumber); - if (magicNumber != PermanentBanMSGMagicNumber) return; // bad msg - setPermanentBanMarkers(true); - applyPermanentBanPunishment(); - PermanentlyBanned = true; -} - -void impulsePermanentUnban(NLMISC::CBitMemStream &impulse) -{ - uint64 magicNumber; - impulse.serial(magicNumber); - if (magicNumber != PermanentUnbanMSGMagicNumber) return; // bad msg - setPermanentBanMarkers(false); - PermanentlyBanned = false; - if (UserEntity) - { - // allows to walk / run again - UserEntity->walkVelocity(ClientCfg.Walk); - UserEntity->runVelocity(ClientCfg.Run); - } -} - - -// *************************************************************************** -class CInterfaceChatDisplayer : public CClientChatManager::IChatDisplayer -{ -public: - virtual void displayChat(TDataSetIndex compressedSenderIndex, const ucstring &ucstr, const ucstring &rawMessage, CChatGroup::TGroupType mode, NLMISC::CEntityId dynChatId, ucstring &senderName, uint bubbleTimer=0); - virtual void displayTell(/*TDataSetIndex senderIndex, */const ucstring &ucstr, const ucstring &senderName); - virtual void clearChannel(CChatGroup::TGroupType mode, uint32 dynChatDbIndex); - -private: - // Add colorization tag for sender name - void colorizeSender(ucstring &text, const ucstring &senderName, CRGBA baseColor); - -}; -static CInterfaceChatDisplayer InterfaceChatDisplayer; - -void CInterfaceChatDisplayer::colorizeSender(ucstring &text, const ucstring &senderName, CRGBA baseColor) -{ - // find the sender/text separator to put color tags - ucstring::size_type pos = senderName.length() - 1; - if (pos != ucstring::npos) - { - ucstring str; - - CInterfaceProperty prop; - prop.readRGBA("UI:SAVE:CHAT:COLORS:SPEAKER"," "); - - CChatWindow::encodeColorTag(prop.getRGBA(), str, false); - - str += text.substr(0, pos+1); - - CChatWindow::encodeColorTag(baseColor, str, true); - - str += text.substr(pos+1); - - text.swap(str); - } -} - -// display a chat from network to interface -void CInterfaceChatDisplayer::displayChat(TDataSetIndex compressedSenderIndex, const ucstring &ucstr, const ucstring &rawMessage, CChatGroup::TGroupType mode, NLMISC::CEntityId dynChatId, ucstring &senderName, uint bubbleTimer) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - ucstring finalString; - string stringCategory = getStringCategory(ucstr, finalString); - - bool bubbleWanted = true; - - // Subtract rawMessage from ucstr so that the 'sender' part remains. - ucstring senderPart = ucstr.luabind_substr(0, ucstr.length() - rawMessage.length()); - - // search a "{no_bubble}" tag - { - ucstring::size_type index = finalString.find(ucstring("{no_bubble}")); - const size_t tokenSize= 11; // length of "{no_bubble}" - if (index != ucstring::npos) - { - bubbleWanted = false; - finalString = finalString.luabind_substr(0, index) + finalString.substr(index+tokenSize,finalString.size()); - } - } - - - // **** get color - CRGBA col; - if (mode != CChatGroup::system) - { - // Remove all {break} - for(;;) - { - ucstring::size_type index = finalString.find(ucstring("{break}")); - if (index == ucstring::npos) break; - finalString = finalString.luabind_substr(0, index) + finalString.luabind_substr(index+7,finalString.size()); - } - - // select DB - sint32 dbIndex = ChatMngr.getDynamicChannelDbIndexFromId(dynChatId); - clamp(dbIndex, (sint32)0 , (sint32)CChatGroup::MaxDynChanPerPlayer); - string entry="UI:SAVE:CHAT:COLORS:"; - switch(mode) - { - case CChatGroup::dyn_chat: entry+="DYN:" + NLMISC::toString(dbIndex); break; - case CChatGroup::say: entry+="SAY"; break; - case CChatGroup::shout: entry+="SHOUT"; break; - case CChatGroup::team: entry+="GROUP"; break; - case CChatGroup::guild: entry+="CLADE"; break; - case CChatGroup::civilization: entry+="CIVILIZATION"; break; - case CChatGroup::territory: entry+="TERRITORY"; break; - case CChatGroup::universe: entry+="UNIVERSE_NEW"; break; - case CChatGroup::region: entry+="REGION"; break; - case CChatGroup::tell: entry+="TELL"; break; - default: nlwarning("unknown group type"); return; - } - - // read DB - CInterfaceProperty prop; - prop.readRGBA(entry.c_str()," "); - col = prop.getRGBA(); - - // Override color if the string contains the color - if (!stringCategory.empty() && stringCategory != "SYS") - { - map::const_iterator it; - it = ClientCfg.SystemInfoParams.find(toLower(stringCategory)); - if (it != ClientCfg.SystemInfoParams.end()) - { - col = it->second.Color; - } - } - } - - if (stringCategory == "emt") - { - bubbleWanted = false; - } - - if (mode != CChatGroup::system) - { - // find the sender/text separator to put color tags - if (senderPart.empty() && stringCategory == "emt") - { - size_t pos = finalString.find(ucstring(": "), 0); - if (pos != ucstring::npos) - { - senderPart = finalString.luabind_substr(0, pos + 2); - } - } - colorizeSender(finalString, senderPart, col); - } - - // play associated fx if any - if( !stringCategory.empty() ) - { - map::const_iterator it; - it = ClientCfg.SystemInfoParams.find( toLower(stringCategory) ); - if( it != ClientCfg.SystemInfoParams.end() ) - { - if( !(*it).second.SysInfoFxName.empty() ) - { - NL3D::UParticleSystemInstance sysInfoFx = FXMngr.instantFX((*it).second.SysInfoFxName); - if( !sysInfoFx.empty() ) - { - sysInfoFx.setClusterSystem( UserEntity->getClusterSystem() ); - sysInfoFx.setPos( UserEntity->pos() ); - } - else - { - nlwarning(" Can't set chat fx %s",(*it).second.SysInfoFxName.c_str()); - } - } - } - } - - // **** redirect to the correct interface output - if( stringCategory != "bbl" ) - { - bool windowVisible; - if (mode == CChatGroup::system) - { - pIM->displaySystemInfo(finalString, stringCategory); - } - else if (mode == CChatGroup::guild) - { - PeopleInterraction.ChatInput.Guild.displayMessage(finalString, col, 2, &windowVisible); - } - else if (mode == CChatGroup::team) - { - PeopleInterraction.ChatInput.Team.displayMessage(finalString, col, 2, &windowVisible); - } - else if (mode == CChatGroup::region) - { - PeopleInterraction.ChatInput.Region.displayMessage(finalString, col, 2, &windowVisible); - } - else if (mode == CChatGroup::universe) - { - if (lastUniversMessage != finalString) - { - PeopleInterraction.ChatInput.Universe.displayMessage(finalString, col, 2, &windowVisible); - lastUniversMessage = finalString; - } - } - else if (mode == CChatGroup::dyn_chat) - { - // retrieve the DBIndex from the dynamic chat id - sint32 dbIndex= ChatMngr.getDynamicChannelDbIndexFromId(dynChatId); - // if found, display, else discarded - if(dbIndex >= 0 && dbIndex < CChatGroup::MaxDynChanPerPlayer) - { - PeopleInterraction.ChatInput.DynamicChat[dbIndex].displayMessage(finalString, col, 2, &windowVisible); - - // Add dynchannel info before text so that the chat log will show the correct string. - CCDBNodeLeaf* node = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CHAT:SHOW_DYN_CHANNEL_NAME_IN_CHAT_CB", false); - if (pIM->getLogState()) - { - // Add dyn chan number before string - ucstring prefix("[" + NLMISC::toString(dbIndex) + "]"); - // Find position to put the new string - // After timestamp? - size_t pos = finalString.find(ucstring("]")); - size_t colonpos = finalString.find(ucstring(": @{")); - // If no ] found or if found but after the colon (so part of the user chat) - if (pos == ucstring::npos || (colonpos < pos)) - { - // No timestamp, so put it right after the color and add a space - pos = finalString.find(ucstring("}"));; - prefix += " "; - } - finalString = finalString.substr(0, pos + 1) + prefix + finalString.substr(pos + 1); - - if (node && node->getValueBool()) - { - uint32 textId = ChatMngr.getDynamicChannelNameFromDbIndex(dbIndex); - ucstring title; - STRING_MANAGER::CStringManagerClient::instance()->getDynString(textId, title); - prefix = title.empty() ? ucstring("") : ucstring(" ") + title; - pos = finalString.find(ucstring("] ")); - finalString = finalString.substr(0, pos) + prefix + finalString.substr(pos); - } - } - } - else - { - nlwarning("Dynamic chat %s not found for message: %s", dynChatId.toString().c_str(), finalString.toString().c_str()); - } - } - else - { - ucstring::size_type index = finalString.find(ucstring("")); - if (index != ucstring::npos) - { - bubbleWanted = false; - finalString = finalString.substr(index+6,finalString.size()); - ucstring::size_type index2 = finalString.find(ucstring(" ")); - ucstring playerName; - if (index2 < (finalString.size()-3)) - { - playerName = finalString.substr(0,index2); - finalString = finalString.substr(index2+1,finalString.size()); - } - if (!senderName.empty()) - { - CEntityCL *senderEntity = EntitiesMngr.getEntityByName (CEntityCL::removeTitleAndShardFromName(senderName), true, true); - if (senderEntity) - { - if (senderEntity->Type != CEntityCL::Player) - { - if (playerName.empty()) - { - senderEntity->removeStateFx(); - senderEntity->setStateFx(finalString.toString()); - nlinfo("empty"); - } - else - { - CEntityCL *destEntity = EntitiesMngr.getEntityByName (CEntityCL::removeTitleAndShardFromName(playerName), false, true); - if (destEntity) - { - destEntity->removeStateFx(); - destEntity->setStateFx(finalString.toString()); - nlinfo("no empty"); - } - } - } - } - } - finalString.clear(); - } - else - { - PeopleInterraction.ChatInput.AroundMe.displayMessage(finalString, col, 2, &windowVisible); - } - } - // if tell, bkup sendername - if (mode == CChatGroup::tell && windowVisible && !senderName.empty()) - { - PeopleInterraction.LastSenderName = CEntityCL::removeTitleAndShardFromName(senderName); - } - } - - // received CHAT - //nldebug(" Received CHAT : %s with category %s",finalString.toString().c_str(),stringCategory.c_str()); - - - // **** Process chat entry for the bubbles - // todo hulud : registering a chat callback would be better than calling this hardcoded action handler - ucstring finalRawMessage; - // remove color qualifier from raw string - getStringCategory(rawMessage, finalRawMessage); - if (bubbleWanted) - { - InSceneBubbleManager.chatOpen(compressedSenderIndex, finalRawMessage, bubbleTimer); - } - - // Log - - string channel; - if (mode == CChatGroup::dyn_chat) - { - sint32 dbIndex = ChatMngr.getDynamicChannelDbIndexFromId(dynChatId); - clamp(dbIndex, (sint32)0 , (sint32)CChatGroup::MaxDynChanPerPlayer); - - channel = "dyn" + toString(dbIndex); - } - else - { - channel = CChatGroup::groupTypeToString(mode); - if (channel.empty()) - { - channel = "#" + toString((uint32)mode); - } - } - if (!stringCategory.empty() && NLMISC::toUpper(stringCategory) != "SYS") - { - channel = channel + "/" + stringCategory; - } - pIM->log (finalString, channel); - -} - - -// display a tell from network to interface -void CInterfaceChatDisplayer::displayTell(/*TDataSetIndex senderIndex, */const ucstring &ucstr, const ucstring &senderName) -{ - - ucstring finalString = ucstr; - - // for now, '&' are removed by server so use another format until a special msg is made - if (strFindReplace(finalString, ucstring(""), ucstring())) - { - CLuaManager::getInstance().executeLuaScript("RingAccessPoint:forceRefresh()"); - } - - - CInterfaceProperty prop; - prop.readRGBA("UI:SAVE:CHAT:COLORS:TELL"," "); - bool windowVisible; - - ucstring goodSenderName = CEntityCL::removeTitleAndShardFromName(senderName); - - // The sender part is up to and including the first ":" after the goodSenderName - ucstring::size_type pos = finalString.find(goodSenderName); - pos = finalString.find(':', pos); - pos = finalString.find(' ', pos); - ucstring senderPart = finalString.substr(0, pos+1); - colorizeSender(finalString, senderPart, prop.getRGBA()); - - PeopleInterraction.ChatInput.Tell.displayTellMessage(/*senderIndex, */finalString, goodSenderName, prop.getRGBA(), 2, &windowVisible); - CInterfaceManager::getInstance()->log(finalString, CChatGroup::groupTypeToString(CChatGroup::tell)); - - // Open the free teller window - CChatGroupWindow *pCGW = PeopleInterraction.getChatGroupWindow(); - if (pCGW != NULL) - pCGW->setActiveFreeTeller(goodSenderName); - - if (windowVisible && !goodSenderName.empty()) - PeopleInterraction.LastSenderName = goodSenderName; -} - -// clear a channel -void CInterfaceChatDisplayer::clearChannel(CChatGroup::TGroupType mode, uint32 dynChatDbIndex) -{ - if (mode == CChatGroup::guild) PeopleInterraction.ChatInput.Guild.clearMessages(); - else if (mode == CChatGroup::team) PeopleInterraction.ChatInput.Team.clearMessages(); - else if (mode == CChatGroup::region) PeopleInterraction.ChatInput.Region.clearMessages(); - else if (mode == CChatGroup::arround) PeopleInterraction.ChatInput.AroundMe.clearMessages(); - else if (mode == CChatGroup::universe) PeopleInterraction.ChatInput.Universe.clearMessages(); - else if (mode == CChatGroup::dyn_chat) - { - // if correct dbIndex, clear - if(dynChatDbIndex code; -// if( huff ) -// { -// impulse.serialCont( code ); -// } -// if (PermanentlyBanned) return; -// #ifdef OLD_STRING_SYSTEM -// ChatMngr.getDynamicDB().add( index, ucstr, code ); -// #else -// nlwarning( "// TRAP // WE MUST NEVER CALL THIS IMPULE ANYMORE : ALL IS HANDLED BY STRING_MANAGER NOW !!!" ); -// #endif -// -// // received ADD_DYN_STR -// nlinfo("impulseCallBack : Received ADD_DYN_STR : adding %s at index %d",ucstr.toString().c_str(),index); -//} -/* -string getInterfaceNameFromId (sint botType, sint interfaceId) -{ - string interfaceName = "ui:interface:bot_chat_"; - - switch (botType) - { - case 0: interfaceName += "figurant_"; break; - case 1: interfaceName += "figurant_presse_"; break; - case 2: interfaceName += "chef_village_"; break; - default: interfaceName += "figurant_"; break; - } - - switch (interfaceId) - { - case BOTCHATTYPE::Intro: interfaceName += "intro"; break; - case BOTCHATTYPE::FriendlyMainPage: interfaceName += "friendly_main"; break; - case BOTCHATTYPE::NeutralMainPage: interfaceName += "neutral_main"; break; - case BOTCHATTYPE::NastyMainPage: interfaceName += "nasty_main"; break; - case BOTCHATTYPE::MoreNewsPage: interfaceName += "more_news"; break; - case BOTCHATTYPE::Done: nlinfo ("end of bot chat"); interfaceName.clear(); break; - } - return interfaceName; -} - -static char *shortNews[] = { - "The wind is sour and brings only bad tidings...", "Kitins have been sighted near the village!", "", - "The tribe of the Black Circle has recently", "increased its activities in our region.", "", - "The Black Circle has made an incursion", "into our territory!", "", - "The Black Circle has been sighted near one", "of our forward posts, deep in dangerous territory.", "", - "The tide has washed up evil news, friend.", "The Black Circle is active in our region.", "", - "Our people suffer from a debilitating shortage.", "We are in sore need of KamiBast.", "", - "The economy is slow and our reserve of", "Live Seed low.", "", - "We are in sore need of Live Seed", "If there is a Goo epidemic, we shall all perish!", "", - "Our master mages have gotten wind of", "the growing Kami discontentment", "", -}; - -static char *longNews[] = { - "These powerful predators haven't come this near", "to the village since their devastating attack", "over 15 seasons ago!", - "They are after more KamiBast", "for their occult practices.", "", - "They have captured", "2 of our fortifications in the bush!", "", - "They have taken over one of our richest sources", "of KamiBast, and are exploiting it", "for their own occult purposes.", - "They now hold an important source", "of Live Seed hostage,", "close to one of our forward posts.", - "We use the magical properties of KamiBast and", "its unusually rich fibers for all our crafts.", "", - "If we don't harvest new Seed soon,", "we will have no way of purchasing goods", "and resources, beyond what we produce ourselves", - "We use the rich Sap of Live Seed to produce", "an antidote that counters the disastrous", "effects of the Goo on all Atysian life forms.", - "The Kamis are shaken by the Black Circle's", "presence. If the Circle continues it's occult", "practices, we will all suffer the Kamic anger.", -}; -*/ -/* -void setFakeNews () -{ - char *table[] = { "figurant", "chef_village", "garde", "commercant" }; - - sint rnd = rand ()%(sizeof(shortNews)/sizeof(shortNews[0])/3); - rnd; - - for (uint i = 0; i < sizeof(table)/sizeof(table[0]); i++) - { - { // set test for the friendly main - string iname; - iname = "ui:interface:bot_chat_"; - iname += table[i]; - iname += "_friendly_main"; - - CInterfaceGroup *inter = CWidgetManager::getInstance()->getWindowFromId(iname); - if (inter == NULL) - { - nlwarning ("cant find interface 's%'", iname.c_str()); - continue; - } - - CViewText *inter2 = (CViewText *)inter->getView("title0"); - nlassert (inter2 != NULL); - inter2->setText(ucstring(shortNews[rnd*3])); - - CViewText *inter3 = (CViewText *)inter->getView("title1"); - nlassert (inter3 != NULL); - inter3->setText(ucstring(shortNews[rnd*3+1])); - - CViewText *inter4 = (CViewText *)inter->getView("title2"); - nlassert (inter4 != NULL); - inter4->setText(ucstring(shortNews[rnd*3+2])); - } - { // set test for the neutral main - string iname; - iname = "ui:interface:bot_chat_"; - iname += table[i]; - iname += "_neutral_main"; - - CInterfaceGroup *inter = CWidgetManager::getInstance()->getWindowFromId(iname); - if (inter == NULL) - { - nlwarning ("cant find interface 's%'", iname.c_str()); - continue; - } - - CViewText *inter2 = (CViewText *)inter->getView("title0"); - nlassert (inter2 != NULL); - inter2->setText(ucstring(shortNews[rnd*3])); - - CViewText *inter3 = (CViewText *)inter->getView("title1"); - nlassert (inter3 != NULL); - inter3->setText(ucstring(shortNews[rnd*3+1])); - } - { // set test for the more news - string iname; - iname = "ui:interface:bot_chat_"; - iname += table[i]; - iname += "_more_news"; - - CInterfaceGroup *inter = CWidgetManager::getInstance()->getWindowFromId(iname); - if (inter == NULL) - { - nlwarning ("cant find interface 's%'", iname.c_str()); - continue; - } - - CViewText *inter2 = (CViewText *)inter->getView("title0"); - nlassert (inter2 != NULL); - inter2->setText(ucstring(longNews[rnd*3])); - - CViewText *inter3 = (CViewText *)inter->getView("title1"); - nlassert (inter3 != NULL); - inter3->setText(ucstring(longNews[rnd*3+1])); - - CViewText *inter4 = (CViewText *)inter->getView("title2"); - nlassert (inter4 != NULL); - inter4->setText(ucstring(longNews[rnd*3+2])); - } - } -} -*/ - - - - - -//========================================= -/** Temp setup for choice list - */ -/* -static void setupBotChatChoiceList(CInterfaceGroup *botChatGroup) -{ - // Temp for test. Should then be read from server msg - std::vector choices; - for(uint k = 0; k < 90; ++k) - { - choices.push_back("Choice " + toString(k)); - } - CBotChat::setChoiceList(botChatGroup, choices, false); -} -*/ - -//========================================= -/** Temp setup for description list - */ -/* -static void setupBotChatDescription(CInterfaceGroup *botChatGroup) -{ - ucstring desc; - for(uint k = 0; k < 90; ++k) - { - desc += "This is a multi line description. "; - } - CBotChat::setDescription(botChatGroup, desc); -} -*/ - -//========================================= -/** Temp setup for bot chat gift - */ -/* -static void setupBotChatBotGift(CInterfaceGroup *botChatGroup) -{ - // create dummy item in the db - CInterfaceManager *im = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("SERVER:INVENTORY:20:0:SHEET")->setValue32(CSheetId("ai_flesh_poisson.item").asInt()); - NLGUI::CDBManager::getInstance()->getDbProp("SERVER:INVENTORY:20:0:QUALITY")->setValue32(0); - NLGUI::CDBManager::getInstance()->getDbProp("SERVER:INVENTORY:20:1:SHEET")->setValue32(CSheetId("fyros_sword_lvl_01_05.item").asInt()); - NLGUI::CDBManager::getInstance()->getDbProp("SERVER:INVENTORY:20:1:QUALITY")->setValue32(2); - CBotChat::setBotGift(botChatGroup, ucstring("Thanks to have succeeded the mission"), ucstring("Here's your reward"), ucstring("The bot has taken the object quest from your inventory")); -} -*/ - -//----------------------------------------------- -// impulseBotChatSetInterface : -//----------------------------------------------- -#if 0 -void impulseBotChatSetInterface(NLMISC::CBitMemStream &impulse) -{ - // received ADD_DYN_STR - - CEntityId user; - uint32 happyness; - BOTCHATTYPE::TBotChatInterfaceId interfaceId; - bool hasNews; - - impulse.serial (user); - impulse.serial (happyness); - -// impulse.serialEnum (interfaceId); - uint16 interfId; - impulse.serial(interfId); - interfaceId = (BOTCHATTYPE::TBotChatInterfaceId)(interfId&0xff); - uint8 botType = (interfId>>8) & 0xff; - - impulse.serial (hasNews); - - nldebug("impulseCallBack : Received BOT_CHAT:SET_INTERFACE interface %d, have news %s, happy %d, bottype %hu", interfaceId, hasNews?"yes":"no", happyness,(uint16)botType); - - string stringId; - vector args; - if (hasNews) - { - -/* impulse.serial (stringId); - impulse.serialCont (args); - nlinfo ("receive the news '%s' with %d args", stringId.c_str(), args.size()); -*/ - // TEMP FOR THE DEMO, DON'T USE THE NETWORK NEW BUT SELECT A NEWS HERE -/* - CInterfaceGroup *inter = CWidgetManager::getInstance()->getWindowFromId("ui:interface:bot_chat_intro"); - nlassert (inter != NULL); - inter->setActive(true); - - CViewText *inter2 = (CViewText *)inter->getView("hi"); - nlassert (inter2 != NULL); - inter2->NetworkTextId.setString("IOS_NEWS_FOOTBALL_SHORT_EEII", &ChatMngr); - inter2->NetworkTextId.Args.push_back(10); - inter2->NetworkTextId.Args.push_back(20); - inter2->NetworkTextId.Args.push_back(1); - inter2->NetworkTextId.Args.push_back(2); -*/ } - - // FOR THE DEMO, find and set a fake news: -// setFakeNews (); - - string interfaceName = getInterfaceNameFromId (botType, interfaceId); - - if(interfaceName.empty()) - { - nlwarning ("Received an unknown bot chat interface %d", interfaceId); - } - else - { - CInterfaceGroup *inter = CWidgetManager::getInstance()->getWindowFromId(interfaceName); - if (inter == NULL) - { - nlwarning ("Can't find interface name '%s' %d", interfaceName.c_str(), interfaceId); - } - else - { - CInterfaceManager::getInstance()->setBotChatWin(inter); - if (inter->getActive()) - { - nlwarning ("Interface %s is already active, not normal!", interfaceName.c_str()); - } - else - { - nlinfo ("server want to me display the bot chat interface %s %d", interfaceName.c_str(), interfaceId); - inter->setActive(true); - } - } - } -} -#endif - - - -//----------------------------------------------- -// impulseBeginTrade : -//----------------------------------------------- -void impulseBeginTrade(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - //open trade window - CInterfaceGroup* win = CWidgetManager::getInstance()->getWindowFromId("ui:interface:trade"); - if (!win) - { - nlwarning("invalid interface ui:interface:trade"); - return; - } - win->setActive(true); -} - -//----------------------------------------------- -// impulseBuyPrice : -//----------------------------------------------- -void impulseBuyPrice(NLMISC::CBitMemStream &impulse) -{ - uint16 botChatSession; - uint32 sheetID; - uint16 quality; - uint64 price; - impulse.serial(botChatSession); - impulse.serial(price); - impulse.serial(sheetID); - impulse.serial(quality); - // no more used -} - -//----------------------------------------------- -// impulseDynChatOpen -//----------------------------------------------- -void impulseDynChatOpen(NLMISC::CBitMemStream &impulse) -{ - uint32 BotUID; // Compressed Index - uint32 BotName; // Server string - vector DynStrs; // 0 - Desc, 1 - Option0, 2 - Option1, etc.... - impulse.serial(BotUID); - impulse.serial(BotName); - impulse.serialCont(DynStrs); - - if (PermanentlyBanned) return; - -/* string sTmp = "impulseCallback : Received BOTCHAT:DYNCHAT_OPEN BotUID:"; - sTmp += toString(BotUID) + " BotName:"; - sTmp += toString(BotName) + " DynStrs:"; - for (uint32 i = 0; i < DynStrs.size(); ++i) - { - sTmp += toString(DynStrs[i]); - if (i != DynStrs.size()-1) sTmp += ","; - } - nlinfo(sTmp.c_str());*/ - - InSceneBubbleManager.dynChatOpen(BotUID, BotName, DynStrs); -} - -//----------------------------------------------- -// impulseDynChatClose -//----------------------------------------------- -void impulseDynChatClose(NLMISC::CBitMemStream &impulse) -{ - uint32 BotUID; // Compressed Index - impulse.serial(BotUID); - if (PermanentlyBanned) return; - //nlinfo("impulseCallback : Received BOTCHAT:DYNCHAT_CLOSE BotUID:"+toString(BotUID)); - InSceneBubbleManager.dynChatClose(BotUID); -} - -//----------------------------------------------- -// impulseBeginCast: -//----------------------------------------------- -void impulseBeginCast(NLMISC::CBitMemStream &impulse) -{ - //open cast window - uint32 begin,end; - impulse.serial(begin); - impulse.serial(end); - if (PermanentlyBanned) return; - CInterfaceManager* iMngr = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SPELL_CAST")->setValue32(1); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:CAST_BEGIN")->setValue32(begin); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:CAST_END")->setValue32(end); -} - - - -//----------------------------------------------- -// impulseCorrectPos : -// Message from the server to correct the user position because he is not at the same position on the server.. -//----------------------------------------------- -void impulseCorrectPos(NLMISC::CBitMemStream &impulse) -{ - // TP:CORRECT - //nlinfo("impulseCallback : Received TP:CORRECT"); - sint32 x, y, z; - impulse.serial(x); - impulse.serial(y); - impulse.serial(z); - nlinfo("impulseCorrectPos: new user position %d %d %d", x, y, z); - - if(UserEntity->mode() != MBEHAV::COMBAT_FLOAT) - { - if (x == 0) // Get SpeedAdjustement - { - UserEntity->setSpeedServerAdjust(-0.2f); - } - else - { - // Compute the destination. - CVectorD dest = CVectorD((float)x/1000.0f, (float)y/1000.0f, (float)z/1000.0f); - // Update the position for the vision. - NetMngr.setReferencePosition(dest); - // Change the user poisition. - UserEntity->correctPos(dest); - } - } -}// impulseCorrectPos // - -class CDummyProgress : public IProgressCallback -{ - void progress (float /* value */) {} -}; - -//----------------------------------------------- -// impulseTP : -// Message from the server to teleport the user. -// \warning This function remove the current target. Do no use to correct a position. -//----------------------------------------------- -void impulseTPCommon(NLMISC::CBitMemStream &impulse, bool hasSeason); -void impulseTPCommon2(NLMISC::CBitMemStream &impulse, bool hasSeason); - -void impulseTP(NLMISC::CBitMemStream &impulse) -{ - impulseTPCommon(impulse, false); -} - -void impulseTPWithSeason(NLMISC::CBitMemStream &impulse) -{ - impulseTPCommon(impulse, true); -} - -struct SQueuedTP -{ - NLMISC::CBitMemStream Impulse; - bool HasSeason; - - SQueuedTP(const NLMISC::CBitMemStream &impulse, bool hasSeason) - :Impulse(impulse), HasSeason(hasSeason) - { - } -}; - -// note - this method added by Sadge and Hamster to deal with unexplained recursive calls to impulseTPCommon -// these calls are provoked by the net manager update which is called during loading -void impulseTPCommon(NLMISC::CBitMemStream &impulse, bool hasSeason) -{ - CNiceInputAuto niceInputs; - static std::list queuedTPs; - SQueuedTP thisTP(impulse,hasSeason); - queuedTPs.push_back(thisTP); - - BOMB_IF(queuedTPs.size()!=1,NLMISC::toString("Queueing recursive TPs depth=%u",queuedTPs.size()),return); - - while(!queuedTPs.empty()) - { - impulseTPCommon2(queuedTPs.front().Impulse,queuedTPs.front().HasSeason); - queuedTPs.pop_front(); - }; - -} - - -void impulseTPCommon2(NLMISC::CBitMemStream &impulse, bool hasSeason) -{ - // choose a default screen if not setuped - if( LoadingBackground!=ResurectKamiBackground && LoadingBackground!=ResurectKaravanBackground && - LoadingBackground!=TeleportKamiBackground && LoadingBackground!=TeleportKaravanBackground) - LoadingBackground= TeleportKaravanBackground; - // if resurect but user not dead, choose default. NB: this is a bug, the tp impulse should tell - // which background to choose. \todo yoyo: this is a temp fix - if( UserEntity && !UserEntity->isDead() && - (LoadingBackground==ResurectKamiBackground || LoadingBackground==ResurectKaravanBackground) ) - LoadingBackground= TeleportKaravanBackground; - - // Play music according to the background - if(SoundMngr) - { - LoadingMusic.clear(); - if(LoadingBackground==TeleportKamiBackground) - LoadingMusic= "Kami Teleport.ogg"; - else if(LoadingBackground==TeleportKaravanBackground) - LoadingMusic= "Karavan Teleport.ogg"; - // if resurection, continue to play death music - else if(LoadingBackground==ResurectKamiBackground || LoadingBackground==ResurectKaravanBackground) - { - // noop - } - // default: loading music - else - { - LoadingMusic= "Loading Music Loop.ogg"; - } - - // start to play - SoundMngr->playEventMusic(LoadingMusic, CSoundManager::LoadingMusicXFade, true); - } - - // Create the loading texture. - beginLoading (LoadingBackground); - - // No ESCAPE key - UseEscapeDuringLoading = false; - - // Change the tips - selectTipsOfTheDay (rand()); - - // start progress bar and display background - ProgressBar.reset (BAR_STEP_TP); - ucstring nmsg("Loading..."); - ProgressBar.newMessage ( ClientCfg.buildLoadingString(nmsg) ); - - - // received ADD_DYN_STR - nlinfo("impulseTP: received a request for a TP."); - sint32 x, y, z; - impulse.serial(x); - impulse.serial(y); - impulse.serial(z); - bool useHeading; - impulse.serialBit( useHeading ); - // Is there an orientation too ? - if( useHeading ) - { - float angle; - impulse.serial(angle); - nlinfo("impulseTP: to %d %d %d %f", x, y, z, angle); - CVector ori = CVector((float)cos(angle), (float)sin(angle), 0.0f); - ori.normalize(); - UserEntity->dir(ori, false, false); - UserEntity->front(ori, false, false); - UserEntity->setHeadPitch(0); - UserControls.resetCameraDeltaYaw(); - } - else - nlinfo("impulseTP: to %d %d %d", x, y, z); - - if (hasSeason) - { - extern uint8 ServerSeasonValue; - extern bool ServerSeasonReceived; - impulse.serial(ServerSeasonValue); - ServerSeasonReceived = true; - } - - if (ClientCfg.R2EDEnabled) - { - R2::getEditor().tpReceived(); - } - - // Compute the destination. - CVectorD dest = CVectorD((float)x/1000.0f, (float)y/1000.0f, (float)z/1000.0f); - // Update the position for the vision. - NetMngr.setReferencePosition(dest); - // Change the position of the entity and in Pacs. - UserEntity->pos(dest); - - // Fade out the Game Sound - if(SoundMngr) - SoundMngr->fadeOutGameSound(ClientCfg.SoundTPFade); - - - R2::TTeleportContext tpContext = R2::TPContext_Unknown; - - ucstring tpReason; - ucstring tpCancelText; - - try - { - R2::TR2TpInfos tpInfos; - impulse.serial(tpInfos); - - - if ( tpInfos.UseTpMessage) - { - tpReason = CI18N::get(tpInfos.TpReasonId); - - uint32 size = (uint32)tpInfos.TpReasonParams.size(); - uint32 first = 0; - CSString str(tpReason.toString()); - for (;first != size ; ++first) - { - std::string value = tpInfos.TpReasonParams[first]; - std::string key = NLMISC::toString("%%%u", first +1); - str = str.replace( key.c_str(), value.c_str()); - } - tpReason = ucstring(str); - tpCancelText = CI18N::get(tpInfos.TpCancelTextId); - tpContext = tpInfos.TpContext; - } - - } - catch (const EStream &) - { - tpReason = ucstring("TP Reason"); - tpCancelText = ucstring("Cancel TP"); // for test - // try to deduce tp context from current editor mode - switch (R2::getEditor().getMode()) - { - case R2::CEditor::EditionMode: - case R2::CEditor::NotInitialized: - tpContext = R2::TPContext_Unknown; - tpReason = ucstring(); - tpCancelText = ucstring(); - break; - case R2::CEditor::GoingToDMMode: - case R2::CEditor::TestMode: - case R2::CEditor::DMMode: - tpContext = R2::TPContext_Edit; - break; - case R2::CEditor::AnimationModeLoading: - case R2::CEditor::AnimationModeWaitingForLoading: - case R2::CEditor::AnimationModeDm: - case R2::CEditor::AnimationModeGoingToDm: - tpContext = R2::TPContext_IslandOwner; - break; - case R2::CEditor::AnimationModePlay: - case R2::CEditor::AnimationModeGoingToPlay: - default: - tpContext = R2::TPContext_Mainland; - break; - } - } - - - - if (!tpReason.empty()) - { - std::string tpIcon; - switch(tpContext) - { - case R2::TPContext_Mainland: tpIcon = "cancel_tp_main_land.tga"; break; - case R2::TPContext_Edit: tpIcon = "cancel_tp_edit.tga"; break; - case R2::TPContext_IslandOwner: tpIcon = "cancel_tp_island_owner.tga"; break; - default: break; - } - ProgressBar.setTPMessages(tpReason, tpCancelText, tpIcon); - } - - ProgressBar.progress(0); - // enable hardware mouse to allow to click the buttons - //bool oldHardwareCursor = IsMouseCursorHardware(); - //InitMouseWithCursor(true); - // Select the closest continent from the new position. - ContinentMngr.select(dest, ProgressBar); - // - //InitMouseWithCursor(oldHardwareCursor); - - // reset 'cancel' button - ProgressBar.setTPMessages(ucstring(), ucstring(), ""); - - - // ProgressBar.enableQuitButton(false); // TMP TMP - ProgressBar.progress(1.f); // do a last display without the buttons because first frame may take a while to draw, and the buttons have no more effect at this point. - ProgressBar.finish(); - // ProgressBar.enableQuitButton(true); // TMP TMP - - // Teleport the User. - UserEntity->tp(dest); - - // Msg Received, send an acknowledge after the landscape has been loaded. - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream("TP:ACK", out)) - { - NetMngr.push(out); - nlinfo("impulseTP: teleport acknowledge 'TP:ACK' sent."); - } - else - nlwarning("impulseTP: unknown message name : 'TP:ACK'."); - - - // First frame - FirstFrame = true; - - - // if tp canceling was asked, act accordingly - if (ProgressBar.getTPCancelFlag(true)) - { - switch(tpContext) - { - case R2::TPContext_Mainland: - CAHManager::getInstance()->runActionHandler("return_to_mainland", NULL); - break; - case R2::TPContext_Edit: - CAHManager::getInstance()->runActionHandler("r2ed_stop_test", NULL); - break; - case R2::TPContext_IslandOwner: - CAHManager::getInstance()->runActionHandler("r2_stop_live", NULL); - break; - default: - break; - } - } - - initHardwareCursor(true); -}// impulseTP // - -//----------------------------------------------- -// impulseCombatEngageFailed : -//----------------------------------------------- -void impulseCombatEngageFailed(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - nlinfo("impulseCombatEngageFailed: Combat Engage Failed."); - - // Unlock the motion. - UserControls.locked(false); -}// impulseCombatEngageFailed // - -//----------------------------------------------- -// impulseTeamInvitation : -//----------------------------------------------- -void impulseTeamInvitation(NLMISC::CBitMemStream &impulse) -{ - nlinfo("impulseTeamInvitation: received an invitation"); - - uint32 textID; - impulse.serial(textID); - if (PermanentlyBanned) return; - - CLuaManager::getInstance().executeLuaScript("game:onTeamInvation("+toString(textID)+")", 0); -}// impulseTeamInvitation // - -//----------------------------------------------- -// impulseTeamShareOpen -// The server request that the client opens the team sharing system -//----------------------------------------------- -void impulseTeamShareOpen(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - CInterfaceManager *im = CInterfaceManager::getInstance(); - CGroupContainer *gc = dynamic_cast( CWidgetManager::getInstance()->getElementFromId("ui:interface:team_share")); - if (!gc) return; - gc->setActive(true); - CWidgetManager::getInstance()->setTopWindow(gc); - gc->updateCoords(); - gc->center(); -}// impulseTeamShareOpen // - -//----------------------------------------------- -// impulseTeamShareInvalid -// invalidate the player validation. If someone has choosen an item/phrase after the player has validated -// the player receive this message to let him know that the chance percentage to obtain a specific item has -// changed and so the player can update its own settings to fit better to what he wants. -// On the client side we have just to show the valid button. All the resets are done on the server side. -//----------------------------------------------- -void impulseTeamShareInvalid(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CCtrlTextButton *pTB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:team_share:content:ok")); - if (pTB != NULL) - pTB->setActive(true); -}// impulseTeamShareInvalid // - -//----------------------------------------------- -// impulseTeamShareClose -// The server wants to close the team sharing interface (if the sharing has been validated or other reasons) -//----------------------------------------------- -void impulseTeamShareClose(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer - *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:team_share")); - if (pGC != NULL) - pGC->setActive(false); - CCtrlTextButton *pTB = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:team_share:content:ok")); - if (pTB != NULL) - pTB->setActive(true); -}// impulseTeamShareClose // - -//----------------------------------------------- -// impulseTeamContactInit -// initialize friend list and ignore list from the contact list -//----------------------------------------------- -void impulseTeamContactInit(NLMISC::CBitMemStream &impulse) -{ - vector vFriendListName; - vector vFriendListOnline; - vector vIgnoreListName; - - impulse.serialCont(vFriendListName); - uint32 nbState; - impulse.serial(nbState); - vFriendListOnline.resize(nbState); - for (uint i=0; igetDbProp("UI:SAVE:CONTACT_LIST:SORT_ORDER")->getValue32()); - - if (order == CPeopleList::sort_online) - { - PeopleInterraction.FriendList.sortEx(order); - } -}// impulseTeamContactStatus // - - -//----------------------------------------------- -// impulseTeamContactRemove -// Remove a contact by the server -//----------------------------------------------- -void impulseTeamContactRemove(NLMISC::CBitMemStream &impulse) -{ - uint32 contactId; - uint8 nList; - - impulse.serial(contactId); - impulse.serial(nList); - - if (PermanentlyBanned) return; - - //nlinfo("impulseCallback : Received TEAM:CONTACT_REMOVE %d %d", contactId, nList); - - PeopleInterraction.removeContactFromList(contactId, nList); - -}// impulseTeamContactRemove // - - -//----------------------------------------------- -// servers sets information of a guild member: -// u16 ( member index ) u32 (player name ), u8 ( player grade + last bit set if player online ). -//----------------------------------------------- -/*void impulseGuildSetMemberInfo(NLMISC::CBitMemStream &impulse) -{ - uint16 index; - impulse.serial(index); - uint32 guildMemberName; - impulse.serial(guildMemberName); - uint8 grade; - impulse.serial(grade); - bool online = ((grade&0x80) != 0); - grade = (grade & 0x7F); - CGuildManager::getInstance()->set(index, guildMemberName, grade, online); -}*/ - -//----------------------------------------------- -// vector of pair( u32 (player name ), u8 ( player grade + last bit set if player online ) ) -//----------------------------------------------- -/*void impulseGuildInitMemberInfo(NLMISC::CBitMemStream &impulse) -{ - vector < pair < uint32, uint8 > > AllMembers; - uint16 nbEntries; - impulse.serial(nbEntries); - AllMembers.resize(nbEntries); - for (uint32 i = 0; i < nbEntries; ++i) - { - uint32 name; - impulse.serial(name); - uint8 gradeNonline; - impulse.serial(gradeNonline); - AllMembers[i].first = name; - AllMembers[i].second = gradeNonline; - } - - CGuildManager::getInstance()->init(AllMembers); -}*/ - - -//----------------------------------------------- -// impulseGuildInvitation -//----------------------------------------------- -/*void impulseGuildInvitation(NLMISC::CBitMemStream &impulse) -{ - nlinfo("impulseGuildInvitation"); - -}*/ - -//----------------------------------------------- -// impulseGuildJoinProposal -// server sent to client invitation (uint32 invitorNameId, uint32 guildNameId -//----------------------------------------------- -void impulseGuildJoinProposal(NLMISC::CBitMemStream &impulse) -{ - - uint32 phraseID; - impulse.serial(phraseID); - - if (PermanentlyBanned) return; - - //nlinfo("impulseCallback : Received GUILD:JOIN_PROPOSAL %d", phraseID); - - CGuildManager::getInstance()->launchJoinProposal(phraseID); - /*//activate the pop up window - CInterfaceManager *im = CInterfaceManager::getInstance(); - CGroupContainer *gc = dynamic_cast( CWidgetManager::getInstance()->getElementFromId("ui:interface:join_guild_proposal")); - if (!gc) return; - CViewText *vt = dynamic_cast(gc->getView("invitor_name")); - if (vt == NULL) return; - vt->setText(invitor); - gc->setActive(true); - CWidgetManager::getInstance()->setTopWindow(gc); - gc->updateCoords(); - gc->center(); - gc->enableBlink(2);*/ -}// impulseGuildJoinProposal // - - -//----------------------------------------------- -// impulseCloseTempInv -//----------------------------------------------- -void impulseCloseTempInv(NLMISC::CBitMemStream &impulse) -{ - CTempInvManager::getInstance()->close(); -} - -//----------------------------------------------- -// impulseAscencorTeleport -//----------------------------------------------- -void impulseAscencorTeleport(NLMISC::CBitMemStream &impulse) -{ - -} // impulseAscencorTeleport // - -//----------------------------------------------- -// impulseEnterCrZoneProposal -// server sent to client invitation (uint32 invitorNameId, uint32 guildNameId -//----------------------------------------------- -void impulseEnterCrZoneProposal(NLMISC::CBitMemStream &impulse) -{ - uint32 phraseID; - impulse.serial(phraseID); - if (PermanentlyBanned) return; - - //nlinfo("impulseCallback : Received MISSION:ASK_ENTER_CRITICAL %d", phraseID); - - //activate the pop up window - CInterfaceManager *im = CInterfaceManager::getInstance(); - CGroupContainer *gc = dynamic_cast( CWidgetManager::getInstance()->getElementFromId("ui:interface:enter_crzone_proposal")); - if (!gc) return; - CViewTextID *vti = dynamic_cast(gc->getView("phrase")); - if (!vti) return; - vti->setTextId(phraseID); - gc->setActive(true); - CWidgetManager::getInstance()->setTopWindow(gc); - gc->updateCoords(); - gc->center(); - gc->enableBlink(2); -}// impulseEnterCrZoneProposal // - -//----------------------------------------------- -// impulseCloseEnterCrZoneProposal -// server close proposal interface -//----------------------------------------------- -void impulseCloseEnterCrZoneProposal(NLMISC::CBitMemStream &impulse) -{ - // hide interface - CInterfaceManager* pIM = CInterfaceManager::getInstance(); - CInterfaceGroup *pIG = (CInterfaceGroup*)CWidgetManager::getInstance()->getElementFromId ("ui:interface:enter_crzone_proposal"); - if(pIG) - pIG->setActive(false); -}// impulseCloseEnterCrZoneProposal // - - -//----------------------------------------------- -// impulseExchangeInvitation : -//----------------------------------------------- -void impulseExchangeInvitation(NLMISC::CBitMemStream &impulse) -{ - uint32 textID; - impulse.serial(textID); - if (PermanentlyBanned) return; - CInterfaceManager* iMngr = CInterfaceManager::getInstance(); - - // show the modal window that allow the player to accept / decline the invitation - CGroupContainer *wnd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(PLAYER_EXCHANGE_INVITATION_DIALOG)); - if (wnd) - { - wnd->setActive(true); - wnd->updateCoords(); - wnd->center(); - wnd->enableBlink(2); - CWidgetManager::getInstance()->setTopWindow(wnd); - } - - CViewTextID *vti = dynamic_cast(wnd->getView("invite_phrase")); - if (vti) - { - vti->setTextId(textID); - } - -}// impulseExchangeInvitation // - -//----------------------------------------------- -// impulseExchangeCloseInvitation : -//----------------------------------------------- -void impulseExchangeCloseInvitation(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - CInterfaceManager* iMngr = CInterfaceManager::getInstance(); - // hide the modal window that allow the player to accept / decline the invitation - CInterfaceGroup *wnd = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(PLAYER_EXCHANGE_INVITATION_DIALOG)); - if (wnd) wnd->setActive(false); -} - -//----------------------------------------------- -// impulseMountAbort : -//----------------------------------------------- -void impulseMountAbort(NLMISC::CBitMemStream &impulse) -{ - nlwarning("impulseMountAbort: Received ANIMALS:MOUNT_ABORT => no more used"); -}// impulseMountAbort // - -//----------------------------------------------- -// impulseRyzomTime : -// Synchronize the ryzom time with the server. -//----------------------------------------------- -/* -void impulseRyzomTime(NLMISC::CBitMemStream &impulse) -{ - nlinfo("impulseRyzomTime: Ryzom Time Received"); - uint32 serverTick; - float ryzomTime; - uint32 ryzomDay; - impulse.serial(serverTick); - impulse.serial(ryzomTime); - impulse.serial(ryzomDay); - nlinfo("impulseRyzomTime: Day '%d' Time '%f'.", ryzomDay, ryzomTime); - - // Initialize - RT.setOrigin( serverTick, ryzomDay, ryzomTime ); -}// impulseRyzomTime // -*/ -//----------------------------------------------- -// impulseWhere : -// Display server position -//----------------------------------------------- -void impulseWhere(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallback : Received DEBUG:REPLY_WHERE"); - - sint32 x,y,z; - impulse.serial(x); - impulse.serial(y); - impulse.serial(z); - if (PermanentlyBanned) return; - char buf[128]; - - double xf = ((double)x)/1000.0f; - double yf = ((double)y)/1000.0f; - double zf = ((double)z)/1000.0f; - - sprintf(buf,"Your server position is : X= %g Y= %g Z= %g",xf,yf,zf); - nlinfo(buf); - CInterfaceManager::getInstance()->displaySystemInfo(ucstring(buf)); -}// impulseWhere // - -//----------------------------------------------- -// impulseWho : -// Display server position -//----------------------------------------------- -/* -void impulseWho(NLMISC::CBitMemStream &impulse) -{ - nlinfo("impulseWho Received"); - CInterfaceManager::getInstance()->displaySystemInfo(ucstring("Players currently in the game :")); - - ucstring name; - uint32 loginId; - uint16 dist; - uint8 dirshort; - string str; - while( impulse.getPos() < (sint32)impulse.length() ) - { - impulse.serial(name); - impulse.serial(loginId); - impulse.serial(dist); - impulse.serial(dirshort); - - double angle = dirshort * 2.0 * NLMISC::Pi / 255.0; - angle -= NLMISC::Pi; - nlinfo ("name %s uid %u dist %hu dirshort %hu angle %f", name.toString().c_str(),loginId, dist, (uint16)dirshort, angle); - sint direction =(sint) floor( 0.5 + ( 8.0 * (angle + NLMISC::Pi)/(NLMISC::Pi) ) ); - direction = ((direction%16)+16)%16; - static const string txts[]= - { - "uiW", - "uiWSW", - "uiSW", - "uiSSW", - "uiS", - "uiSSE", - "uiSE", - "uiESE", - "uiE", - "uiENE", - "uiNE", - "uiNNE", - "uiN", - "uiNNW", - "uiNW", - "uiWNW", - }; - - str = toString (" - uid %d - distance %hu meters - direction ", loginId, dist); - CInterfaceManager::getInstance()->displaySystemInfo(ucstring(name + ucstring(str) + CI18N::get(txts[direction]))); - } -}// impulseWho // -*/ - -/* -void impulseWhoGM(NLMISC::CBitMemStream &impulse) -{ - nlinfo("impulseWhoGM Received"); - CInterfaceManager::getInstance()->displaySystemInfo(ucstring("Players currently in the game :")); - - ucstring name; - uint32 loginId; - uint16 dist; - uint8 dirshort; - string str; - while( impulse.getPos() < (sint32)impulse.length() ) - { - impulse.serial(name); - impulse.serial(loginId); - impulse.serial(dist); - impulse.serial(dirshort); - - double angle = dirshort * 2.0 * NLMISC::Pi / 255.0; - angle -= NLMISC::Pi; - nlinfo ("name %s uid %u dist %hu dirshort %hu angle %f", name.toString().c_str(),loginId, dist, (uint16)dirshort, angle); - sint direction =(sint) floor( 0.5 + ( 8.0 * (angle + NLMISC::Pi)/(NLMISC::Pi) ) ); - direction = ((direction%16)+16)%16; - static const string txts[]= - { - "uiW", - "uiWSW", - "uiSW", - "uiSSW", - "uiS", - "uiSSE", - "uiSE", - "uiESE", - "uiE", - "uiENE", - "uiNE", - "uiNNE", - "uiN", - "uiNNW", - "uiNW", - "uiWNW", - }; - - str = toString (" - uid %d - distance %hu meters - direction ", loginId, dist); - CInterfaceManager::getInstance()->displaySystemInfo(ucstring(name + ucstring(str) + CI18N::get(txts[direction]))); - } -}// impulseWho // -*/ -//----------------------------------------------- -// impulseCounter : -// check UDP validity -//----------------------------------------------- -void impulseCounter(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallBack : Received DEBUG:COUNTER"); - try - { - uint32 counter; - impulse.serial(counter); - - static uint queueTop = 0; - static deque queue; - - if (counter > queueTop) - { - queue.resize(queue.size()+counter-queueTop, false); - queueTop = counter; - } - - if (queueTop-counter+1 > queue.size()) - { - nlinfo("COUNTER: counter %d arrived too late...", counter); - } - else - { - if (queue[queue.size()-1-(queueTop-counter)]) - { - nlwarning("COUNTER: Received counter %d more than once !", counter); - } - else - { - nldebug("COUNTER: set counter %d", counter); - queue[queue.size()-1-(queueTop-counter)] = true; - } - - while (queue.size() > 128) - { - if (!queue.front()) - { - nlwarning("COUNTER: counter %d not received !", queueTop-queue.size()-1); - } - - queue.pop_front(); - } - } - } - catch (const Exception &e) - { - nlwarning ("Problem while decoding a COUTNER msg, skipped: %s", e.what()); - } -} - -//----------------------------------------------- -// impulsePhraseSend : -// A dyn string (or phrase) is send (so, we receive it) -//----------------------------------------------- -void impulsePhraseSend(NLMISC::CBitMemStream &impulse) -{ - STRING_MANAGER::CStringManagerClient::instance()->receiveDynString(impulse); -} - -//----------------------------------------------- -// impulseStringResp : -// Update the local string set -//----------------------------------------------- -void impulseStringResp(NLMISC::CBitMemStream &impulse) -{ - uint32 stringId; - string strUtf8; - impulse.serial(stringId); - impulse.serial(strUtf8); - ucstring str; - str.fromUtf8(strUtf8); - - if (PermanentlyBanned) return; - - STRING_MANAGER::CStringManagerClient::instance()->receiveString(stringId, str); -} - -//----------------------------------------------- -// impulseReloadCache : -// reload the string cache -//----------------------------------------------- -void impulseReloadCache(NLMISC::CBitMemStream &impulse) -{ - uint32 timestamp;; - impulse.serial(timestamp); - if (PermanentlyBanned) return; - STRING_MANAGER::CStringManagerClient::instance()->loadCache(timestamp); -} - -//----------------------------------------------- -// impulseBotChatEnd -// ForceThe end of the bot chat -//----------------------------------------------- -void impulseBotChatForceEnd(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - CBotChatManager::getInstance()->setCurrPage(NULL); -} - - -//----------------------------------------------- -// MISSION COMPLETED JOURNAL -//----------------------------------------------- -/* -#define MC_M_CONTAINER "ui:interface:info_player_journal" -#define MC_S_CONTAINER "ui:interface:ipj_com_missions" -#define MC_TEMPLATE "tipj_mission_complete" -//----------------------------------------------- -CGroupContainer *getMissionCompletedContainer() -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceElement *pIE = CWidgetManager::getInstance()->getElementFromId(MC_M_CONTAINER); - CGroupContainer *pGCM = dynamic_cast(pIE); - if (pGCM == NULL) return NULL; - - CGroupList *pList = pGCM->getList(); - CGroupContainer *pGCS = dynamic_cast(pList->getGroup(MC_S_CONTAINER)); - return pGCS; -} - -//----------------------------------------------- -void clearMissions() -{ - CGroupContainer *pGCMC = getMissionCompletedContainer(); - CInterfaceGroup *pContent = pGCMC->getGroup("content"); - pContent->clearGroups(); -} -//----------------------------------------------- -void addMission(uint32 titleID) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer *pGCMC = getMissionCompletedContainer(); - if (pGCMC == NULL) - { - nlwarning("cannot get container for missions completed"); - return; - } - CInterfaceGroup *pContent = pGCMC->getGroup("content"); - - uint32 nNbMission = pContent->getGroups().size(); - vector > vArgs; - - vArgs.push_back(pair("id", "mc"+NLMISC::toString(nNbMission))); - vArgs.push_back(pair("mcid", NLMISC::toString(titleID))); - - if (nNbMission == 0) - { - vArgs.push_back(pair("posref", "TL TL")); - vArgs.push_back(pair("posparent", "parent")); - vArgs.push_back(pair("y", "0")); - } - else - { - vArgs.push_back(pair("posref", "BL TL")); - } - - CInterfaceGroup *pIG = pIM->createGroupInstance(MC_TEMPLATE, pContent->getId(), vArgs); - if (pIG == NULL) - { - nlwarning("cannot create a mission completed"); - return; - } - pIG->setParent(pContent); - if (nNbMission == 0) - pIG->setParentPos(pContent); - else - pIG->setParentPos(pContent->getGroups()[nNbMission-1]); - pContent->addGroup(pIG); -} -*/ -//----------------------------------------------- -// impulseJournalInitCompletedMissions : -// initialize the player journal missions for completed missions -//----------------------------------------------- -void impulseJournalInitCompletedMissions (NLMISC::CBitMemStream &impulse) -{ -/* - vector vMissionCompleted; - impulse.serialCont(vMissionCompleted); - - clearMissions(); - - for (uint32 i = 0; i < vMissionCompleted.size(); ++i) - addMission (vMissionCompleted[i]); -*/ -} - -//----------------------------------------------- -// impulseJournalInitCompletedMissions : -// initialize the player journal missions for completed missions -//----------------------------------------------- -void impulseJournalUpdateCompletedMissions (NLMISC::CBitMemStream &impulse) -{ -/* - uint32 nNewCompletedMission; - impulse.serial(nNewCompletedMission); - - addMission (nNewCompletedMission); -*/ -} - - -//----------------------------------------------- -// impulseJournalCantAbandon : -// server refuses mission abandon -//----------------------------------------------- -void impulseJournalCantAbandon (NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - /// reactivate abandon button - CCDBNodeLeaf *pNL = NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:MISSION_ABANDON_BUTTON",false); - if (pNL != NULL) - pNL->setValue64(1); -} - - - -//----------------------------------------------- -// server add a compass target -//----------------------------------------------- -void impulseJournalAddCompass(NLMISC::CBitMemStream &impulse) -{ - sint32 x; - sint32 y; - uint32 text; - impulse.serial(x); - impulse.serial(y); - impulse.serial(text); - if (PermanentlyBanned) return; - //nlinfo("impulseCallback : Received JOURNAL:ADD_COMPASS %d %d %d", x, y, text); - CCompassDialogsManager::getInstance().addEntry( x,y,text ); -} - -//----------------------------------------------- -// server removes a compass target -//----------------------------------------------- -void impulseJournalRemoveCompass(NLMISC::CBitMemStream &impulse) -{ - uint32 text; - impulse.serial(text); - if (PermanentlyBanned) return; - //nlinfo("impulseCallback : Received JOURNAL:REMOVE_COMPASS %d", text); - CCompassDialogsManager::getInstance().removeEntry( text ); -} - - - -// -// the server ask me to execute a command -// -void impulseRemoteAdmin (NLMISC::CBitMemStream &impulse) -{ - CLog logDisplayVars; - CLightMemDisplayer mdDisplayVars; - logDisplayVars.addDisplayer (&mdDisplayVars); - mdDisplayVars.setParam (10); - - uint32 rid; - impulse.serial (rid); - string cmd; - impulse.serial (cmd); - - // remove the 2 first rc character if exists, only there to say to the EGS that is a remote command - if (cmd.size()>2 && tolower(cmd[0])=='r' && tolower(cmd[1])=='c') - cmd = cmd.substr(2); - - mdDisplayVars.clear (); - ICommand::execute(cmd, logDisplayVars, !ICommand::isCommand(cmd)); - const std::deque &strs = mdDisplayVars.lockStrings(); - - string str; - if (ICommand::isCommand(cmd)) - { - for (uint k = 0; k < strs.size(); k++) - { - str += strs[k]; - } - } - else - { - if (!strs.empty()) - { - str = strs[0].substr(0,strs[0].size()-1); - // replace all spaces into underscore because space is a reserved char - for (uint i = 0; i < str.size(); i++) if (str[i] == ' ') str[i] = '_'; - } - else - { - str = "???"; - } - } - mdDisplayVars.unlockStrings(); - - //nlinfo("impulseCallback : Received COMMAND:REMOTE_ADMIN : Server asked me to execute '%s', result is '%s'", cmd.c_str(), str.c_str()); - - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream("COMMAND:REMOTE_ADMIN_ANSWER", out)) - { - out.serial (rid); - out.serial (cmd); - out.serial (str); - NetMngr.push (out); - //nlinfo("impulseCallback : COMMAND:REMOTE_ADMIN_ANSWER %d %s %s sent", rid, cmd.c_str(), str.c_str()); - } -} - - -//----------------------------------------------- -// impulseGuildAscensor : -// server request that the client launch the ascensor interface -//----------------------------------------------- - -void impulseGuildAscensor (NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - //nlinfo("impulseCallback : Received GUILD:ASCENSOR"); - CGuildManager::getInstance()->launchAscensor(); -} - -//----------------------------------------------- -//impulseGuildLeaveAscensor -//----------------------------------------------- -void impulseGuildLeaveAscensor (NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - //nlinfo("impulseCallback : Received GUILD:LEAVE_ASCENSOR"); - CGuildManager::getInstance()->quitAscensor(); -} - -//----------------------------------------------- -//impulseGuildAbortCreation -//----------------------------------------------- -void impulseGuildAbortCreation (NLMISC::CBitMemStream &impulse) -{ - CBotChatPage *pPage = CBotChatManager::getInstance()->getCurrPage(); - CBotChatPageCreateGuild *pPageCG = dynamic_cast(pPage); - if (pPageCG == BotChatPageAll->CreateGuild) - CBotChatManager::getInstance()->setCurrPage(NULL); -} - -void impulseGuildOpenGuildWindow(NLMISC::CBitMemStream &impulse) -{ - CGuildManager::getInstance()->openGuildWindow(); -} - - -//----------------------------------------------- -// impulseGuildOpenInventory -//----------------------------------------------- -void impulseGuildOpenInventory (NLMISC::CBitMemStream &impulse) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:INVENTORY_GUILD_OPENED")->setValue32(1); -} - -//----------------------------------------------- -// impulseGuildCloseInventory -//----------------------------------------------- -void impulseGuildCloseInventory (NLMISC::CBitMemStream &impulse) -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:INVENTORY_GUILD_OPENED")->setValue32(0); -} - -//----------------------------------------------- -// impulseGuildUpdatePlayerTitle -// server block/unblock some reserved titles -//----------------------------------------------- -void impulseGuildUpdatePlayerTitle(NLMISC::CBitMemStream &impulse) -{ - CSkillManager *pSM = CSkillManager::getInstance(); - bool bUnblock; - impulse.serial(bUnblock); - vector vTitles; - impulse.serialCont(vTitles); - if (PermanentlyBanned) return; - if (bUnblock) - { - for (uint32 i = 0; i < vTitles.size(); ++i) - pSM->unblockTitleFromServer((CHARACTER_TITLE::ECharacterTitle)vTitles[i]); - } - else - { - for (uint32 i = 0; i < vTitles.size(); ++i) - pSM->blockTitleFromServer((CHARACTER_TITLE::ECharacterTitle)vTitles[i]); - } -} - -//----------------------------------------------- -// impulseGuildUseFemaleTitles -// server activates/deactivates use of female titles -//----------------------------------------------- -void impulseGuildUseFemaleTitles(NLMISC::CBitMemStream &impulse) -{ - impulse.serial( UseFemaleTitles ); -} - -//----------------------------------------------- -// impulsePhraseDownLoad -// server upload the phrases. -//----------------------------------------------- -void impulsePhraseDownLoad (NLMISC::CBitMemStream &impulse) -{ - std::vector phrases; - - // Read Known Phrases - impulse.serialCont(phrases); - CSPhraseManager *pPM= CSPhraseManager::getInstance(); - for(uint i=0;ibuildPhraseFromSheet(phraseCom, phrases[i].PhraseSheetId.asInt()); - pPM->setPhraseNoUpdateDB(phrases[i].KnownSlot, phraseCom); - } - else - { - pPM->setPhraseNoUpdateDB(phrases[i].KnownSlot, phrases[i].Phrase); - } - } - // must update the DB (NB: if initInGameDone) after all phrase set. - pPM->updateBookDB(); - - // Then Read Memorized Phrases - std::vector memorizedPhrases; - impulse.serialCont(memorizedPhrases); - if (PermanentlyBanned) return; - for(uint i=0;imemorizePhrase( - memorizedPhrases[i].MemoryLineId, - memorizedPhrases[i].MemorySlotId, - memorizedPhrases[i].PhraseId); - } - - // OK. - extern bool SabrinaPhraseBookLoaded; - SabrinaPhraseBookLoaded= true; - - // update gray state, if game inited. - pPM->updateMemoryBar(); -} - -//----------------------------------------------- -// impulsePhraseConfirmBuy -// server confirm/infirm the buy of botchat phrase. -//----------------------------------------------- -void impulsePhraseConfirmBuy (NLMISC::CBitMemStream &impulse) -{ - uint16 phraseId; - bool confirm; - - impulse.serial(phraseId); - impulse.serial(confirm); - - if (PermanentlyBanned) return; - - CSPhraseManager *pSM= CSPhraseManager::getInstance(); - pSM->receiveBotChatConfirmBuy(phraseId, confirm); -} - - -//----------------------------------------------- -// impulsePhraseAckExecuteCyclic -// server confirm/infirm the cyclic execution of a phrase -//----------------------------------------------- -void impulsePhraseAckExecuteCyclic (NLMISC::CBitMemStream &impulse) -{ - uint8 counter; - bool ok; - - impulse.serial(ok); - impulse.serial(counter); - - if (PermanentlyBanned) return; - - - CSPhraseManager *pSM= CSPhraseManager::getInstance(); - pSM->receiveAckExecuteFromServer(true, counter, ok); -} - - -//----------------------------------------------- -// impulsePhraseAckExecuteCyclic -// server confirm/infirm the execution of a phrase -//----------------------------------------------- -void impulsePhraseAckExecuteNext (NLMISC::CBitMemStream &impulse) -{ - uint8 counter; - bool ok; - - impulse.serial(ok); - impulse.serial(counter); - - if (PermanentlyBanned) return; - - CSPhraseManager *pSM= CSPhraseManager::getInstance(); - pSM->receiveAckExecuteFromServer(false, counter, ok); -} - -// Same params as in BOMB_IF -#ifdef FINAL_VERSION -#define SKIP_IF(condition,msg,skipAction) if (!(condition)); else skipAction; -#else -#define SKIP_IF(condition,msg,skipAction) if (!(condition)) WARN(msg); else skipAction; -#endif - -template -void updateInventoryFromStream (NLMISC::CBitMemStream &impulse, const CInventoryCategoryTemplate *templ, bool notifyItemSheetChanges) -{ - try - { - // get the egs tick of this change - TGameCycle serverTick; - impulse.serial(serverTick); - - // For All inventories - for ( uint invId=0; invId!=CInventoryCategoryTemplate::NbInventoryIds; ++invId ) - { - // Presence bit - bool hasContent; - impulse.serialBit( hasContent ); - if ( ! hasContent ) - continue; - - // Number field - uint32 nbChanges; - impulse.serial( nbChanges, INVENTORIES::LowNumberBits ); - if ( nbChanges == INVENTORIES::LowNumberBound ) - impulse.serial( nbChanges, 32 ); - - const string invBranchStr = CInventoryCategoryTemplate::getDbStr( (typename CInventoryCategoryTemplate::TInventoryId)invId ); - ICDBNode::CTextId textId( invBranchStr ); - ICDBNode *inventoryNode = IngameDbMngr.getNodePtr()->getNode( textId, false ); - BOMB_IF(!inventoryNode, "Inventory missing in database", return); - - // List of updates - for ( uint c=0; c!=nbChanges; ++c ) - { - // Unpack (the bitmemstream is written from high-order to low-order) - uint32 iuInfoVersion; - impulse.serial( iuInfoVersion, 1 ); - if ( iuInfoVersion == 1 ) - { - uint32 slotIndex; - impulse.serial( slotIndex, CInventoryCategoryTemplate::SlotBitSize ); - - // Access the database leaf - CCDBNodeBranch *slotNode = safe_cast(inventoryNode->getNode( (uint16)slotIndex )); - CCDBNodeLeaf *leafNode = type_cast(slotNode->find( INVENTORIES::InfoVersionStr )); - BOMB_IF( !leafNode, "Inventory slot property missing in database", continue ); - - // Apply or increment Info Version in database - if ( CInventoryCategoryTemplate::needPlainInfoVersionTransfer() ) - { - uint32 infoVersion; - impulse.serial( infoVersion, INVENTORIES::InfoVersionBitSize ); - leafNode->setPropCheckGC( serverTick, infoVersion ); - } - else - { - // NB: don't need to check GC on a info version upgrade, since this is always a delta of +1 - // the order of received of this impulse is not important - leafNode->setValue64( leafNode->getValue64() + 1 ); - } - - } - else - { - uint32 iuAll; - impulse.serial( iuAll, 1 ); - if ( iuAll == 1 ) - { - INVENTORIES::CItemSlot itemSlot; - itemSlot.serialAll( impulse, templ ); - //nldebug( "Inv %s Update %u", CInventoryCategoryTemplate::InventoryStr[invId], itemSlot.getSlotIndex() ); - - // Apply all properties to database - CCDBNodeBranch *slotNode = safe_cast(inventoryNode->getNode( (uint16)itemSlot.getSlotIndex() )); - for ( uint i=0; i!=INVENTORIES::NbItemPropId; ++i ) - { - CCDBNodeLeaf *leafNode = type_cast(slotNode->find( string(INVENTORIES::CItemSlot::ItemPropStr[i]) )); - SKIP_IF( !leafNode, "Inventory slot property missing in database", continue ); - leafNode->setPropCheckGC( serverTick, (sint64)itemSlot.getItemProp( ( INVENTORIES::TItemPropId)i ) ); - } - } - else - { - uint32 iuOneProp; - impulse.serial( iuOneProp, 1 ); - if ( iuOneProp == 1 ) - { - INVENTORIES::CItemSlot itemSlot; - itemSlot.serialOneProp( impulse, templ ); - //nldebug( "Inv %s Prop %u %s", CInventoryCategoryTemplate::InventoryStr[invId], itemSlot.getSlotIndex(), INVENTORIES::CItemSlot::ItemPropStr[itemSlot.getOneProp().ItemPropId] ); - - // Apply property to database - CCDBNodeBranch *slotNode = safe_cast(inventoryNode->getNode( (uint16)itemSlot.getSlotIndex() )); - CCDBNodeLeaf *leafNode = type_cast(slotNode->find( string(INVENTORIES::CItemSlot::ItemPropStr[itemSlot.getOneProp().ItemPropId]) )); - SKIP_IF( !leafNode, "Inventory slot property missing in database", continue ); - leafNode->setPropCheckGC( serverTick, (sint64)itemSlot.getOneProp().ItemPropValue ); - - } - else // iuReset - { - uint32 slotIndex; - impulse.serial( slotIndex, CInventoryCategoryTemplate::SlotBitSize ); - //nldebug( "Inv %s Reset %u", CInventoryCategoryTemplate::InventoryStr[invId], slotIndex ); - - // Reset all properties in database - CCDBNodeBranch *slotNode = safe_cast(inventoryNode->getNode( (uint16)slotIndex )); - for ( uint i=0; i!=INVENTORIES::NbItemPropId; ++i ) - { - // Instead of clearing all leaves (by index), we must find and clear only the - // properties in TItemPropId, because the actual database leaves may have - // less properties, and because we must not clear the leaf INFO_VERSION. - // NOTE: For example, only player BAG inventory has WORNED leaf. - CCDBNodeLeaf *leafNode = type_cast(slotNode->find( string(INVENTORIES::CItemSlot::ItemPropStr[i]) )); - SKIP_IF( !leafNode, "Inventory slot property missing in database", continue ); - leafNode->setPropCheckGC( serverTick, 0 ); - } - } - } - } - } - } - - CInventoryManager::getInstance()->sortBag(); - } - catch (const Exception &e) - { - nlwarning ("Problem while decoding a DB_UPD_INV msg, skipped: %s", e.what()); - } -} - -//----------------------------------------------- -// impulseUpdateInventory: -//----------------------------------------------- -void impulseUpdateInventory (NLMISC::CBitMemStream &impulse) -{ - updateInventoryFromStream( impulse, (INVENTORIES::CInventoryCategoryForCharacter*)NULL, true ); -}; - -//----------------------------------------------- -// impulseInitInventory: -//----------------------------------------------- -void impulseInitInventory (NLMISC::CBitMemStream &impulse) -{ - sint32 p = impulse.getPos(); - impulseUpdateInventory( impulse ); - IngameDbMngr.setInitPacketReceived(); - nlinfo( "DB_INIT:INV done (%u bytes)", impulse.getPos()-p ); -} - -//----------------------------------------------- -// impulseItemInfoSet: -//----------------------------------------------- -void impulseItemInfoSet (NLMISC::CBitMemStream &impulse) -{ - CItemInfos itemInfos; - impulse.serial(itemInfos); - - getInventory().onReceiveItemInfo(itemInfos); -} - -//----------------------------------------------- -// impulseItemInfoRefreshVersion: -//----------------------------------------------- -void impulseItemInfoRefreshVersion (NLMISC::CBitMemStream &impulse) -{ - uint16 slotId; - uint8 infoVersion; - impulse.serial(slotId); - impulse.serial(infoVersion); - - getInventory().onRefreshItemInfoVersion(slotId, infoVersion); -} - -//----------------------------------------------- -// impulsePrereqInfoSet: -//----------------------------------------------- -void impulsePrereqInfoSet (NLMISC::CBitMemStream &impulse) -{ - CPrerequisitInfos prereqInfos; - uint8 index; - impulse.serial(prereqInfos); - impulse.serial(index); - - //write infos in interface - CBotChatManager::getInstance()->onReceiveMissionInfo(index, prereqInfos); -} - -//----------------------------------------------- -//----------------------------------------------- -void impulseDeathRespawnPoint (NLMISC::CBitMemStream &impulse) -{ - CRespawnPointsMsg msg; - impulse.serial(msg); - if (PermanentlyBanned) return; - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupMap *pMap = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:respawn_map:content:map_content:actual_map")); - if (pMap == NULL) - { - nlwarning("problem cannot find ui:interface:respawn_map:content:map_content:actual_map"); - return; - } - pMap->addRespawnPoints(msg); - - - pMap = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:map:content:map_content:actual_map")); - if (pMap == NULL) - { - nlwarning("problem cannot find ui:interface:map:content:map_content:actual_map"); - return; - } - pMap->addRespawnPoints(msg); -} - -//----------------------------------------------- -//----------------------------------------------- -void impulseDeathRespawn (NLMISC::CBitMemStream &impulse) -{ - // TODO : Bring me to life !!! -} - -//----------------------------------------------- -// impulseDuelInvitation : -//----------------------------------------------- -void impulseDuelInvitation(NLMISC::CBitMemStream &impulse) -{ - uint32 textID; - impulse.serial(textID); - - //nlinfo("impulseCallback : Received DUEL:INVITATION %d", textID); - - if (PermanentlyBanned) return; - - //activate the pop up window - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:join_duel_proposal")); - if (pGC == NULL) return; - CViewTextID *pVTID = dynamic_cast(pGC->getView("invitor_name")); - if (pVTID == NULL) return; - pVTID->setTextId(textID); - pGC->setActive(true); - CWidgetManager::getInstance()->setTopWindow(pGC); - pGC->updateCoords(); - pGC->center(); - pGC->enableBlink(2); - -}// impulseDuelInvitation // - -//----------------------------------------------- -// impulseDuelCancelInvitation: -//----------------------------------------------- -void impulseDuelCancelInvitation(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - //nlinfo("impulseCallback : Received DUEL:CANCEL_INVITATION"); - - //activate the pop up window - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:join_duel_proposal")); - if (pGC == NULL) return; - pGC->setActive(false); - -}// impulseDuelCancelInvitation // - -//----------------------------------------------- -// impulsePVPChallengeInvitation : -//----------------------------------------------- -void impulsePVPChallengeInvitation(NLMISC::CBitMemStream &impulse) -{ - uint32 textID; - impulse.serial(textID); - - if (PermanentlyBanned) return; - - //nlinfo("impulseCallback : Received PVP_CHALLENGE:INVITATION %d", textID); - - //activate the pop up window - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:join_pvp_challenge_proposal")); - if (pGC == NULL) return; - CViewTextID *pVTID = dynamic_cast(pGC->getView("invitor_name")); - if (pVTID == NULL) return; - pVTID->setTextId(textID); - pGC->setActive(true); - CWidgetManager::getInstance()->setTopWindow(pGC); - pGC->updateCoords(); - pGC->center(); - pGC->enableBlink(2); - -}// impulsePVPChallengeInvitation // - -//----------------------------------------------- -// impulsePVPChallengeCancelInvitation: -//----------------------------------------------- -void impulsePVPChallengeCancelInvitation(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallback : Received PVP_CHALLENGE:CANCEL_INVITATION"); - - //activate the pop up window - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:join_pvp_challenge_proposal")); - if (pGC == NULL) return; - pGC->setActive(false); - -}// impulsePVPChallengeCancelInvitation // - - - -//----------------------------------------------- -// impulsePVPFactionPushFactionWar: -//----------------------------------------------- -void impulsePVPFactionPushFactionWar(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallback : Received PVP_FACTION:PUSH_FACTION_WAR"); - - PVP_CLAN::CFactionWar factionWar; - impulse.serialEnum(factionWar.Clan1); - impulse.serialEnum(factionWar.Clan2); - - CFactionWarManager::getInstance()->addFactionWar(factionWar); -} - - -//----------------------------------------------- -// impulsePVPFactionPopFactionWar: -//----------------------------------------------- -void impulsePVPFactionPopFactionWar(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallback : Received PVP_FACTION:POP_FACTION_WAR"); - - PVP_CLAN::CFactionWar factionWar; - impulse.serialEnum(factionWar.Clan1); - impulse.serialEnum(factionWar.Clan2); - - CFactionWarManager::getInstance()->stopFactionWar(factionWar); -} - - -//----------------------------------------------- -// impulsePVPFactionFactionWars: -//----------------------------------------------- -void impulsePVPFactionFactionWars(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallback : Received PVP_FACTION:FACTION_WARS"); - - CFactionWarsMsg factionWars; - impulse.serial(factionWars); - - for( uint i=0; iaddFactionWar(factionWars.FactionWarOccurs[i]); - } -} - - - -//----------------------------------------------- -// impulsePVPChooseClan -//----------------------------------------------- -/* -void impulsePVPChooseClan(NLMISC::CBitMemStream &impulse) -{ - nlinfo("impulsePVPChooseClan : Received PVP_CLAN:CHOOSE_CLAN"); - - EGSPD::CPeople::TPeople clan1= EGSPD::CPeople::Unknown, clan2= EGSPD::CPeople::Unknown; - impulse.serialEnum( clan1 ); - impulse.serialEnum( clan2 ); - - if (PermanentlyBanned) return; - - //activate the pop up window - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:join_pvp_clan_proposal")); - if (pGC == NULL) return; - pGC->setActive(true); - - CCtrlTextButton * butClan1 = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:join_pvp_clan_proposal:content:clan1")); - if( butClan1 == NULL ) - return; - butClan1->setText( ucstring(EGSPD::CPeople::toString( clan1 )) ); - - CCtrlTextButton * butClan2 = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:join_pvp_clan_proposal:content:clan2")); - if( butClan2 == NULL ) - return; - butClan2->setText( ucstring(EGSPD::CPeople::toString( clan2 )) ); -} -*/ - -//----------------------------------------------- -// impulseEncyclopediaUpdate -//----------------------------------------------- -void impulseEncyclopediaUpdate(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallback : Received ENCYCLOPEDIA:UPDATE"); - - CEncyclopediaUpdateMsg msg; - impulse.serial(msg); - if (PermanentlyBanned) return; - CEncyclopediaManager::getInstance()->update(msg); -}// impulseEncyclopediaUpdate // - -//----------------------------------------------- -// impulseEncyclopediaInit -//----------------------------------------------- -void impulseEncyclopediaInit(NLMISC::CBitMemStream &impulse) -{ - //nlinfo("impulseCallback : Received ENCYCLOPEDIA:INIT"); - - CEncyclopediaUpdateMsg msg; - impulse.serial(msg); - if (PermanentlyBanned) return; - CEncyclopediaManager::getInstance()->update(msg); -}// impulseEncyclopediaInit // - -//----------------------------------------------- -//----------------------------------------------- -void impulseItemOpenRoomInventory(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - // This is a message because we may do other things there - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:INVENTORY_ROOM_OPENED")->setValue32(1); -} - -//----------------------------------------------- -//----------------------------------------------- -void impulseItemCloseRoomInventory(NLMISC::CBitMemStream &impulse) -{ - if (PermanentlyBanned) return; - // This is a message because we may do other things there - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:INVENTORY_ROOM_OPENED")->setValue32(0); - - // deactivate the pop up window - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:inv_room")); - if (pGC == NULL) return; - pGC->setActive(false); -} - -//----------------------------------------------- -//----------------------------------------------- -void impulseUserBars(NLMISC::CBitMemStream &impulse) -{ - uint8 msgNumber; - sint32 hp, sap, sta, focus; - impulse.serial(msgNumber); - impulse.serial(hp); - impulse.serial(sap); - impulse.serial(sta); - impulse.serial(focus); - - if (PermanentlyBanned) return; - - // Setup the user Bars - CBarManager::CBarInfo bi; - CBarManager::getInstance()->setupUserBarInfo(msgNumber, hp, sap, sta, focus); -} - -//----------------------------------------------- -//----------------------------------------------- -void impulseOutpostChooseSide(NLMISC::CBitMemStream &impulse) -{ - // read message - uint8 type; - bool outpostInFire; - bool playerGuildInConflict; - bool playerGuildIsAttacker; - impulse.serial(type); - impulse.serial(outpostInFire); - impulse.serial(playerGuildInConflict); - impulse.serial(playerGuildIsAttacker); - uint32 ownerGuildNameId; - impulse.serial( ownerGuildNameId ); - uint32 attackerGuildNameId; - impulse.serial( attackerGuildNameId ); - uint32 declTimer; - impulse.serial( declTimer ); - - // start - OutpostManager.startPvpJoinProposal((OUTPOSTENUMS::TPVPType)type, outpostInFire, playerGuildInConflict, playerGuildIsAttacker, - ownerGuildNameId, attackerGuildNameId, declTimer); -} - -//----------------------------------------------- -//----------------------------------------------- -void impulseOutpostDeclareWarAck(NLMISC::CBitMemStream &impulse) -{ - bool canValidate; - uint32 docTextId; - uint32 timeStartAttack; - - impulse.serial(canValidate); - impulse.serial(docTextId); - impulse.serial(timeStartAttack); - - // write result in Local DB. - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - - // ack reception - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:OUTPOST:DECLARE_WAR_ACK_RECEIVED"); - if(node) - node->setValueBool(true); - // set result of ACK - node= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:OUTPOST:DECLARE_WAR_ACK_OK"); - if(node) - node->setValueBool(canValidate); - node= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:OUTPOST:DECLARE_WAR_ACK_TEXTID"); - if(node) - node->setValue32(docTextId); - node= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:OUTPOST:DECLARE_WAR_ACK_TIME_RANGE_ATT"); - if(node) - node->setValue32(timeStartAttack); -} - -extern void addWebIGParams(string &url, bool trustedDomain); - -//----------------------------------------------- -//----------------------------------------------- -class CServerMessageBoxOnReceiveTextId : public STRING_MANAGER::IStringWaitCallback -{ -private: - enum TTextType {TitleType= 0, ContentType, NumTextType}; - uint32 _TextId[NumTextType]; - bool _TextReceived[NumTextType]; - bool _AlreadyDisplayed; - - // show the window - void activateMsgBoxWindow() - { - STRING_MANAGER::CStringManagerClient *pSMC= STRING_MANAGER::CStringManagerClient::instance(); - - // get the content string (should have been received!) - ucstring contentStr; - ucstring titleStr; - if(!pSMC->getDynString(_TextId[ContentType], contentStr)) - return; - - if(!pSMC->getDynString(_TextId[TitleType], titleStr)) - return; - - // if the string start with a @{Wxxxx} code, remove it and get the wanted window size - sint w = 256; // default size to 256 !! - bool is_webig = false; - - if(contentStr.size()>=6 && contentStr[0]=='W' && contentStr[1]=='E' && contentStr[2]=='B' - && contentStr[3]==' ' && contentStr[4]==':' && contentStr[5]==' ' ) - { - uint i; - const uint digitStart= 6; - const uint digitMaxEnd= (uint)contentStr.size(); - - is_webig = true; - - for(i = digitStart; i < digitMaxEnd; i++) - { - if(contentStr[i] == ' ') - break; - } - if(i != digitMaxEnd) - { - ucstring web_app = contentStr.substr(digitStart, i-digitStart); - contentStr = ucstring(ClientCfg.WebIgMainDomain + "/") + web_app + ucstring("/index.php?") + contentStr.substr((size_t)i + 1); - } - else - { - contentStr.clear(); - i = digitStart; - } - } - else if(contentStr.size()>=5 && contentStr[0]=='@' && contentStr[1]=='{' && contentStr[2]=='W') - { - uint i; - const uint digitStart= 3; - const uint digitMaxEnd= 8; - for(i=digitStart;i - group = group.substr(9, group.size()-10); - groupHtml = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:"+group+":content:html")); - if (!groupHtml) - { - groupHtml = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:webig:content:html")); - group = "webig"; - } - - if (groupHtml) - { - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:"+group)); - if (pGC) - { - if (contentStr.empty()) - { - pGC->setActive(false); - } - else - { - if (group == "webig") - pGC->setActive(true); - string url = contentStr.toString(); - addWebIGParams(url, true); - groupHtml->browse(url.c_str()); - CWidgetManager::getInstance()->setTopWindow(pGC); - } - } - } - } - else - { - CGroupContainer *pGC = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:server_message_box")); - if (pGC) - { - // show the window with correct width - pGC->setW(w); - pGC->setActive(true); - - // must set the text by hand - CViewText *vt= dynamic_cast(CWidgetManager::getInstance()->getElementFromId(CWidgetManager::getInstance()->getParser()->getDefine("server_message_box_content_view_text"))); - if(vt) - vt->setTextFormatTaged(contentStr); - - // open - CWidgetManager::getInstance()->setTopWindow(pGC); - pGC->invalidateCoords(); - // Yoyo: because of buggued group container, I found that 6 times is a good number.... - for(uint i=0;i<6;i++) - pGC->updateCoords(); - pGC->center(); - pGC->enableBlink(2); - } - } - } - -public: - // called when the string is available - virtual void onDynStringAvailable(uint stringId, const ucstring &value) - { - // don't care if already displayed - if(_AlreadyDisplayed) - return; - - // check if one of waited text - for(uint i=0;i display window - _AlreadyDisplayed= true; - activateMsgBoxWindow(); - } - - // start the waiter - void startWaitTexts(uint32 titleTextId, uint32 docTextId) - { - // reset - _TextId[TitleType]= titleTextId; - _TextId[ContentType]= docTextId; - _TextReceived[TitleType]= false; - _TextReceived[ContentType]= false; - _AlreadyDisplayed= false; - - // start to wait receive of those string (NB: they may be already here, but waitDynStrings calls directly the callback in this case) - STRING_MANAGER::CStringManagerClient *pSMC= STRING_MANAGER::CStringManagerClient::instance(); - pSMC->waitDynString(titleTextId, this); - pSMC->waitDynString(docTextId, this); - } -}; -CServerMessageBoxOnReceiveTextId ServerMessageBoxOnReceiveTextId; - - -void impulseUserPopup(NLMISC::CBitMemStream &impulse) -{ - uint32 titleTextId; - uint32 docTextId; - impulse.serial(titleTextId); - impulse.serial(docTextId); - - // setup TEMP DB for title - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:TEMP:SERVER_POPUP:TITLE"); - if(node) node->setValue32(titleTextId); - - // Open the Popup only when the 2 dyn strings are available - ServerMessageBoxOnReceiveTextId.startWaitTexts(titleTextId, docTextId); -} - -//----------------------------------------------- -//----------------------------------------------- -//extern void impulseCombatFlyingHpDelta(NLMISC::CBitMemStream &impulse); -void impulseCombatFlyingHpDelta(NLMISC::CBitMemStream &impulse) -{ - uint32 entityID; - uint32 rgba; - sint16 hpDelta; - impulse.serial(entityID); - impulse.serial(rgba); - impulse.serial(hpDelta); - CRGBA color((uint8)(rgba>>24&255), (uint8)(rgba>>16&255), (uint8)(rgba>>8&255), (uint8)(rgba&255)); - CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(entityID); - if (entity) - entity->addHPOutput(ucstring(toString("%d", hpDelta)), color); -} - -void impulseCombatFlyingTextItemSpecialEffectProc(NLMISC::CBitMemStream &impulse) -{ - uint32 entityID; - uint32 rgba; - uint8 effect; - sint32 param; - impulse.serial(entityID); - impulse.serial(rgba); - impulse.serial(effect); - impulse.serial(param); - CRGBA color((uint8)(rgba>>24&255), (uint8)(rgba>>16&255), (uint8)(rgba>>8&255), (uint8)(rgba&255)); - ucstring text = CI18N::get(toString("uiItemSpecialEffectFlyingText%s", ITEM_SPECIAL_EFFECT::toString((ITEM_SPECIAL_EFFECT::TItemSpecialEffect)effect).c_str())); - strFindReplace(text, "%param", toString("%d", param)); - CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(entityID); - if (entity) - entity->addHPOutput(text, color); -} - -void impulseCombatFlyingText(NLMISC::CBitMemStream &impulse) -{ - uint32 entityID; - uint8 tmp; - impulse.serial(entityID); - impulse.serial(tmp); - COMBAT_FLYING_TEXT::TCombatFlyingText type = (COMBAT_FLYING_TEXT::TCombatFlyingText)tmp; - - CRGBA color(255, 255, 255); - ucstring text(""); - float dt = 0.0f; - - switch (type) - { - case COMBAT_FLYING_TEXT::TargetDodge: // The target dodged - color = CRGBA(255, 128, 64); - text = CI18N::get("uiDodge"); - break; - - case COMBAT_FLYING_TEXT::TargetParry: // The target parried - color = CRGBA(255, 128, 64); - text = CI18N::get("uiParry"); - break; - - case COMBAT_FLYING_TEXT::TargetEvade: // Actually the user miss his hit - color = CRGBA(255, 128, 64); - text = CI18N::get("uiEvade"); - break; - - case COMBAT_FLYING_TEXT::SelfEvade: // Actually the target miss his hit - color = CRGBA(255, 255, 0); - text = CI18N::get("uiEvade"); - break; - - case COMBAT_FLYING_TEXT::TargetResist: // The target resisted magic - color = CRGBA(255, 128, 64); - text = CI18N::get("uiResist"); - break; - - case COMBAT_FLYING_TEXT::SelfResist: // The user resisted magic - color = CRGBA(255, 255, 0); - text = CI18N::get("uiResist"); - break; - - case COMBAT_FLYING_TEXT::SelfInterrupt: // the user cast was interupted - color = CRGBA(200, 0, 0); - text = CI18N::get("uiInterrupt"); - dt = 0.4f; - break; - - case COMBAT_FLYING_TEXT::SelfFailure: // The user failed to cast - color = CRGBA(200, 0, 0); - text = CI18N::get("uiFailure"); - break; - - default: // bad type - nlwarning("Bad type for COMBAT_FLYING_TEXT:TCombatFlyingText enum"); - break; - } - - CEntityCL *entity = EntitiesMngr.getEntityByCompressedIndex(entityID); - if (entity) - entity->addHPOutput(text, color, dt); -} - -void impulseSetSeason(NLMISC::CBitMemStream &impulse) -{ - extern uint8 ServerSeasonValue; - extern bool ServerSeasonReceived; - impulse.serial(ServerSeasonValue); - ServerSeasonReceived = true; -} - -void impulseDssDown(NLMISC::CBitMemStream &impulse) -{ - FarTP.onDssDown(); -} - -void impulseSetNpcIconDesc(NLMISC::CBitMemStream &impulse) -{ - uint8 nb8; - impulse.serial(nb8); - bool hasChanged = false; - for (uint i=0; i!=(uint)nb8; ++i) - { - TNPCIconCacheKey npcIconCacheKey; - impulse.serial(npcIconCacheKey); - uint32 state; - impulse.serial(state); - hasChanged = CNPCIconCache::getInstance().onReceiveMissionAvailabilityForThisChar(npcIconCacheKey, (NPC_ICON::TNPCMissionGiverState)state) || hasChanged; // mind the order to avoid partial evaluation - } - if (hasChanged) - CNPCIconCache::getInstance().refreshIconsOfScene(); -} - -void impulseServerEventForMissionAvailability(NLMISC::CBitMemStream &impulse) -{ - CNPCIconCache::getInstance().onEventForMissionAvailabilityForThisChar(); -} - -void impulseSetNpcIconTimer(NLMISC::CBitMemStream &impulse) -{ - NLMISC::TGameCycle delay; - impulse.serial(delay); - CNPCIconCache::getInstance().setMissionGiverTimer(delay); -} - -//----------------------------------------------- -// initializeNetwork : -//----------------------------------------------- -void initializeNetwork() -{ - GenericMsgHeaderMngr.setCallback("DB_UPD_PLR", impulseDatabaseUpdatePlayer); - GenericMsgHeaderMngr.setCallback("DB_INIT:PLR", impulseDatabaseInitPlayer); - GenericMsgHeaderMngr.setCallback("DB_UPD_INV", impulseUpdateInventory); - GenericMsgHeaderMngr.setCallback("DB_INIT:INV", impulseInitInventory); - GenericMsgHeaderMngr.setCallback("DB_GROUP:UPDATE_BANK", impulseDatabaseUpdateBank); - GenericMsgHeaderMngr.setCallback("DB_GROUP:INIT_BANK", impulseDatabaseInitBank); - GenericMsgHeaderMngr.setCallback("DB_GROUP:RESET_BANK", impulseDatabaseResetBank); - GenericMsgHeaderMngr.setCallback("CONNECTION:NO_USER_CHAR", impulseNoUserChar); - GenericMsgHeaderMngr.setCallback("CONNECTION:USER_CHARS", impulseUserChars); - GenericMsgHeaderMngr.setCallback("CONNECTION:USER_CHAR", impulseUserChar); - GenericMsgHeaderMngr.setCallback("CONNECTION:FAR_TP", impulseFarTP); - GenericMsgHeaderMngr.setCallback("CONNECTION:READY", impulseServerReady); - GenericMsgHeaderMngr.setCallback("CONNECTION:VALID_NAME", impulseCharNameValid); - GenericMsgHeaderMngr.setCallback("CONNECTION:SHARD_ID", impulseShardId); - GenericMsgHeaderMngr.setCallback("CONNECTION:SERVER_QUIT_OK", impulseServerQuitOk); - GenericMsgHeaderMngr.setCallback("CONNECTION:SERVER_QUIT_ABORT", impulseServerQuitAbort); - GenericMsgHeaderMngr.setCallback("CONNECTION:MAIL_AVAILABLE", impulseMailNotification); - GenericMsgHeaderMngr.setCallback("CONNECTION:GUILD_MESSAGE_AVAILABLE", impulseForumNotification); - GenericMsgHeaderMngr.setCallback("CONNECTION:PERMANENT_BAN", impulsePermanentBan); - GenericMsgHeaderMngr.setCallback("CONNECTION:UNBAN", impulsePermanentUnban); - - GenericMsgHeaderMngr.setCallback("STRING:CHAT", impulseChat); - GenericMsgHeaderMngr.setCallback("STRING:TELL", impulseTell); - GenericMsgHeaderMngr.setCallback("STRING:FAR_TELL", impulseFarTell); - GenericMsgHeaderMngr.setCallback("STRING:CHAT2", impulseChat2); - GenericMsgHeaderMngr.setCallback("STRING:DYN_STRING", impulseDynString); - GenericMsgHeaderMngr.setCallback("STRING:DYN_STRING_GROUP", inpulseDynStringInChatGroup); - GenericMsgHeaderMngr.setCallback("STRING:TELL2", impulseTell2); -// GenericMsgHeaderMngr.setCallback("STRING:ADD_DYN_STR", impulseAddDynStr); - GenericMsgHeaderMngr.setCallback("TP:DEST", impulseTP); - GenericMsgHeaderMngr.setCallback("TP:DEST_WITH_SEASON", impulseTPWithSeason); - GenericMsgHeaderMngr.setCallback("TP:CORRECT", impulseCorrectPos); - GenericMsgHeaderMngr.setCallback("COMBAT:ENGAGE_FAILED", impulseCombatEngageFailed); - GenericMsgHeaderMngr.setCallback("BOTCHAT:DYNCHAT_OPEN", impulseDynChatOpen); - GenericMsgHeaderMngr.setCallback("BOTCHAT:DYNCHAT_CLOSE", impulseDynChatClose); - - GenericMsgHeaderMngr.setCallback("CASTING:BEGIN", impulseBeginCast); - GenericMsgHeaderMngr.setCallback("TEAM:INVITATION", impulseTeamInvitation); - GenericMsgHeaderMngr.setCallback("TEAM:SHARE_OPEN", impulseTeamShareOpen); - GenericMsgHeaderMngr.setCallback("TEAM:SHARE_INVALID", impulseTeamShareInvalid); - GenericMsgHeaderMngr.setCallback("TEAM:SHARE_CLOSE", impulseTeamShareClose); - GenericMsgHeaderMngr.setCallback("TEAM:CONTACT_INIT", impulseTeamContactInit); - GenericMsgHeaderMngr.setCallback("TEAM:CONTACT_CREATE", impulseTeamContactCreate); - GenericMsgHeaderMngr.setCallback("TEAM:CONTACT_STATUS", impulseTeamContactStatus); - GenericMsgHeaderMngr.setCallback("TEAM:CONTACT_REMOVE", impulseTeamContactRemove); - - GenericMsgHeaderMngr.setCallback("EXCHANGE:INVITATION", impulseExchangeInvitation); - GenericMsgHeaderMngr.setCallback("EXCHANGE:CLOSE_INVITATION", impulseExchangeCloseInvitation); - GenericMsgHeaderMngr.setCallback("ANIMALS:MOUNT_ABORT", impulseMountAbort); - - GenericMsgHeaderMngr.setCallback("DEBUG:REPLY_WHERE", impulseWhere); - GenericMsgHeaderMngr.setCallback("DEBUG:COUNTER", impulseCounter); - - // - GenericMsgHeaderMngr.setCallback("STRING_MANAGER:PHRASE_SEND", impulsePhraseSend); - GenericMsgHeaderMngr.setCallback("STRING_MANAGER:STRING_RESP", impulseStringResp); - GenericMsgHeaderMngr.setCallback("STRING_MANAGER:RELOAD_CACHE", impulseReloadCache); - // - GenericMsgHeaderMngr.setCallback("BOTCHAT:FORCE_END", impulseBotChatForceEnd); - - GenericMsgHeaderMngr.setCallback("JOURNAL:INIT_COMPLETED_MISSIONS", impulseJournalInitCompletedMissions); - GenericMsgHeaderMngr.setCallback("JOURNAL:UPDATE_COMPLETED_MISSIONS", impulseJournalUpdateCompletedMissions); -// GenericMsgHeaderMngr.setCallback("JOURNAL:CANT_ABANDON", impulseJournalCantAbandon); - - GenericMsgHeaderMngr.setCallback("JOURNAL:ADD_COMPASS", impulseJournalAddCompass); - GenericMsgHeaderMngr.setCallback("JOURNAL:REMOVE_COMPASS", impulseJournalRemoveCompass); - - - //GenericMsgHeaderMngr.setCallback("GUILD:SET_MEMBER_INFO", impulseGuildSetMemberInfo); - //GenericMsgHeaderMngr.setCallback("GUILD:INIT_MEMBER_INFO", impulseGuildInitMemberInfo); - - GenericMsgHeaderMngr.setCallback("GUILD:JOIN_PROPOSAL", impulseGuildJoinProposal); - - GenericMsgHeaderMngr.setCallback("GUILD:ASCENSOR", impulseGuildAscensor); - GenericMsgHeaderMngr.setCallback("GUILD:LEAVE_ASCENSOR", impulseGuildLeaveAscensor); - GenericMsgHeaderMngr.setCallback("GUILD:ABORT_CREATION", impulseGuildAbortCreation); - GenericMsgHeaderMngr.setCallback("GUILD:OPEN_GUILD_WINDOW", impulseGuildOpenGuildWindow); - - GenericMsgHeaderMngr.setCallback("GUILD:OPEN_INVENTORY", impulseGuildOpenInventory); - GenericMsgHeaderMngr.setCallback("GUILD:CLOSE_INVENTORY", impulseGuildCloseInventory); - - GenericMsgHeaderMngr.setCallback("GUILD:UPDATE_PLAYER_TITLE", impulseGuildUpdatePlayerTitle); - GenericMsgHeaderMngr.setCallback("GUILD:USE_FEMALE_TITLES", impulseGuildUseFemaleTitles); - //GenericMsgHeaderMngr.setCallback("GUILD:INVITATION", impulseGuildInvitation); - - GenericMsgHeaderMngr.setCallback("HARVEST:CLOSE_TEMP_INVENTORY", impulseCloseTempInv); - - GenericMsgHeaderMngr.setCallback("COMMAND:REMOTE_ADMIN", impulseRemoteAdmin); - - GenericMsgHeaderMngr.setCallback("PHRASE:DOWNLOAD", impulsePhraseDownLoad); - GenericMsgHeaderMngr.setCallback("PHRASE:CONFIRM_BUY", impulsePhraseConfirmBuy); - GenericMsgHeaderMngr.setCallback("PHRASE:EXEC_CYCLIC_ACK", impulsePhraseAckExecuteCyclic); - GenericMsgHeaderMngr.setCallback("PHRASE:EXEC_NEXT_ACK", impulsePhraseAckExecuteNext); - - GenericMsgHeaderMngr.setCallback("ITEM_INFO:SET", impulseItemInfoSet); - GenericMsgHeaderMngr.setCallback("ITEM_INFO:REFRESH_VERSION", impulseItemInfoRefreshVersion); - GenericMsgHeaderMngr.setCallback("MISSION_PREREQ:SET", impulsePrereqInfoSet); - GenericMsgHeaderMngr.setCallback("ITEM:OPEN_ROOM_INVENTORY", impulseItemOpenRoomInventory); - GenericMsgHeaderMngr.setCallback("ITEM:CLOSE_ROOM_INVENTORY", impulseItemCloseRoomInventory); - - GenericMsgHeaderMngr.setCallback("DEATH:RESPAWN_POINT", impulseDeathRespawnPoint); - GenericMsgHeaderMngr.setCallback("DEATH:RESPAWN", impulseDeathRespawn); - - GenericMsgHeaderMngr.setCallback("DUEL:INVITATION", impulseDuelInvitation); - GenericMsgHeaderMngr.setCallback("DUEL:CANCEL_INVITATION", impulseDuelCancelInvitation); - - GenericMsgHeaderMngr.setCallback("PVP_CHALLENGE:INVITATION", impulsePVPChallengeInvitation); - GenericMsgHeaderMngr.setCallback("PVP_CHALLENGE:CANCEL_INVITATION", impulsePVPChallengeCancelInvitation); - - GenericMsgHeaderMngr.setCallback("PVP_FACTION:PUSH_FACTION_WAR", impulsePVPFactionPushFactionWar); - GenericMsgHeaderMngr.setCallback("PVP_FACTION:POP_FACTION_WAR", impulsePVPFactionPopFactionWar); - GenericMsgHeaderMngr.setCallback("PVP_FACTION:FACTION_WARS", impulsePVPFactionFactionWars); - - -// GenericMsgHeaderMngr.setCallback("PVP_VERSUS:CHOOSE_CLAN", impulsePVPChooseClan); - - GenericMsgHeaderMngr.setCallback("ENCYCLOPEDIA:UPDATE", impulseEncyclopediaUpdate); - GenericMsgHeaderMngr.setCallback("ENCYCLOPEDIA:INIT", impulseEncyclopediaInit); - - GenericMsgHeaderMngr.setCallback("USER:BARS", impulseUserBars); - GenericMsgHeaderMngr.setCallback("USER:POPUP", impulseUserPopup); - - - GenericMsgHeaderMngr.setCallback("MISSION:ASK_ENTER_CRITICAL", impulseEnterCrZoneProposal); - GenericMsgHeaderMngr.setCallback("MISSION:CLOSE_ENTER_CRITICAL", impulseCloseEnterCrZoneProposal); - - // Module gateway message - GenericMsgHeaderMngr.setCallback( "MODULE_GATEWAY:FEOPEN", cbImpulsionGatewayOpen); - GenericMsgHeaderMngr.setCallback( "MODULE_GATEWAY:GATEWAY_MSG", cbImpulsionGatewayMessage ); - GenericMsgHeaderMngr.setCallback( "MODULE_GATEWAY:FECLOSE", cbImpulsionGatewayClose ); - - GenericMsgHeaderMngr.setCallback( "OUTPOST:CHOOSE_SIDE", impulseOutpostChooseSide ); - GenericMsgHeaderMngr.setCallback( "OUTPOST:DECLARE_WAR_ACK", impulseOutpostDeclareWarAck ); - - GenericMsgHeaderMngr.setCallback( "COMBAT:FLYING_HP_DELTA", impulseCombatFlyingHpDelta ); - GenericMsgHeaderMngr.setCallback( "COMBAT:FLYING_TEXT_ISE", impulseCombatFlyingTextItemSpecialEffectProc ); - GenericMsgHeaderMngr.setCallback( "COMBAT:FLYING_TEXT", impulseCombatFlyingText ); - - GenericMsgHeaderMngr.setCallback( "SEASON:SET", impulseSetSeason ); - GenericMsgHeaderMngr.setCallback( "RING_MISSION:DSS_DOWN", impulseDssDown ); - - GenericMsgHeaderMngr.setCallback( "NPC_ICON:SET_DESC", impulseSetNpcIconDesc ); - GenericMsgHeaderMngr.setCallback( "NPC_ICON:SVR_EVENT_MIS_AVL", impulseServerEventForMissionAvailability ); - GenericMsgHeaderMngr.setCallback( "NPC_ICON:SET_TIMER", impulseSetNpcIconTimer ); -} - - -//----------------------------------------------- -// impulseCallBack : -// The impulse callback to receive all msg from the frontend. -//----------------------------------------------- -void impulseCallBack(NLMISC::CBitMemStream &impulse, sint32 packet, void *arg) -{ - GenericMsgHeaderMngr.execute(impulse); -} - - -//////////// -// METHOD // -//////////// -//----------------------------------------------- -// CNetManager : -// Constructor. -//----------------------------------------------- -CNetManager::CNetManager() : CNetworkConnection() -{ -#ifdef ENABLE_INCOMING_MSG_RECORDER - _IsReplayStarting = false; -#endif -}// CNetManager // - -//----------------------------------------------- -// update : -// Updates the whole connection with the frontend. -// Call this method evently. -// \return bool : 'true' if data were sent/received. -//----------------------------------------------- -bool CNetManager::update() -{ - H_AUTO_USE ( RZ_Client_Net_Mngr_Update ) - -#ifdef ENABLE_INCOMING_MSG_RECORDER - if(_IsReplayStarting) - return; -#endif - - // If the client is in Local Mode -> no network. - if(ClientCfg.Local) - { - // Init - if(_CurrentServerTick == 0) - { - if(T1 >= _LCT) - { - _MachineTimeAtTick = T1; - _CurrentClientTime = _MachineTimeAtTick - _LCT; - _CurrentClientTick = 0; - _CurrentServerTick = 10; - } - - return false; - } - - if((T1 - _MachineTimeAtTick) >= _MsPerTick) - { - NLMISC::TGameCycle nbTick = (NLMISC::TGameCycle)((T1 - _MachineTimeAtTick)/_MsPerTick); - _CurrentClientTick += nbTick; - _CurrentServerTick += nbTick; - _MachineTimeAtTick += nbTick*_MsPerTick; - } - - // update the smooth server tick for debug - CNetworkConnection::updateSmoothServerTick(); - - // emulation done -#ifdef ENABLE_INCOMING_MSG_RECORDER - return false; -#endif - } - - // Update the base class. - bool result = CNetworkConnection::update(); - // Get changes with the update. - const vector &changes = NetMngr.getChanges(); - - // Manage changes - vector::const_iterator it; - for(it = changes.begin(); it < changes.end(); ++it) - { - const CChange &change = *it; - // Update a property. - if(change.Property < AddNewEntity) - { - if (!IgnoreEntityDbUpdates || change.ShortId == 0) - { - // Update the visual property for the slot. - EntitiesMngr.updateVisualProperty(change.GameCycle, change.ShortId, change.Property, change.PositionInfo.PredictedInterval); - } - else - { - nlwarning("CNetManager::update : Skipping EntitiesMngr.updateVisualProperty() because IgnoreEntityDbUpdates=%s and change.ShortId=%d", (IgnoreEntityDbUpdates?"true":"false"), change.ShortId); - } - } - // Add New Entity (and remove the old one in the slot). - else if(change.Property == AddNewEntity) - { - if (!IgnoreEntityDbUpdates || change.ShortId == 0) - { - // Remove the old entity. - EntitiesMngr.remove(change.ShortId, false); - // Create the new entity. - if(EntitiesMngr.create(change.ShortId, get(change.ShortId), change.NewEntityInfo) == 0) - nlwarning("CNetManager::update : entity in the slot '%u' has not been created.", change.ShortId); - } - else - { - nlwarning("CNetManager::update : Skipping EntitiesMngr.create() because IgnoreEntityDbUpdates=%s and change.ShortId=%d", (IgnoreEntityDbUpdates?"true":"false"), change.ShortId); - } - } - // Delete an entity - else if(change.Property == RemoveOldEntity) - { - if (!IgnoreEntityDbUpdates || change.ShortId == 0) - { - // Remove the old entity. - EntitiesMngr.remove(change.ShortId, true); - } - else - { - nlwarning("CNetManager::update : Skipping EntitiesMngr.remove() because IgnoreEntityDbUpdates=%s and change.ShortId=%d", (IgnoreEntityDbUpdates?"true":"false"), change.ShortId); - } - } - // Lag detected. - else if(change.Property == LagDetected) - { - nldebug("CNetManager::update : Lag detected."); - } - // Probe received. - else if(change.Property == ProbeReceived) - { - nldebug("CNetManager::update : Probe Received."); - } - // Connection ready. - else if(change.Property == ConnectionReady) - { - nldebug("CNetManager::update : Connection Ready."); - } - // Property unknown. - else - nlwarning("CNetManager::update : The property '%d' is unknown.", change.Property); - } - ChatMngr.flushBuffer(InterfaceChatDisplayer); - // Clear all changes. - clearChanges(); - - // Update data base server state - if (IngameDbMngr.getNodePtr()) - { - CInterfaceManager *im = CInterfaceManager::getInstance(); - if (im) - { - CCDBNodeLeaf *node = NULL; - - if (!m_PingLeaf) - m_PingLeaf = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:PING", false); - - if (m_PingLeaf) - { - node = &*m_PingLeaf; - if (node) - node->setValue32(getPing()); - } - - if (!m_UploadLeaf) - m_UploadLeaf = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:UPLOAD", false); - - if (m_UploadLeaf) - { - node = &*m_UploadLeaf; - if (node) - node->setValue32((sint32)(getMeanUpload()*1024.f/8.f)); - } - - if (!m_DownloadLeaf) - m_DownloadLeaf = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:DOWNLOAD", false); - - if (m_DownloadLeaf) - { - node = &*m_DownloadLeaf; - if (node) - node->setValue32((sint32)(getMeanDownload()*1024.f/8.f)); - } - - if (!m_PacketLostLeaf) - m_PacketLostLeaf = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:PACKETLOST", false); - - if (m_PacketLostLeaf) - { - node = &*m_PacketLostLeaf; - if (node) - node->setValue32((sint32)getMeanPacketLoss()); - } - - if (!m_ServerStateLeaf) - m_ServerStateLeaf = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:SERVERSTATE", false); - - if (m_ServerStateLeaf) - { - node = &*m_ServerStateLeaf; - if (node) - node->setValue32((sint32)getConnectionState()); - } - - if (!m_ConnectionQualityLeaf) - m_ConnectionQualityLeaf = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:CONNECTION_QUALITY", false); - - if (m_ConnectionQualityLeaf) - { - node = &*m_ConnectionQualityLeaf; - if (node) - node->setValue32((sint32)getConnectionQuality()); - } - } - } - - // Return 'true' if data were sent/received. - return result; - - -}// update // - -//----------------------------------------------- -// getConnectionQuality : -//----------------------------------------------- -bool CNetManager::getConnectionQuality() -{ - // If the client is in Local Mode -> no network. - if(ClientCfg.Local) - return true; - - return CNetworkConnection::getConnectionQuality(); -}// getConnectionQuality // - - -/** - * Buffers a bitmemstream, that will be converted into a generic action, to be sent later to the server (at next update). - */ -void CNetManager::push(NLMISC::CBitMemStream &msg) -{ - // If the client is in Local Mode -> no network. - if(ClientCfg.Local) - return; - - if (PermanentlyBanned) return; - - CNetworkConnection::push(msg); -} - -/** - * Buffers a target action - */ -void CNetManager::pushTarget(CLFECOMMON::TCLEntityId slot) -{ - // If the client is in Local Mode -> no network. - if(ClientCfg.Local) - { - if(UserEntity->mode() != MBEHAV::COMBAT - && UserEntity->mode() != MBEHAV::COMBAT_FLOAT) - { - UserEntity->targetSlot(slot); - } - return; - } - - CNetworkConnection::pushTarget(slot, LHSTATE::NONE); -} - - -/** - * Buffers a pick-up action - */ -void CNetManager::pushPickup(CLFECOMMON::TCLEntityId slot, LHSTATE::TLHState lootOrHarvest) -{ - // If the client is in Local Mode -> no network. - if(ClientCfg.Local) - { - return; - } - - CNetworkConnection::pushTarget(slot, lootOrHarvest); -} - - -/** - * Send - */ -void CNetManager::send(NLMISC::TGameCycle gameCycle) -{ - // If the client is in Local Mode -> no network. - if(ClientCfg.Local) - return; - - // wait till next server is received - if (_LastSentCycle >= gameCycle) - { - //nlinfo ("Try to CNetManager::send(%d) _LastSentCycle=%d more than one time with the same game cycle, so we wait new game cycle to send", gameCycle, _LastSentCycle); - while (_LastSentCycle >= gameCycle) - { - // Update network. - update(); - // Send dummy info - send(); - // Do not take all the CPU. - nlSleep(100); - - gameCycle = getCurrentServerTick(); - } - } - - CNetworkConnection::send(gameCycle); -} - -/** - * Send - */ -void CNetManager::send() -{ - // If the client is in Local Mode -> no network. - if(ClientCfg.Local) - return; - - CNetworkConnection::send(); -} - -/** - * Disconnects the current connection - */ -void CNetManager::disconnect() -{ - // If the client is in Local Mode -> no need to disconnect. - if(ClientCfg.Local) - return; - - CNetworkConnection::disconnect(); -}// disconnect // - - -/** - * Reset data and init the socket - */ -void CNetManager::reinit() -{ - if(ClientCfg.Local) - return; - - IngameDbMngr.resetInitState(); - CNetworkConnection::reinit(); -} - -void CNetManager::waitForServer() -{ - sint LastGameCycle = getCurrentServerTick(); - - for(;;) - { - // Event server get events - CInputHandlerManager::getInstance()->pumpEventsNoIM(); - // Update Network. - update(); - - if (LastGameCycle != (sint) getCurrentServerTick()) - break; - - nlSleep(100); - send(); - } - -}// waitForServer // - - -#ifdef ENABLE_INCOMING_MSG_RECORDER -//----------------------------------------------- -// setReplayingMode : -//----------------------------------------------- -void CNetManager::setReplayingMode( bool onOff, const std::string& filename ) -{ - CNetworkConnection::setReplayingMode(onOff, filename); - _IsReplayStarting = onOff; -}// setReplayingMode // - -//----------------------------------------------- -// startReplay : -//----------------------------------------------- -void CNetManager::startReplay() -{ - // Init Replay - _MachineTimeAtTick = T1; - if(_MachineTimeAtTick >= _LCT) - _CurrentClientTime = _MachineTimeAtTick - _LCT; - else - _CurrentClientTime = 0; - // Replay now in progress. - _IsReplayStarting = false; -}// startReplay // -#endif - - -/* - * Create the net managers in CLIENT_MULTI mode - */ -void CNetManagerMulti::init( const std::string& cookie, const std::string& addr ) -{ - uint nb, baseCookie; - NLMISC::CConfigFile::CVar *var = ClientCfg.ConfigFile.getVarPtr( "NbConnections" ); - if ( var ) - nb = var->asInt(); - else - nb = 1; - var = ClientCfg.ConfigFile.getVarPtr( "UserId" ); - if ( var ) - baseCookie = var->asInt(); - else - baseCookie = 0; - std::vector fsAddrs; - fsAddrs.push_back( addr ); - string portString = addr.substr( addr.find( ':' ) ); - var = ClientCfg.ConfigFile.getVarPtr( "AdditionalFSList" ); - if ( var ) - { - for ( uint i=0; i!=var->size(); ++i ) - fsAddrs.push_back( var->asString( i ) + portString ); - } - nlinfo( "CNetManagerMulti: Creating %u connections to %u front-ends, baseCookie=%u...", nb, fsAddrs.size(), baseCookie ); - - for ( uint i=0; i!=nb; ++i ) - { - CNetManager *nm = new CNetManager(); - string multicook = NLMISC::toString( "%8x|%8x|%8x", 0, 0, baseCookie + i ); - nm->init( multicook, fsAddrs[i % fsAddrs.size()] ); - _NetManagers.push_back( nm ); - } -} - -// -uint32 ShardId = 0; -std::string WebServer; - - - - -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -/////////// COMMANDS after should NOT appear IN the FINAL VERSION /////////// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// -///////////////////////////////////////////////////////////////////////////// - - -#if !FINAL_VERSION - -// temp : simulate a team msg in local mode -NLMISC_COMMAND(localTellTeam, "Temp : simulate a tell in local mode", " ") -{ - if (args.empty()) return false; - ucstring player = args[0]; - std::string msg; - if (args.size() >= 2) - { - msg = args[1]; - for(uint k = 2; k < args.size(); ++k) - { - msg += " " + args[k]; - } - } - TDataSetIndex dsi = INVALID_DATASET_INDEX; - InterfaceChatDisplayer.displayChat(dsi, ucstring(msg), ucstring(msg), CChatGroup::team, NLMISC::CEntityId::Unknown, player); - return true; -} - -// temp : simulate a tell in local mode -NLMISC_COMMAND(localTell, "Temp : simulate a tell in local mode", " ") -{ - if (args.empty()) return false; - ucstring player = args[0]; - std::string msg; - if (args.size() >= 2) - { - msg = args[1]; - for(uint k = 2; k < args.size(); ++k) - { - msg += " " + args[k]; - } - } -// TDataSetIndex dsi = INVALID_DATASET_ROW; - InterfaceChatDisplayer.displayTell(/*dsi, */ucstring(msg), player); - return true; -} - -NLMISC_COMMAND(testDynChatOpen, "", "") -{ - NLMISC::CBitMemStream bm; - if (bm.isReading()) bm.invert(); - uint32 BotUID = 22; // Compressed Index - uint32 BotName = 654; // Server string - vector DynStrs; // 0 - Desc, 1 - Option0, 2 - Option1, etc.... - DynStrs.push_back(16540); - DynStrs.push_back(11465); - DynStrs.push_back(12654); - bm.serial(BotUID); - bm.serial(BotName); - bm.serialCont(DynStrs); - bm.invert(); - bm.seek(0, NLMISC::IStream::begin); - impulseDynChatOpen(bm); - return true; -} - -NLMISC_COMMAND(testDynChatClose, "", "") -{ - NLMISC::CBitMemStream bm; - if (bm.isReading()) bm.invert(); - uint32 BotUID = 22; // Compressed Index - bm.serial(BotUID); - bm.invert(); - bm.seek(0, NLMISC::IStream::begin); - impulseDynChatClose(bm); - return true; -} - - -NLMISC_COMMAND(testCloseTempInv, "","") -{ - NLMISC::CBitMemStream bm; - impulseCloseTempInv(bm); - return true; -} - -NLMISC_COMMAND(testTeamInvite, "","") -{ - NLMISC::CBitMemStream bm; - if (bm.isReading()) bm.invert(); - uint32 index = 10; - bm.serial(index); - bm.invert(); - bm.seek(0, NLMISC::IStream::begin); - impulseTeamInvitation(bm); - return true; -} -NLMISC_COMMAND(testGuildInvite, "","") -{ - NLMISC::CBitMemStream bm; - if (bm.isReading()) bm.invert(); - uint32 index = 10; - bm.serial(index); - bm.serial(index); - bm.invert(); - bm.seek(0, NLMISC::IStream::begin); - impulseGuildJoinProposal(bm); - return true; -} - -NLMISC_COMMAND( testExchangeInvitation, "Test the modal window for invitation exchange", "" ) -{ - CBitMemStream impulse; - uint32 nameIndex = 0; - impulse.serial(nameIndex); - impulse.invert(); - impulseExchangeInvitation(impulse); - return true; -} - - -NLMISC_COMMAND(testAscensor, "Temp : Simulate a GUILD:ASCENSOR message coming from server","") -{ - NLMISC::CBitMemStream bm; - if (bm.isReading()) bm.invert(); - uint32 index = 10; - bm.serial(index); - bm.invert(); - bm.seek(0, NLMISC::IStream::begin); - impulseGuildAscensor(bm); - return true; -} - -NLMISC_COMMAND(testDuelInvite, "","") -{ - NLMISC::CBitMemStream bm; - if (bm.isReading()) bm.invert(); - uint32 index = 10; - bm.serial(index); - bm.invert(); - bm.seek(0, NLMISC::IStream::begin); - impulseDuelInvitation(bm); - return true; -} - -//NLMISC_COMMAND(receiveId, ""," ") -//{ -// uint32 index; -// fromString(args[0], index); -// ucstring ucstr = args[1]; -// -// vector code; -// -//#ifdef OLD_STRING_SYSTEM -// ChatMngr.getDynamicDB().add( index, ucstr, code ); -//#else -// // TRAP // WE MUST NEVER CALL THIS COMMAND ANYMORE : ALL IS HANDLED BY STRING_MANAGER NOW !!! -// nlstop; -//#endif -// -// return true; -//} - -NLMISC_COMMAND(testOutpostChooseSide, "","b b u32 u32") -{ - if(args.size()<4) - return false; - NLMISC::CBitMemStream bm; - if (bm.isReading()) bm.invert(); - bool playerGuildInConflict; - fromString(args[0], playerGuildInConflict); - bool playerGuildIsAttacker; - fromString(args[1], playerGuildIsAttacker); - bm.serial(playerGuildInConflict); - bm.serial(playerGuildIsAttacker); - uint32 ownerGuildNameId; - fromString(args[2], ownerGuildNameId); - bm.serial( ownerGuildNameId ); - uint32 attackerGuildNameId; - fromString(args[3], attackerGuildNameId); - bm.serial( attackerGuildNameId ); - uint32 declTimer= 100; - bm.serial( declTimer ); - - bm.invert(); - bm.seek(0, NLMISC::IStream::begin); - impulseOutpostChooseSide(bm); - return true; -} - -NLMISC_COMMAND(testUserPopup, "","u32 u32") -{ - if(args.size()<2) - return false; - NLMISC::CBitMemStream bm; - if (bm.isReading()) bm.invert(); - uint32 titleId; - fromString(args[0], titleId); - bm.serial( titleId ); - uint32 textId; - fromString(args[1], textId); - bm.serial( textId ); - - bm.invert(); - bm.seek(0, NLMISC::IStream::begin); - impulseUserPopup(bm); - return true; -} - - -#endif - diff --git a/code/ryzom/client/src/user_entity.cpp b/code/ryzom/client/src/user_entity.cpp deleted file mode 100644 index 0ddd61c41..000000000 --- a/code/ryzom/client/src/user_entity.cpp +++ /dev/null @@ -1,4542 +0,0 @@ -// Ryzom - MMORPG Framework -// Copyright (C) 2010-2019 Winch Gate Property Limited -// -// This source file has been modified by the following contributors: -// Copyright (C) 2013 Laszlo KIS-ADAM (dfighter) -// Copyright (C) 2013-2019 Jan BOON (Kaetemi) -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as -// published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see . - - - - -///////////// -// INCLUDE // -///////////// -#include "stdpch.h" -// Misc. -#include "nel/misc/vectord.h" -#include "nel/misc/matrix.h" -#include "nel/misc/quat.h" -// 3D Interface. -#include "nel/3d/u_scene.h" -#include "nel/3d/u_visual_collision_manager.h" -#include "nel/3d/viewport.h" -#include "nel/3d/u_bone.h" -#include "nel/3d/u_instance_material.h" -#include "nel/3d/u_play_list.h" -#include "nel/3d/u_point_light.h" -#include "nel/3d/u_particle_system_instance.h" -#include "nel/3d/u_camera.h" -// Pacs Interface -#include "nel/pacs/u_global_position.h" -// Client. -#include "user_entity.h" -#include "motion/user_controls.h" -#include "pacs_client.h" -#include "net_manager.h" -#include "time_client.h" -#include "entity_animation_manager.h" -#include "sheet_manager.h" -#include "sound_manager.h" -#include "interface_v3/interface_manager.h" -#include "entities.h" -#include "debug_client.h" -#include "misc.h" -#include "interface_v3/bot_chat_manager.h" -#include "fx_manager.h" -#include "main_loop.h" -#include "interface_v3/group_in_scene_bubble.h" -#include "interface_v3/inventory_manager.h" -#include "nel/gui/group_html.h" -#include "interface_v3/people_interraction.h" -#include "init_main_loop.h" -#include "view.h" -#include "interface_v3/sphrase_manager.h" -#include "interface_v3/sbrick_manager.h" -#include "interface_v3/action_phrase_faber.h" -#include "interface_v3/bar_manager.h" -#include "interface_v3/skill_manager.h" -#include "far_tp.h" -#include "npc_icon.h" -// game share -#include "game_share/slot_types.h" -#include "game_share/player_visual_properties.h" -#include "game_share/mode_and_behaviour.h" -#include "game_share/inventories.h" -#include "game_share/animal_type.h" -#include "game_share/bot_chat_types.h" -// Sound animation -#include "nel/sound/sound_anim_manager.h" -#include "nel/sound/sound_animation.h" -#include "nel/sound/sound_anim_marker.h" -// r2 -#include "r2/editor.h" - -#ifdef DEBUG_NEW -#define new DEBUG_NEW -#endif - -/////////// -// USING // -/////////// -using namespace NLMISC; -using namespace NLPACS; -using namespace std; -using NL3D::UScene; -using NL3D::UVisualCollisionManager; -using NL3D::UTextContext; - - -//////////// -// EXTERN // -//////////// -extern UScene *Scene; -extern UVisualCollisionManager *CollisionManager; -extern CEntityAnimationManager *EAM; -extern UTextContext *TextContext; -extern NL3D::UCamera MainCam; - -// Context help -extern void contextHelp (const std::string &help); - -extern void beastOrder (const std::string &orderStr, const std::string &beastIndexStr, bool confirmFree = true); - -// Out game received position -NLMISC::CVectorD UserEntityInitPos; -NLMISC::CVector UserEntityInitFront; -CUserEntity *UserEntity = NULL; - -uint32 CharFirstConnectedTime = 0; -uint32 CharPlayedTime = 0; - -const double MaxExtractionDistance = 1.0f; - -//////////// -// GLOBAL // -//////////// - -// Hierarchical timer -H_AUTO_DECL ( RZ_Client_Update_Sound ) - -////////////// -// FUNCTION // -////////////// -//string chooseRandom( const vector& sounds, uint32& previousIndex ); - -//----------------------------------------------- -// CUserEntity : -// Constructor. -//----------------------------------------------- -CUserEntity::CUserEntity() -: CPlayerCL() -{ - Type = User; - _Run = false; - _RunWhenAble = false; - _WalkVelocity = 1.0f; - _RunVelocity = 2.0f; - _CurrentVelocity = _WalkVelocity; - - _FrontVelocity = 0.0f; - _LateralVelocity = 0.0f; - - _SpeedServerAdjust = 1.0f; - - // \todo GUIGUI : do it more generic. - _First_Pos = false; - - // No selection, trader, interlocutor at the beginning. - _Selection = CLFECOMMON::INVALID_SLOT; - _Trader = CLFECOMMON::INVALID_SLOT; - _Interlocutor = CLFECOMMON::INVALID_SLOT; - - // Not selectable at the beginning. - _Selectable = false; - - // Your are not on a mount at the beginning. - _OnMount = false; - _HiddenMount = CLFECOMMON::INVALID_SLOT; - - _AnimAttackOn = false; - - _ViewMode = FirstPV; - _PermanentDeath = false; - _FollowMode = false; - - _CheckPrimitive = 0; - // The user is not in collision with someone else. - _ColOn = false; - // Collisions are not removed. - _ColRemoved = false; - - // No Move To at the beginning. - _MoveToSlot = CLFECOMMON::INVALID_SLOT; - _MoveToAction= CUserEntity::None; - _MoveToDist= 0.0; - _MoveToColStartTime= 0; - - _FollowForceHeadPitch= false; - - _ForceLookSlot= CLFECOMMON::INVALID_SLOT; - _LastExecuteCombatSlot= CLFECOMMON::INVALID_SLOT; - - _R2CharMode= R2::TCharMode::Player; - -}// CUserEntity // - - -//----------------------------------------------- -// ~CUserEntity : -// Destructor. -//----------------------------------------------- -CUserEntity::~CUserEntity() -{ - // Remove observers - _SpeedFactor.release(); - _MountHunger.release(); - _MountSpeeds.release(); - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - - { - CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:IS_INVISIBLE", false); - if (node) - { - ICDBNode::CTextId textId; - node->removeObserver(&_InvisibleObs, textId); - } - } - - for(uint i=0;igetDbProp(toString("SERVER:USER:SKILL_POINTS_%d:VALUE", i), false); - if(node) - { - ICDBNode::CTextId textId; - node->removeObserver(_SkillPointObs+i, textId); - } - } - - for( uint i=0; i<_FamesObs.size(); ++i ) - { - uint32 factionIndex = _FamesObs[i]->FactionIndex; - uint32 fameIndexInDatabase = CStaticFames::getInstance().getDatabaseIndex(factionIndex); - string sDBPath = toString("SERVER:FAME:PLAYER%d:VALUE",fameIndexInDatabase); - - CCDBNodeLeaf * node = NLGUI::CDBManager::getInstance()->getDbProp(sDBPath, false); - if(node) - { - ICDBNode::CTextId textId; - node->removeObserver(_FamesObs[i], textId); - } - } - contReset(_FamesObs); - - CNPCIconCache::getInstance().removeObservers(); - - // Remove the Primitive used for check (because ~CEntityCL() will call CEntityCL::removePrimitive(), not CUserEntity::removePrimitive()) - removeCheckPrimitive(); - - CNPCIconCache::release(); - -}// ~CUserEntity // - -//----------------------------------------------- -// initProperties : -// Initialize properties of the entity (according to the class). -//----------------------------------------------- -void CUserEntity::initProperties() -{ - properties().selectable(true); -}// initProperties // - - -//----------------------------------------------- -// build : -// Build the entity from a sheet. -//----------------------------------------------- -bool CUserEntity::build(const CEntitySheet *sheet) // virtual -{ - // Init received position - pos(UserEntityInitPos); - front(UserEntityInitFront); - dir(front()); - setHeadPitch(0); - - // Cast the sheet in the right type. - _PlayerSheet = dynamic_cast(sheet); - if(_PlayerSheet == 0) - { - pushDebugStr("User Sheet is not a valid '.race_stats'."); - return false; - } - else - pushInfoStr("User Sheet is a valid '.race_stats'."); - // Get the DB Entry - if(IngameDbMngr.getNodePtr()) - { - CCDBNodeBranch *nodeRoot = dynamic_cast(IngameDbMngr.getNodePtr()->getNode(0)); - if(nodeRoot) - { - _DBEntry = dynamic_cast(nodeRoot->getNode(_Slot)); - if(_DBEntry == 0) - pushDebugStr("Cannot get a pointer on the DB entry."); - } - } - - disableFollow(); - // Walk/Run ? - if(ClientCfg.RunAtTheBeginning != _Run) - switchVelocity(); - - // Set the up of the user. - up(CVector(0,0,1)); - - // Init User infos. - eyesHeight(ClientCfg.EyesHeight); - walkVelocity(ClientCfg.Walk); - runVelocity(ClientCfg.Run); - - // Compute the first automaton. - _CurrentAutomaton = automatonType() + "_normal.automaton"; - - // Build the PACS Primitive. - if(initPrimitive(0.5f, 2.0f, 0.0f, 0.0f, UMovePrimitive::Slide, (UMovePrimitive::TTrigger)(UMovePrimitive::OverlapTrigger | UMovePrimitive::EnterTrigger), MaskColPlayer, MaskColPlayer | MaskColNpc | MaskColDoor)) - _Primitive->insertInWorldImage(dynamicWI); - - // Compute the element to be able to snap the entity to the ground. - computeCollisionEntity(); - - // Initialize properties of the client. - initProperties(); - - // Initialize the observer for the speed factor and mount stuff - _SpeedFactor.init(); - _MountHunger.init(); - _MountSpeeds.init(); - - // Create the user playlist - createPlayList(); - - // Initialize the internal time. - _LastFrameTime = ((double)T1) * 0.001; - - // Set the gender in local mode. - if(ClientCfg.Local) - { - _Mode = MBEHAV::NORMAL; - _ModeWanted = MBEHAV::NORMAL; - _Gender = ClientCfg.Sex; - SPropVisualA visualA = buildPropVisualA(_PlayerSheet->GenderInfos[_Gender]); - SPropVisualB visualB = buildPropVisualB(_PlayerSheet->GenderInfos[_Gender]); - SPropVisualC visualC; - visualA.PropertySubData.Sex = _Gender; - visualC.PropertyC = 0; - visualC.PropertySubData.CharacterHeight = 0; - visualC.PropertySubData.ArmsWidth = 7; - visualC.PropertySubData.LegsWidth = 7; - visualC.PropertySubData.TorsoWidth = 7; - visualC.PropertySubData.BreastSize = 7; - // Set the Database - sint64 *prop = (sint64 *)&visualA; - NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P"+toString("%d", CLFECOMMON::PROPERTY_VPA))->setValue64(*prop); // Set the database - prop = (sint64 *)&visualB; - NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P"+toString("%d", CLFECOMMON::PROPERTY_VPB))->setValue64(*prop); // Set the database - prop = (sint64 *)&visualC; - NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E0:P"+toString("%d", CLFECOMMON::PROPERTY_VPC))->setValue64(*prop); // Set the database - // Apply Changes. - updateVisualProperty(0, CLFECOMMON::PROPERTY_VPA); - } - // \todo GUIGUI Retrieve the player's appearence during the avatar selection. - // Get Visual Properties From the character selection window. - else - { - } - - // Rebuild interface - buildInSceneInterface (); - - // Add observer on invisible property - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - { - CCDBNodeLeaf *node = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:IS_INVISIBLE", false); - if (node) - { - ICDBNode::CTextId textId; - node->addObserver(&_InvisibleObs, textId); - } - } - - // Add an observer on skill points - for(uint i=0;igetDbProp(toString("SERVER:USER:SKILL_POINTS_%d:VALUE", i), false); - if(node) - { - ICDBNode::CTextId textId; - node->addObserver(_SkillPointObs+i, textId); - } - } - - // Add an observer on Fames - for( uint i=(uint)PVP_CLAN::BeginClans; i<=(uint)PVP_CLAN::EndClans; ++i ) - { - uint32 factionIndex = PVP_CLAN::getFactionIndex((PVP_CLAN::TPVPClan)i); - uint32 fameIndexInDatabase = CStaticFames::getInstance().getDatabaseIndex(factionIndex); - string sDBPath = toString("SERVER:FAME:PLAYER%d:VALUE",fameIndexInDatabase); - - CFameObserver * fameObs = new CFameObserver(); - if( fameObs ) - { - fameObs->FactionIndex = factionIndex; - CCDBNodeLeaf * node = NLGUI::CDBManager::getInstance()->getDbProp(sDBPath, false); - if(node) - { - ICDBNode::CTextId textId; - node->addObserver(fameObs, textId); - } - _FamesObs.push_back(fameObs); - } - } - - // Add an observer on Mission Journal - CNPCIconCache::getInstance().addObservers(); - - // Initialize the camera distance. - View.cameraDistance(ClientCfg.CameraDistance); - - // char and account time properties - CSkillManager *pSM = CSkillManager::getInstance(); - if( pSM ) - { - pSM->tryToUnblockTitleFromCharOldness( CharFirstConnectedTime ); - pSM->tryToUnblockTitleFromCharPlayedTime( CharPlayedTime ); - } - - // Entity created. - return true; -}// build // - - -//----------------------------------------------- -// eyesHeight : -// \todo GUIGUI : do it better in mount mode -//----------------------------------------------- -float CUserEntity::eyesHeight() -{ - if(!_OnMount) - return _EyesHeight * _CharacterScalePos; - else - return _EyesHeight * _CharacterScalePos; -}// eyesHeight // - - -///////////////////////////////////////////////// -///////////////////////////////////////////////// -/////////////// VISUAL PROPERTIES /////////////// -///////////////////////////////////////////////// -///////////////////////////////////////////////// -//----------------------------------------------- -// updateVisualPropertyPos : -// Update Entity Position. -//----------------------------------------------- -void CUserEntity::updateVisualPropertyPos(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &/* prop */, const NLMISC::TGameCycle &/* pI */) -{ -}// updateVisualPropertyPos // - -//----------------------------------------------- -// updateVisualPropertyOrient : -// Update Entity Orientation. -//----------------------------------------------- -void CUserEntity::updateVisualPropertyOrient(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &/* prop */) -{ -}// updateVisualPropertyOrient // - - -void CUserEntity::updateVisualPropertyTargetList(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &/* prop */, uint /* listIndex */) -{ -} - -void CUserEntity::updateVisualPropertyVisualFX(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &prop) -{ - applyVisualFX(prop); -} - -//----------------------------------------------- -// updateVisualPropertyBehaviour : -// Update Entity Behaviour. -//----------------------------------------------- -void CUserEntity::updateVisualPropertyBehaviour(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &prop) -{ - // Compute the behaviour. - CBehaviourContext bc; - bc.Behav = MBEHAV::CBehaviour(prop); - bc.BehavTime = TimeInSec; - if(VerboseAnimUser) - { - nlinfo("UE::updateVPBeha: '%d(%s)'.", (sint)bc.Behav.Behaviour, MBEHAV::behaviourToString(bc.Behav.Behaviour).c_str()); - } - CCDBNodeLeaf *targetList0 = dynamic_cast(_DBEntry->getNode(CLFECOMMON::PROPERTY_TARGET_LIST_0)); - CCDBNodeLeaf *targetList1 = dynamic_cast(_DBEntry->getNode(CLFECOMMON::PROPERTY_TARGET_LIST_1)); - CCDBNodeLeaf *targetList2 = dynamic_cast(_DBEntry->getNode(CLFECOMMON::PROPERTY_TARGET_LIST_1)); - CCDBNodeLeaf *targetList3 = dynamic_cast(_DBEntry->getNode(CLFECOMMON::PROPERTY_TARGET_LIST_1)); - if (targetList0 && targetList1 && targetList2 && targetList3) - { - uint64 vp[4] = - { - (uint64) targetList0->getValue64(), - (uint64) targetList1->getValue64(), - (uint64) targetList2->getValue64(), - (uint64) targetList3->getValue64() - }; - bc.Targets.unpack(vp, 4); - } - applyBehaviour(bc); -}// updateVisualPropertyBehaviour // - -//----------------------------------------------- -// updateVisualPropertyName : -// Update Entity Name. -//----------------------------------------------- -void CUserEntity::updateVisualPropertyName(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - uint32 oldNameId = _NameId; - - CPlayerCL::updateVisualPropertyName(gameCycle, prop); - - // Name changed ? -/* if (oldNameId != _NameId) - { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CInterfaceElement *element = CWidgetManager::getInstance()->getElementFromId("ui:interface:mailbox:content:html"); - if (element) - { - CGroupHTML *html = dynamic_cast(element); - if (html) - html->browse("home"); - } - } -*/ -}// updateVisualPropertyName // - -//----------------------------------------------- -// updateVisualPropertyTarget : -// Update Entity Target. -//----------------------------------------------- -void CUserEntity::updateVisualPropertyTarget(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &/* prop */) -{ - // Don't override the Player Target, cause client side entirely => no lag. - //targetSlot((CLFECOMMON::TCLEntityId)prop); -}// updateVisualPropertyTarget // - -//----------------------------------------------- -// updateVisualPropertyMode : -// New mode received -> immediately change the mode for the user. -// \warning Read the position or orientation from the database when reading the mode (no more updated in updateVisualPropertyPos and updateVisualPropertyOrient). -//----------------------------------------------- -void CUserEntity::updateVisualPropertyMode(const NLMISC::TGameCycle &/* gameCycle */, const sint64 &prop) -{ - // Combat Float Check - if((MBEHAV::EMode)prop == MBEHAV::COMBAT_FLOAT) - { - nlwarning("UE:updateVPMode: the user should never have the COMBAT_FLOAT mode."); - return; - } - // New Mode Received. - _TheoreticalMode = (MBEHAV::EMode)prop; - // Change the user mode. - mode(_TheoreticalMode); -}// updateVisualPropertyMode // - -//----------------------------------------------- -// updateVisualPropertyVpa : -// Update Entity Visual Property A -//----------------------------------------------- -void CUserEntity::updateVisualPropertyVpa(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - CPlayerCL::updateVisualPropertyVpa(gameCycle, prop); - - // Special for user: Disable Character Lod, because always want it at full rez. - if(!_Skeleton.empty()) - { - _Skeleton.setLodCharacterShape(-1); - } - - updateVisualDisplay(); -}// updateVisualPropertyVpa // - -//----------------------------------------------- -// updateVisualPropertyVpb : -// Update Entity Visual Property B -//----------------------------------------------- -void CUserEntity::updateVisualPropertyVpb(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - CPlayerCL::updateVisualPropertyVpb(gameCycle, prop); - updateVisualDisplay(); -}// updateVisualPropertyVpb // - -//----------------------------------------------- -// updateVisualPropertyVpc : -// Update Entity Visual Property C -//----------------------------------------------- -void CUserEntity::updateVisualPropertyVpc(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - CPlayerCL::updateVisualPropertyVpc(gameCycle, prop); - updateVisualDisplay(); -}// updateVisualPropertyVpc // - -//----------------------------------------------- -// updateVisualPropertyEntityMounted : -// Update Entity Mount -//----------------------------------------------- -void CUserEntity::updateVisualPropertyEntityMounted(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - if(isFighting()) - CPlayerCL::updateVisualPropertyEntityMounted(gameCycle, prop); - else - _Mount = (CLFECOMMON::TCLEntityId)prop; -}// updateVisualPropertyEntityMounted // - -//----------------------------------------------- -// updateVisualPropertyRiderEntity : -// Update Entity Rider -//----------------------------------------------- -void CUserEntity::updateVisualPropertyRiderEntity(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - if(isFighting()) - CPlayerCL::updateVisualPropertyRiderEntity(gameCycle, prop); - else - _Rider = (CLFECOMMON::TCLEntityId)prop; -}// updateVisualPropertyRiderEntity // - -//----------------------------------------------- -//----------------------------------------------- -void CUserEntity::updateVisualPropertyPvpMode(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - CPlayerCL::updateVisualPropertyPvpMode(gameCycle, prop); - // Additionaly, inform interface of the change - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - // For PVP ZoneFaction - CCDBNodeLeaf *pDB= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:TRACK_PVP_CHANGE_MODE"); - if(pDB) - { - sint32 val= pDB->getValue32(); - pDB->setValue32(val+1); - } - // For Any PVP change - pDB= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:TRACK_PVP_CHANGE_ANY"); - if(pDB) - { - sint32 val= pDB->getValue32(); - pDB->setValue32(val+1); - } -} - -//----------------------------------------------- -//----------------------------------------------- -void CUserEntity::updateVisualPropertyOutpostInfos(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - CPlayerCL::updateVisualPropertyOutpostInfos(gameCycle, prop); - // For Any PVP change - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - CCDBNodeLeaf *pDB= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:TRACK_PVP_CHANGE_ANY"); - if(pDB) - { - sint32 val= pDB->getValue32(); - pDB->setValue32(val+1); - } -} - -//----------------------------------------------- -//----------------------------------------------- -void CUserEntity::updateVisualPropertyPvpClan(const NLMISC::TGameCycle &gameCycle, const sint64 &prop) -{ - CPlayerCL::updateVisualPropertyPvpClan(gameCycle, prop); - // For Any PVP change - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - CCDBNodeLeaf *pDB= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:USER:TRACK_PVP_CHANGE_ANY"); - if(pDB) - { - sint32 val= pDB->getValue32(); - pDB->setValue32(val+1); - } -} - - -///////////////////////////////////////////////// -///////////////////////////////////////////////// -///////////////////////////////////////////////// -///////////////////////////////////////////////// - - -//----------------------------------------------- -// mode : -// Method called to change the mode (Combat/Mount/etc.). -// \todo GUIGUI : apply stage in combat modes instead of just removing them. -// \todo GUIGUI : go or teleport the player to the mode position (see how to manage it). -//----------------------------------------------- -bool CUserEntity::mode(MBEHAV::EMode m) -{ - if(Verbose & VerboseAnim) - nlinfo("UE::mode: old mode '%s(%d)' new mode '%s(%d)'.", MBEHAV::modeToString(_Mode).c_str(), _Mode, MBEHAV::modeToString(m).c_str(), m); - // Nothing to do if the mode is the same as the previous one. - if(m == _Mode) - return true; - // Release the old Mode. - switch(_Mode) - { - // Leave COMBAT Mode - case MBEHAV::COMBAT: - case MBEHAV::COMBAT_FLOAT: - { - // If there are some stage not complete -> remove them - if(_Stages._StageSet.size() != 0) - _Stages._StageSet.clear(); - } - break; - // Leave MOUNTED Mode - case MBEHAV::MOUNT_NORMAL: - case MBEHAV::MOUNT_SWIM: - { - if ( m == MBEHAV::REST ) - { - // can't go afk while mounting - return false; - } - - // if changing mode for another mount mode, do nothing - if (m != MBEHAV::MOUNT_NORMAL && m != MBEHAV::MOUNT_SWIM) - { - // Display the mount again. - CCharacterCL *mount = dynamic_cast(EntitiesMngr.entity(_Mount)); - if(mount) - { - // Set the mount. - mount->rider(CLFECOMMON::INVALID_SLOT); - mount->_Stages._StageSet.clear(); - mount->setMode(MBEHAV::NORMAL); - mount->computeAutomaton(); - mount->computeAnimSet(); - mount->setAnim(CAnimationStateSheet::Idle); - if(mount->getPrimitive()) - mount->getPrimitive()->setOcclusionMask(MaskColNpc); // the mount is an npc - mount->_ForbidClipping = false; - } - // - _Mount = CLFECOMMON::INVALID_SLOT; - // Restore the user Primitive - if(_Primitive) - { - _Primitive->setRadius( std::min(0.5f, (float)(RYZOM_ENTITY_SIZE_MAX/2)) ); - _Primitive->setHeight(2); - } - _OnMount = false; - - // Shift the player position (not to stand inside the mount) - CVectorD unmountShift; - unmountShift.sphericToCartesian(1.0, frontYaw() + NLMISC::Pi/2, 0); - pacsPos(pos() + unmountShift); - - // Restore running if necessary - if (!_Run && _RunWhenAble) - { - switchVelocity(); - } - } - - if (_Mode == MBEHAV::MOUNT_SWIM && ( m == MBEHAV::COMBAT || m == MBEHAV::COMBAT_FLOAT)) - { - //TODO : display "you can't fight while swimming" - return true; - } - } - break; - // Leave DEATH Mode - case MBEHAV::DEATH: - // Restore the last view. - viewMode(viewMode()); - break; - case MBEHAV::SWIM: - if( m == MBEHAV::COMBAT || m == MBEHAV::COMBAT_FLOAT) - { - //TODO : display "you can't fight while swimming" - return true; - } - break; - default: - nlwarning("Invalid behaviour change."); - } - - // Reset Parent, unless we stay in mount mode - if ((_Mode != MBEHAV::MOUNT_SWIM && _Mode != MBEHAV::MOUNT_NORMAL) - || (m != MBEHAV::MOUNT_SWIM && m != MBEHAV::MOUNT_NORMAL) - ) - { - parent(CLFECOMMON::INVALID_SLOT); - } - - // Change the Mode for the user ( if user sits down or stands up we wait in order to play the sit/stand transition anim) - if( m != MBEHAV::SIT && _Mode != MBEHAV::SIT ) - _Mode = m; - _ModeWanted = m; - - // Initialize the new Mode. - switch(m) - { - // Combat mode - case MBEHAV::COMBAT: - case MBEHAV::COMBAT_FLOAT: - { - C64BitsParts rot; - - // Compute the angle - const string propName = toString("SERVER:Entities:E%d:P%d", _Slot, CLFECOMMON::PROPERTY_ORIENTATION); - rot.i64[0] = NLGUI::CDBManager::getInstance()->getDbProp(propName)->getValue64(); - _TargetAngle = rot.f[0]; - - // Initialize controls for the combat. - UserControls.startCombat(); - - // Context help - contextHelp ("action_bar"); - } - break; - - // Mount Normal or mount swim - case MBEHAV::MOUNT_NORMAL: - { - CCharacterCL *mount = dynamic_cast(EntitiesMngr.entity(parent())); - if(mount) - { - mount->_Stages.removePosWithNoMode(); - dir(mount->dir()); - } - } - case MBEHAV::MOUNT_SWIM: - { - // Hide the mount unless we come from another mounted mode - if (_Mode != MBEHAV::MOUNT_SWIM && _Mode != MBEHAV::MOUNT_NORMAL) - { - if(_Mount != CLFECOMMON::INVALID_SLOT) // if _Mount is still invalid, the following code will be done in updatePos() - { - setOnMount(); - } - } - // refresh target - UserEntity->selection(_Selection); - } - break; - - // Dead mode. - case MBEHAV::DEATH: - setDead(); - if(isSwimming()) - _Mode = MBEHAV::SWIM_DEATH; - break; - - // Normal or Default mode. - case MBEHAV::NORMAL: - _CurrentBehaviour.Behaviour = MBEHAV::IDLE; - default: - // - setAlive(); - viewMode(viewMode()); - break; - } - - bool doSetAnim = true; - // if user sits down or stands up we set transition anim before changing animset - if( m == MBEHAV::SIT ) - { - setAnim(CAnimationStateSheet::SitMode); - _Mode = m; - doSetAnim = false; - } - else - if( _Mode == MBEHAV::SIT && m!=MBEHAV::DEATH ) - { - setAnim(CAnimationStateSheet::SitEnd); - _Mode = m; - doSetAnim = false; - } - - // Show/Hide all or parts of the body. - updateVisualDisplay(); - if( ClientCfg.AutomaticCamera ) - { - // Set the direction as the front. - dir(front()); - } - // Compute the current automaton - computeAutomaton(); - // Update the animation set according to the mode. - computeAnimSet(); - - if( doSetAnim ) - { - // Animset changed -> update current animation - setAnim(CAnimationStateSheet::Idle); - } - - // Changing the mode well done. - return true; -}// mode // - - -/* - * Mount the mount in _Mount - */ -void CUserEntity::setOnMount() -{ - CCharacterCL *mount = dynamic_cast(EntitiesMngr.entity(_Mount)); - if(mount) - { - // Update primitives for the mount and the rider. - if(_Primitive && mount->getPrimitive()) - { - _Primitive->setRadius( std::min(mount->getPrimitive()->getRadius(), (float)(RYZOM_ENTITY_SIZE_MAX/2)) ); - _Primitive->setHeight(mount->getPrimitive()->getHeight()); - mount->getPrimitive()->setOcclusionMask(MaskColNone); // Remove collisions. - } - // Now on a mount - _OnMount = true; - // Link the mount and the user. - parent(_Mount); - // Refresh the View Mode - viewMode(viewMode()); - // Close the crafting window if open - closeFaberCastWindow(); - - // Keep run in mind - _RunWhenAble = _Run; - - mount->_ForbidClipping = true; - } -} - - - -//----------------------------------------------- -// getVelocity : -// compute and return the entity velocity -//----------------------------------------------- -CVector CUserEntity::getVelocity() const -{ - static const CVector lateral(0,0,1); - static CVector velocity; - velocity = front() * _FrontVelocity + ( lateral ^ front()) * _LateralVelocity; - velocity.normalize(); - // User is Dead - if(isDead()) - { - velocity *= 0.0; - } - // User is sitting - else if(isSit()) - { - velocity *= 0.0; - } - // User is swimming - else if(isSwimming()) - { - // We are a Ring DM so speed up a litle - - - // Forward Run or Walk - if(_FrontVelocity > 0.0f) - { - if(_Run) - velocity *= 3.0; - else - velocity *= 1.0; - } - // Lateral or Backward Walk - else - velocity *= 1.0; - - if (_R2CharMode == R2::TCharMode::Editer || _R2CharMode == R2::TCharMode::Dm) - { - velocity *= (float(ClientCfg.DmRun) / 6.0f); // velocity max = max run / 2 - } - - } - else if(isRiding()) - { - // Forward Run or Walk - if(_FrontVelocity > 0.0f) - { - if(_Run) - velocity *= getMountRunVelocity(); - else - velocity *= getMountWalkVelocity(); - } - // Lateral or Backward Walk (currently, not used) - else - velocity *= 0.66f;//getMountWalkVelocity(); - } - else - { - // Forward Run or Walk - if(_FrontVelocity > 0.0f) - velocity *= currentVelocity(); - // Lateral or Backward Walk - else - velocity *= _WalkVelocity; - } - return velocity; -}// getVelocity // - -//----------------------------------------------- -// speed : -// Return the Entity Current Speed. -//----------------------------------------------- -double CUserEntity::speed() const // virtual -{ - return CPlayerCL::speed(); -// return (double)getVelocity().norm(); -}// speed // - -//----------------------------------------------- -// applyMotion : -// Apply the motion to the entity. -//----------------------------------------------- -void CUserEntity::applyMotion(CEntityCL *target) -{ - // default each frame - _ForceLookSlot= CLFECOMMON::INVALID_SLOT; - - bool lastHasMoved = _HasMoved; - _HasMoved = false; - // Remove Positions in stages - _Stages.removePosWithNoMode(); - // Remove Positions in stages for the mount. - CCharacterCL *mount = 0; - if(parent() != CLFECOMMON::INVALID_SLOT) - { - mount = dynamic_cast(EntitiesMngr.entity(parent())); - if(mount) - mount->_Stages.removePosWithNoMode(); - } - // NO PRIMITIVE -> NO MOVE - if(_Primitive == 0) - return; - // BAD CONNECTION -> NO MOVE - if(NetMngr.getConnectionQuality() == false) - return; - // MS per TICK <=0 -> NO MOVE - if(NetMngr.getMsPerTick() <= 0) - return; - // Compute Speed Vector - NLMISC::CVectorD speed; - if(_MoveToSlot != CLFECOMMON::INVALID_SLOT) - { - // Check the Target. - if(target == 0 || target == this) - return; - // Compute the vector between the user and the target. - CVectorD dir2targ = target->pos() - pos(); - dir2targ.z = 0.0; - if(dir2targ == CVectorD::Null) - dir2targ = front(); - const double angToTarget = atan2(dir2targ.y, dir2targ.x); - CVectorD aimingPos = target->getAttackerPos(angToTarget, attackRadius() + ClientCfg.AttackDist); - // Aiming Position - CVectorD dirToAimingPos = aimingPos-pos(); - dirToAimingPos.z = 0.0; - const double distToAimingPos = dirToAimingPos.norm(); - - // Decide if the target is reached or not - bool targetReached= false; - if(distToAimingPos > 0.5) - { - // Because of Tryker Counter, may increase the Threshold, when the player is stalled - if(distToAimingPos<_MoveToDist) - { - // If the player is stalled too much time, abort the move and launch the action - float actualSpeed= float((_Position - _LastFramePos).norm() / DT); - - // if player effectively runs twice slower, start colision timer - if( actualSpeed*2 < getMaxSpeed() ) - { - if(!_MoveToColStartTime) - _MoveToColStartTime= T1; - } - // else ok, reset colision timer - else - _MoveToColStartTime= 0; - - // if too much time stalled, stop run. - if(_MoveToColStartTime && (T1 - _MoveToColStartTime >= ClientCfg.MoveToTimeToStopStall) ) - targetReached= true; - } - else - _MoveToColStartTime= 0; - } - else - targetReached= true; - - // If the target is reached - if(targetReached) - { - // stop and execute action - speed = CVectorD::Null; - moveToAction(target); - } - // else continue follow - else - { - // Look at the entity. delay it after pacs evalCollision(), for correct orientation - _ForceLookSlot= target->slot(); - // but still estimate now an approximative front (may be used between now and applyForceLook()) - forceLookEntity(dir2targ, false); - - // Normalize - dirToAimingPos.normalize(); - // Set the Velocity Direction - speed = dirToAimingPos*distToAimingPos; - speed /= DT; - if(speed.norm() > getMaxSpeed()) - speed = dirToAimingPos*getMaxSpeed(); - } - } - else if(follow()) - { - // Check the Target. - if(target == 0 || target == this) - return; - // If the target is moving, orientate the user to the target. -// if(target->hasMoved()) - { - // Compute the vector between the user and the target. - CVectorD dir2targ = target->pos() - pos(); - dir2targ.z = 0.0; - if(dir2targ != CVectorD::Null) - { - // Look at the entity. delay it after pacs evalCollision(), for correct orientation - _ForceLookSlot= target->slot(); - // but still estimate now an approximative front (may be used between now and applyForceLook()) - forceLookEntity(dir2targ, false); - } - } - // Compute the angle in the world to attack the target. - const double angToTarget = frontYaw(); - // Get the best position to attack the target with the given angle. - const CVectorD aimingPos = target->getAttackerPos(angToTarget, attackRadius() + ClientCfg.AttackDist); - // Aiming Position - CVectorD dirToAimingPos = aimingPos-pos(); - dirToAimingPos.z = 0.0; - const double distToAimingPos = dirToAimingPos.norm(); - // If the User was not moving and the distance to re-move is not enough big, stay idle - if(lastHasMoved - || (isFighting() && distToAimingPos >= 0.5) - || (!isFighting() && distToAimingPos >= 3.0)) - { - dirToAimingPos.normalize(); - // User is in combat mode -> follow as close as possible. - if(isFighting()) - { - // Target is moving - if(target->hasMoved()) - { - // Get closer if too far. - if(distToAimingPos >= 0.2) - { - // Set the Velocity Direction - speed = dirToAimingPos*distToAimingPos; - speed /= DT; - if(speed.norm() > getMaxSpeed()) - speed = dirToAimingPos*getMaxSpeed(); - } - else - { - // Try to have the same speed as the target. - if(target->getSpeed() > getMaxSpeed()) - speed = target->dir()* ((float)getMaxSpeed()); - else - speed = target->dir()* ((float)target->getSpeed()); - } - } - // Target is not moving. - else - { - // Get closer if too far. - if(distToAimingPos >= 0.1) - { - // Set the Velocity Direction - speed = dirToAimingPos*distToAimingPos; - speed /= DT; - if(speed.norm() > getMaxSpeed()) - speed = dirToAimingPos*getMaxSpeed(); - } - else - speed = CVectorD::Null; - } - } - // User is not in combat mode -> follow not so close. - else - { - // Too far, get closer as fast as possible - if(distToAimingPos >= 3.0) - { - // Set the Velocity Direction - speed = dirToAimingPos*distToAimingPos; - speed /= DT; - if(speed.norm() > getMaxSpeed()) - speed = dirToAimingPos*getMaxSpeed(); - } - // Just far enough, adjust the user speed to the target - else if(target->hasMoved() && distToAimingPos >= 1.0) - { - // Try to have the same speed as the target. - if(target->getSpeed() > getMaxSpeed()) - speed = target->dir()* ((float)getMaxSpeed()); - else - speed = target->dir()* ((float)target->getSpeed()); - } - // Too close, Stop - else - speed = CVectorD::Null; - } - } - // User was stop and the next pos is to close to begin to move. - else - speed = CVectorD::Null; - } - else - { - speed = getVelocity()*_SpeedFactor.getValue(); - _SpeedFactor.addFactorValue(0.005f); - } - - // SPEED VECTOR NULL -> NO MOVE - if(speed == CVectorD::Null) - return; - - // First Person View - if(UserControls.isInternalView()) - { - // If the server is slow, the client move slower too (only needed in FPV). - double modif = (100.0f/(float)NetMngr.getMsPerTick()); - // don't increase speed - clamp(modif, 0.0, 1.0); - speed *= modif; - // Move - _HasMoved = true; - _Primitive->move(speed, dynamicWI); - if(mount && mount->getPrimitive()) - mount->getPrimitive()->move(speed, dynamicWI); - } - // Third Person View - else - { - double modif = (100.0f/(float)NetMngr.getMsPerTick()); - clamp(modif, 0.0, 1.0); - speed *= modif; - speed += pos(); - sint64 x = (sint64)((sint32)(speed.x * 1000.0)); - sint64 y = (sint64)((sint32)(speed.y * 1000.0)); - sint64 z = (sint64)((sint32)(speed.z * 1000.0)); - const uint time = 10; // = 1sec because the speed is in Meter per Sec. - _Stages.addStage(NetMngr.getCurrentClientTick()+time, CLFECOMMON::PROPERTY_POSX, x, 0); - _Stages.addStage(NetMngr.getCurrentClientTick()+time, CLFECOMMON::PROPERTY_POSY, y); - _Stages.addStage(NetMngr.getCurrentClientTick()+time, CLFECOMMON::PROPERTY_POSZ, z); - // Move the Mount - if(mount) - { - mount->_Stages.addStage(NetMngr.getCurrentClientTick()+time, CLFECOMMON::PROPERTY_POSX, x, 0); - mount->_Stages.addStage(NetMngr.getCurrentClientTick()+time, CLFECOMMON::PROPERTY_POSY, y); - mount->_Stages.addStage(NetMngr.getCurrentClientTick()+time, CLFECOMMON::PROPERTY_POSZ, z); - } - } - - -}// applyMotion // - - -//--------------------------------------------------- -//--------------------------------------------------- -void CUserEntity::applyForceLook() -{ - if(_ForceLookSlot!=CLFECOMMON::INVALID_SLOT) - { - CEntityCL *target= EntitiesMngr.entity(_ForceLookSlot); - if(target && target!=this) - { - // Compute the vector between the user and the target. - CVectorD dir2targ = target->pos() - pos(); - dir2targ.z = 0.0; - if(dir2targ == CVectorD::Null) - dir2targ = front(); - // Look at the entity - forceLookEntity(dir2targ, true); - } - } -} - - -//--------------------------------------------------- -// updatePosCombatFloatChanged : -//--------------------------------------------------- -void CUserEntity::updatePosCombatFloatChanged(CEntityCL * /* target */) // virtual -{ - if(viewMode() == FirstPV) - { - pos(_FirstPos); - } -}// updatePosCombatFloatChanged // - - -//----------------------------------------------- -// forceIndoorFPV // -// Return true if the user is indoor and the CFG want to force the FPV Indoor. -//----------------------------------------------- -bool CUserEntity::forceIndoorFPV() -{ - return (ClientCfg.ForceIndoorFPV && indoor()); -}// forceIndoorFPV // - - -//----------------------------------------------- -// enableFollow : -//----------------------------------------------- -void CUserEntity::disableFollow() -{ - if (_FollowMode==false) - return; - - _FollowMode = false; - - // Send the message to the server. - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream("TARGET:NO_FOLLOW", out)) - NetMngr.push(out); - else - nlwarning("UE:follow: unknown message named 'TARGET:NO_FOLLOW'."); - -}// follow // - - -//----------------------------------------------- -// enableFollow : -//----------------------------------------------- -void CUserEntity::enableFollow(bool resetCameraRot) -{ - if (_FollowMode == true) - return; - - if( _Mode == MBEHAV::DEATH ) - return; - - _FollowMode = true; - - // Send the message to the server. - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream("TARGET:FOLLOW", out)) - NetMngr.push(out); - else - nlwarning("UE:follow: unknown message named 'TARGET:FOLLOW'."); - - // Disable any autowalk (else when follow re-disabled, it will effect, which is weird) - UserControls.autowalkState(false); - - // disable afk mode - setAFK(false); - - // if want to reset camera rotation - if(resetCameraRot) - startForceLookEntity(targetSlot()); - -}// follow // - - -//----------------------------------------------- -// resetAnyMoveTo -//----------------------------------------------- -void CUserEntity::resetAnyMoveTo() -{ - // if we cancel a MoveToPhrase action, MUST dec the action counter, and hide the Action Icon - if(_MoveToAction==CUserEntity::CombatPhrase || _MoveToAction==CUserEntity::ExtractRM) - { - // the clientExecute has not been called in case of "ExtractRM autoFind" - bool autoFindExtractRM= _MoveToAction==CUserEntity::ExtractRM && _MoveToPhraseMemoryLine == std::numeric_limits::max(); - if(!autoFindExtractRM) - { - CSPhraseManager *pPM= CSPhraseManager::getInstance(); - pPM->cancelClientExecute(_MoveToPhraseCyclic); - } - } - - // reset to no moveTo - _MoveToSlot = CLFECOMMON::INVALID_SLOT; - _MoveToAction = CUserEntity::None; - _MoveToDist = 0.0; - _MoveToColStartTime= 0; -} - -//----------------------------------------------- -// moveToCheckStartDist : -// Check if the user is not already well placed. -//----------------------------------------------- -void CUserEntity::moveToCheckStartDist(CLFECOMMON::TCLEntityId slot, double dist, TMoveToAction /* action */) -{ - if(_MoveToSlot != CLFECOMMON::INVALID_SLOT) - { - // Start a new Force Look entity - startForceLookEntity(_MoveToSlot); - - // Disable any autowalk (else when moveTo re-disabled, it will effect, which is weird) - UserControls.autowalkState(false); - - // disable afk mode - setAFK(false); - - // if sufficiently near, launch the action - CEntityCL *target = EntitiesMngr.entity(slot); - if(target) - { - CVectorD dir2targ = target->pos() - pos(); - dir2targ.z = 0.0; - if((dir2targ==CVectorD::Null) || (dir2targ.norm() < dist)) - { - moveToAction(target); - } - } - } -}// moveToCheckStartDist // - -//----------------------------------------------- -// moveTo : -// Method to move to someone else. -//----------------------------------------------- -void CUserEntity::moveTo(CLFECOMMON::TCLEntityId slot, double dist, TMoveToAction action) -{ - resetAnyMoveTo(); - - // setup new state - _MoveToSlot = slot; - _MoveToDist = dist; - _MoveToAction = action; - - moveToCheckStartDist(_MoveToSlot, _MoveToDist, _MoveToAction); -}// moveTo // - -//----------------------------------------------- -// moveToMission : -// Method to move to someone else for a mission. NB: if prec action was a CombatPhrase action, action counter are decremented -//----------------------------------------------- -void CUserEntity::moveToMission(CLFECOMMON::TCLEntityId slot, double dist, uint32 id) -{ - resetAnyMoveTo(); - - // setup new state - _MoveToSlot = slot; - _MoveToDist = dist; - _MoveToAction = CUserEntity::Mission; - _MoveToMissionId = id; - - moveToCheckStartDist(_MoveToSlot, _MoveToDist, _MoveToAction); -}// moveToMission // - -//----------------------------------------------- -// moveToMissionRing : -// Method to move to someone else for a ring mission. NB: if prec action was a CombatPhrase action, action counter are decremented -//----------------------------------------------- -void CUserEntity::moveToMissionRing(CLFECOMMON::TCLEntityId slot, double dist, uint32 id) -{ - resetAnyMoveTo(); - - // setup new state - _MoveToSlot = slot; - _MoveToDist = dist; - _MoveToAction = CUserEntity::MissionRing; - _MoveToMissionId = id; - - moveToCheckStartDist(_MoveToSlot, _MoveToDist, _MoveToAction); -}// moveToMissionRing // - -//----------------------------------------------- -// moveTo : -// Method to move to someone else. -//----------------------------------------------- -void CUserEntity::moveToCombatPhrase(CLFECOMMON::TCLEntityId slot, double dist, uint phraseMemoryLine, uint phraseMemorySlot, bool phraseCyclic) -{ - resetAnyMoveTo(); - - // setup new state - _MoveToSlot = slot; - _MoveToDist = dist; - _MoveToAction = CUserEntity::CombatPhrase; - _MoveToPhraseMemoryLine= phraseMemoryLine; - _MoveToPhraseMemorySlot= phraseMemorySlot; - _MoveToPhraseCyclic= phraseCyclic; - - moveToCheckStartDist(_MoveToSlot, _MoveToDist, _MoveToAction); -} - -//----------------------------------------------- -// Method to move to someone else, for foraging extraction -// The caller MUST call after CSPhraseManager::clientExecute(), to increment action counter -//----------------------------------------------- -void CUserEntity::moveToExtractionPhrase(CLFECOMMON::TCLEntityId slot, double dist, uint phraseMemoryLine, uint phraseMemorySlot, bool cyclic) -{ - // Test if forage tool in hand, otherwise auto-equip with it - bool validForageToolInHand = false; - CInventoryManager * inv = CInventoryManager::getInstance(); - if ( !inv ) - { - return; - } - uint32 rightHandSheet = inv->getRightHandItemSheet(); - if ( rightHandSheet ) - { - validForageToolInHand = inv->isForageToolItem( rightHandSheet ); - } - if ( !validForageToolInHand ) - { - // Find a forage tool in the bag - uint i; - for ( i=0; igetBagItem(i).getSheetID(); - if ( itemSheet && inv->isForageToolItem(itemSheet) ) - { - break; - } - } - if ( i != MAX_BAGINV_ENTRIES && ClientCfg.AutoEquipTool ) - { - // remember last used weapon(s) - rememberWeaponsInHand(); - - // Clear hands - inv->unequip( "LOCAL:INVENTORY:HAND:1" ); - inv->unequip( "LOCAL:INVENTORY:HAND:0" ); - - // Equip hands - string bagPath = toString( "LOCAL:INVENTORY:BAG:%u", i ); - inv->equip( bagPath, "LOCAL:INVENTORY:HAND:0" ); - } - else - { - // No forage tool in bag - CInterfaceManager::getInstance()->displaySystemInfo( CI18N::get("uiForageToolMissing"), "CHK" ); - return; - } - } - - resetAnyMoveTo(); - - // setup new state - _MoveToSlot = slot; - _MoveToDist = dist; - _MoveToAction = CUserEntity::ExtractRM; - _MoveToPhraseMemoryLine= phraseMemoryLine; - _MoveToPhraseMemorySlot= phraseMemorySlot; - _MoveToPhraseCyclic= cyclic; - - moveToCheckStartDist(_MoveToSlot, _MoveToDist, _MoveToAction); -} - -//----------------------------------------------- -// Method to begin a spire construction -// The caller MUST call after CSPhraseManager::clientExecute(), to increment action counter -//----------------------------------------------- -void CUserEntity::moveToTotemBuildingPhrase(CLFECOMMON::TCLEntityId slot, double dist, uint phraseMemoryLine, uint phraseMemorySlot, bool cyclic) -{ - resetAnyMoveTo(); - - // setup new state - _MoveToSlot = slot; - _MoveToDist = dist; - _MoveToAction = CUserEntity::BuildTotem; - _MoveToPhraseMemoryLine= phraseMemoryLine; - _MoveToPhraseMemorySlot= phraseMemorySlot; - _MoveToPhraseCyclic= cyclic; - - moveToCheckStartDist(_MoveToSlot, _MoveToDist, _MoveToAction); -} - -//----------------------------------------------- -// moveToAction : -// Launch the Action Once the Move is done. -// \param CEntityCL * : pointer on the destination entity. -// \warning entity pointer must be valid(allocated). -//----------------------------------------------- -void CUserEntity::moveToAction(CEntityCL *ent) -{ - // Check entity pointer - nlassert(ent); - - UserControls.needReleaseForward(); - - // Get the interface instance. - CInterfaceManager *IM = CInterfaceManager::getInstance(); - switch(_MoveToAction) - { - // Attack - case CUserEntity::Attack: - UserEntity->attack(); - break; - // Quartering - case CUserEntity::Quarter: - if((ent->properties()).harvestable()) - CAHManager::getInstance()->runActionHandler("context_quartering", 0); - break; - // Loot - case CUserEntity::Loot: - if((ent->properties()).lootable()) - CAHManager::getInstance()->runActionHandler("context_loot", 0); - break; - // Pick Up - case CUserEntity::PickUp: - nlwarning("UE:checkMoveTo: not yet implemented"); - break; - case CUserEntity::ExtractRM: - extractRM(); - break; - // Trade Item - case CUserEntity::TradeItem: - CAHManager::getInstance()->runActionHandler("context_trade_item", 0); - break; - // Trade Phrase - case CUserEntity::TradePhrase: - CAHManager::getInstance()->runActionHandler("context_trade_phrase", 0); - break; - // Trade Pact - case CUserEntity::TradePact: - CAHManager::getInstance()->runActionHandler("context_trade_pact", 0); - break; - // Mission - case CUserEntity::Mission: - { - string param = toString("id=%d", _MoveToMissionId); - CAHManager::getInstance()->runActionHandler("mission_option", 0, param); - } - break; - // Dynamic Mission - case CUserEntity::DynamicMission: - CAHManager::getInstance()->runActionHandler("context_dynamic_mission", 0); - break; - // Static Mission - case CUserEntity::StaticMission: - CAHManager::getInstance()->runActionHandler("context_choose_mission", 0); - break; - // Mission - case CUserEntity::MissionRing: - { - string param = toString("id=%d", _MoveToMissionId); - CAHManager::getInstance()->runActionHandler("mission_ring", 0, param); - } - break; - // Create Guild - case CUserEntity::CreateGuild: - CAHManager::getInstance()->runActionHandler("context_create_guild", 0); - break; - // News - case CUserEntity::News: - CAHManager::getInstance()->runActionHandler("context_talk", 0); - break; - // Trade Teleport - case CUserEntity::TradeTeleport: - CAHManager::getInstance()->runActionHandler("context_trade_teleport", 0); - break; - // Trade Faction items - case CUserEntity::TradeFaction: - CAHManager::getInstance()->runActionHandler("context_trade_faction", 0); - break; - // Trade Cosmetic - case CUserEntity::TradeCosmetic: - CAHManager::getInstance()->runActionHandler("context_trade_cosmetic", 0); - break; - // Talk - case CUserEntity::Talk: - nlwarning("UE:checkMoveTo: not yet implemented"); - break; - // CombatPhrase - case CUserEntity::CombatPhrase: - UserEntity->attackWithPhrase(); - break; - // Mount - case CUserEntity::Mount: - { - string orderStr = "mount"; - string beastIndexStr = "@UI:GCM_BEAST_SELECTED"; - bool confirmFree = true; - beastOrder(orderStr,beastIndexStr,confirmFree); - break; - } - // WebPage - case CUserEntity::WebPage: - CAHManager::getInstance()->runActionHandler("context_web_page", 0); - break; - // Outpost - case CUserEntity::Outpost: - CLuaManager::getInstance().executeLuaScript("game:outpostBCOpenStateWindow()", 0); - break; - // BuildTotem - case CUserEntity::BuildTotem: - buildTotem(); - break; - // openArkUrl - case CUserEntity::OpenArkUrl: - CLuaManager::getInstance().executeLuaScript("getUI('ui:interface:web_transactions'):find('html'):browse(ArkTargetUrl)", 0); - break; - default: - break; - } - - // Move To Done. - resetAnyMoveTo(); -}// moveToAction // - - -//----------------------------------------------- -// sendToServer : -// Send the position and orientation to the server. -//----------------------------------------------- -bool CUserEntity::sendToServer(CBitMemStream &out) -{ - if(GenericMsgHeaderMngr.pushNameToStream("POSITION", out)) - { - // Backup the position sent. - if (_Primitive) _Primitive->getGlobalPosition(_LastGPosSent, dynamicWI); - // Send Position & Orientation - CPositionMsg positionMsg; - positionMsg.X = (sint32)(pos().x * 1000); - positionMsg.Y = (sint32)(pos().y * 1000); - positionMsg.Z = (sint32)(pos().z * 1000); - positionMsg.Heading = frontYaw(); - out.serial(positionMsg); - return true; - } - else - { - nlwarning("UE:sendToServer: unknown message named 'POSITION'."); - return false; - } -}// sendToServer // - -//----------------------------------------------- -// msgForCombatPos : -// Fill the msg to know if the user is well placed to fight. -//----------------------------------------------- -bool CUserEntity::msgForCombatPos(NLMISC::CBitMemStream &out) -{ - static bool wellPosition = false; - bool wellP = false; -// if(isFighting()) - { - // Is the user well Placed - CEntityCL *target = EntitiesMngr.entity(UserEntity->targetSlot()); - if(target) - wellP = target->isPlacedToFight(UserEntity->pos(), front(), attackRadius() + ClientCfg.AttackDist); - } - // If different from the last time - if(wellPosition != wellP) - { - wellPosition = wellP; - // Send state to server. - if(GenericMsgHeaderMngr.pushNameToStream("COMBAT:VALIDATE_MELEE", out)) - { - uint8 flag = wellP?1:0; - out.serial(flag); - return true; - } - else - nlwarning("UE:msgForCombatPos: unknown message named 'COMBAT:TOGGLE_COMBAT_FLOAT_MODE'."); - } - // Do not send the msg. - return false; -}// msgForCombatPos // - - -//----------------------------------------------- -// checkPos : -// Check the User Position according to the server code. -// \todo GUIGUI : put checks on GPos -// \todo GUIGUI : refact the check primitive when creating a PACS again -//----------------------------------------------- -void CUserEntity::checkPos() -{ - if(PACS && _Primitive) - { - // Is in water ? - if(GR) - { - UGlobalPosition gPos; - _Primitive->getGlobalPosition(gPos, dynamicWI); - float waterHeight; - if(GR->isWaterPosition(gPos, waterHeight)) - { - if(isSwimming() == false) - { - // Player is Dead set the right mode (swim and dead) - if(isDead()) - mode(MBEHAV::SWIM_DEATH); - else - { - // Do not swim when in combat mode. - if(isFighting()) - { - _HasMoved = false; - pacsPos(_LastPositionValidated, _LastGPosValidated); - } - // \todo GUIGUI : if the move was cancelled, do not switch to swimming mode. - else if (isRiding()) - { - mode(MBEHAV::MOUNT_SWIM); - // also change mounted entity mode - CCharacterCL *mount = dynamic_cast(EntitiesMngr.entity(_Mount)); - if(mount) - { - // Set the mount. - mount->setMode(MBEHAV::MOUNT_SWIM); - mount->computeAutomaton(); - mount->computeAnimSet(); - mount->setAnim(CAnimationStateSheet::Idle); - } - } - else - { - mode(MBEHAV::SWIM); - } - } - } - } - else - { - if(isSwimming()) - { - if(isDead()) - { - mode(MBEHAV::DEATH); - } - else if (isRiding()) - { - mode(MBEHAV::MOUNT_NORMAL); - // also change mounted entity mode - CCharacterCL *mount = dynamic_cast(EntitiesMngr.entity(_Mount)); - if(mount) - { - // Set the mount. - mount->setMode(MBEHAV::MOUNT_NORMAL); - mount->computeAutomaton(); - mount->computeAnimSet(); - mount->setAnim(CAnimationStateSheet::Idle); - } - } - else - { - mode(MBEHAV::NORMAL); - } - } - } - } - - // Create the Primitive used to check if the move will be accepted by the server - if(_CheckPrimitive == 0) - { - _Primitive->getGlobalPosition(_LastGPosSent, dynamicWI); - _Primitive->getGlobalPosition(_LastGPosValidated, dynamicWI); - _CheckPrimitive = PACS->addNonCollisionablePrimitive(_Primitive); - _CheckPrimitive->setOcclusionMask(MaskColNone); // Collide with nothing - _CheckPrimitive->setCollisionMask(MaskColNone); // Collide with nothing - _LastPositionValidated = pos(); - } - if(_CheckPrimitive) - { - _CheckPrimitive->setGlobalPosition(_LastGPosSent, dynamicWI); - CVectorD speed = _Primitive->getFinalPosition(dynamicWI) - _CheckPrimitive->getFinalPosition(dynamicWI); - - _CheckPrimitive->move(speed, dynamicWI); - if(PACS->evalNCPrimitiveCollision(1.0, _CheckPrimitive, dynamicWI) == false) - nlwarning("UE:checkPos: _CheckPrimitive is a collisionable primitive !!!"); - - CVectorD vectDist = _Primitive->getFinalPosition(dynamicWI) - _CheckPrimitive->getFinalPosition(dynamicWI); - if(vectDist.norm() > 0.001) - { - // The server will not be able to reproduce this move, restoring the last one. - _HasMoved = false; - pacsPos(_LastPositionValidated,_LastGPosValidated); - } - else - { - _LastPositionValidated = _Primitive->getFinalPosition(dynamicWI); - _Primitive->getGlobalPosition(_LastGPosValidated, dynamicWI); - } - } - } -}// checkPos // - - -//----------------------------------------------- -// testPacsPos : -// test the move from posToTest to current pos -//----------------------------------------------- -bool CUserEntity::testPacsPos( CVectorD& posToTest ) -{ - if(PACS && _Primitive && _CheckPrimitive) - { - _CheckPrimitive->setGlobalPosition(posToTest, dynamicWI); - CVectorD speed = _Primitive->getFinalPosition(dynamicWI) - _CheckPrimitive->getFinalPosition(dynamicWI); - - _CheckPrimitive->move(speed, dynamicWI); - if(PACS->evalNCPrimitiveCollision(1.0, _CheckPrimitive, dynamicWI) == false) - nlwarning("UE:testPacsPos: _CheckPrimitive is a collisionable primitive !!!"); - - CVectorD vectDist = _Primitive->getFinalPosition(dynamicWI) - _CheckPrimitive->getFinalPosition(dynamicWI); - if(vectDist.norm() > 0.001) - { - return false; - } - else - return true; - } - return false; - -} // testPacsPos // - - -//----------------------------------------------- -// tp : -// Teleport the player (remove selection, re-init checkPos, etc.). -//----------------------------------------------- -void CUserEntity::tp(const CVectorD &dest) -{ - // Remove the selection. - UserEntity->selection(CLFECOMMON::INVALID_SLOT); - // Update PACS - pacsPos(dest); - // Update the primitive useful to check the user position. - _LastPositionValidated = dest; - // Get the Global position - if(_Primitive) - { - // this is the last PACS position validated too - _Primitive->getGlobalPosition(_LastGPosValidated, dynamicWI); - // consider this is the last position sent to server (since actually received!) - _Primitive->getGlobalPosition(_LastGPosSent, dynamicWI); - // Set the new position of the 'check' primitive - if(_CheckPrimitive) - _CheckPrimitive->setGlobalPosition(_LastGPosSent, dynamicWI); - } - else - nlwarning("UE:tp: the entity has a Null primitive."); - // Return to interface mode. - viewMode(UserEntity->viewMode()); - // User well oriented. - dir(UserEntity->front()); - // Set Normal Mode after a teleport. - mode(MBEHAV::NORMAL); - // Set animation with idle. - setAnim(CAnimationStateSheet::Idle); -}// tp // - -//----------------------------------------------- -// correctPos : -// Teleport the player to correct his position. -//----------------------------------------------- -void CUserEntity::correctPos(const NLMISC::CVectorD &dest) -{ - nlinfo("UE:correctPos: new user position %f %f %f", dest.x, dest.y, dest.z); - // Change the user poisition. - UserEntity->pacsPos(dest); - // Update the primitive useful to check the user position. - _LastPositionValidated = dest; - // Get the Global position - if(_Primitive) - { - // this is the last PACS position validated too - _Primitive->getGlobalPosition(_LastGPosValidated, dynamicWI); - // consider this is the last position sent to server (since actually received!) - _Primitive->getGlobalPosition(_LastGPosSent, dynamicWI); - // Set the new position of the 'check' primitive - if(_CheckPrimitive) - _CheckPrimitive->setGlobalPosition(_LastGPosSent, dynamicWI); - } - else - nlwarning("UE:correctPos: the entity has a Null primitive."); - - // Correct the pos of the mount, if riding - if ( isRiding() ) - { - if ( _Mount < EntitiesMngr.entities().size() ) - { - CEntityCL *mount = EntitiesMngr.entities()[_Mount]; - if ( mount ) - mount->pacsPos( dest ); - } - } -}// correctPos // - - -/* - * Check if the mount is able to run, and force walking mode if not - * (if the player clicked on run, set back to walk). - */ -void CUserEntity::checkMountAbleToRun() -{ - if ( isRiding() ) - { - if ( running() ) - { - // Make the mount walk if she's hungry - if ( ! _MountHunger.canRun() ) - switchVelocity( false ); - } - else - { - // Make the mount run if she's not hungry anymore - if ( _RunWhenAble && _MountHunger.canRun() ) - switchVelocity( false ); - } - } -} - - -//----------------------------------------------- -// Update the position of the entity after the motion. -// \param t : Time for the position of the entity after the motion. -// \param target : pointer on the current target. -//----------------------------------------------- -void CUserEntity::updatePos(const TTime &t, CEntityCL *target) -{ - // Update Mount if mounting (if _Mount was still not valid when mode received) - if((_Mount != CLFECOMMON::INVALID_SLOT && isRiding()) && _OnMount==false) - { - setOnMount(); - } - // External view are managed like other entities. - if(!UserControls.isInternalView()) - { - // Update position according to the animations. - CPlayerCL::updatePos(t, target); - _LastFrameTime = t*0.001; - // Set The FPV when indoor. - if(forceIndoorFPV()) - viewMode(FirstPV, false); - return; - } - /* - else - { - // update anim state at least (needed when a spell is cast to play the cast fx at the right time, because they may be visible) - updateAnimationState(); - }*/ - - // Compute the Time Step. - double frameTimeRemaining = computeTimeStep(((double)t)*0.001); - // Do not update animation if Client Light - if (!ClientCfg.Light) - { - // Attack Animation. - if(_AnimAttackOn) - { - if(animIndex(MOVE) != ::CAnimation::UnknownAnim) - { - if(animOffset(MOVE) >= EAM->getAnimationLength(animId(MOVE))) - { - _AnimAttackOn = false; - updateVisualDisplay(); - } - } - } - - // Increase the time in the current animation. - double previousTimeOffset = animOffset(MOVE); - double offset = previousTimeOffset + frameTimeRemaining; - // Check Anim length - double animLength = EAM->getAnimationLength(animId(MOVE)); - if(offset > animLength) - animOffset(MOVE, animLength); - else - animOffset(MOVE, offset); - // Manage Events that could be created by the animation (like sound). - animEventsProcessing(previousTimeOffset, animOffset(MOVE)); - } - // Get the right pos from PACS. - if(_Primitive && GR) - { - UGlobalPosition gPos; - _Primitive->getGlobalPosition(gPos, dynamicWI); - - // Set the new current pos. - pos(GR->getGlobalPosition(gPos)); - } - // Set the direction. - if( ClientCfg.AutomaticCamera ) - { - //dir(front()); - } - // Reset the TPV when outdoor if needed. - if(_Primitive && GR) - { - UGlobalPosition gPos; - _Primitive->getGlobalPosition(gPos, dynamicWI); - if(!GR->isInterior(gPos)) - if(!ClientCfg.FPV) - viewMode(ThirdPV, false); - } - // Current time is now the entity time too. - _LastFrameTime = t*0.001; -}// updatePos // - -//----------------------------------------------- -// updateDisplay : -// Update the PACS position after the evalCollision. The entity position is set too. This is fast. -// If the entity position is too far from its PACS position, setGlobalPosition is called. -// After this call, the position.z is valid. -//----------------------------------------------- -void CUserEntity::pacsFinalizeMove() // virtual -{ - if(_Primitive == 0) - return; - - // Get the global position - _FinalPacsPos = _Primitive->getFinalPosition(dynamicWI); - - // Get the global position - UGlobalPosition gPos; - _Primitive->getGlobalPosition(gPos, dynamicWI); - if(gPos.InstanceId != -1) - { - pos(_FinalPacsPos); - if(_Mount != CLFECOMMON::INVALID_SLOT) - { - CEntityCL *mount = EntitiesMngr.entity(_Mount); - if(mount) - mount->pacsPos(pos()); - } - } - else - _SetGlobalPositionDone = false; -}// pacsFinalizeMove // - - -//----------------------------------------------- -// applyBehaviour : -// Apply the behaviour for the user. -//----------------------------------------------- -void CUserEntity::applyBehaviour(const CBehaviourContext &behaviourContext) // virtual -{ - const MBEHAV::CBehaviour &behaviour = behaviourContext.Behav; - // Special code for the First Person View - if((viewMode() == FirstPV) && behaviour.isCombat()) - { - // Backup the current behaviour. - _CurrentBehaviour = behaviourContext.Behav; - dir(front()); - - // check if self-target - bool selfSpell = false; - if (behaviourContext.Targets.Targets.size() == 1) - { - if (behaviourContext.Targets.Targets[0].TargetSlot == 0) - { - selfSpell = true; - } - } - bool isOffensif; - switch(behaviour.Behaviour) - { - case MBEHAV::CAST_OFF: - case MBEHAV::CAST_OFF_FAIL: - case MBEHAV::CAST_OFF_SUCCESS: - case MBEHAV::CAST_OFF_LINK: - isOffensif = true; - break; - default: - isOffensif = false; - break; - } - - // Default target hit dates - static vector targetHitDates; - targetHitDates.clear(); - targetHitDates.resize(behaviourContext.Targets.Targets.size(), TimeInSec); - - // cast projectiles/impact linked to behaviour - updateCurrentAttack(); - if (isCurrentBehaviourAttackEnd()) - { - // In First Person (don't care), use a default animation => will choose a default delay of 0.5 - performCurrentAttackEnd(behaviourContext, selfSpell && isOffensif, - targetHitDates, CAnimationStateSheet::UnknownState); - } - // - _RightFXActivated = false; - _LeftFXActivated = false; - if(EAM) - { - animState (MOVE, CAnimationStateSheet::FirstPersonAttack); - animIndex (MOVE, CAnimation::UnknownAnim); - animOffset(MOVE, 0.0); - _CurrentState = EAM->mState(_CurrentAutomaton, animState(MOVE)); - if(_CurrentState && _CurrentAnimSet[MOVE]) - { - const CAnimationState *animStatePtr = _CurrentAnimSet[MOVE]->getAnimationState(animState(MOVE)); - if(animStatePtr) - { - animIndex(MOVE, animStatePtr->chooseAnim(_AnimJobSpecialisation, people(), getGender(), 0.0)); - if(animIndex(MOVE) != CAnimation::UnknownAnim) - { - if(_PlayList) - { - _PlayList->setAnimation (MOVE, animId(MOVE)); - _PlayList->setTimeOrigin (MOVE, ryzomGetLocalTime ()*0.001);//_LastFrameTime); - _AnimAttackOn = true; - updateVisualDisplay(); - } - } - } - } - } - // Start FX to play at the animation beginning like trails. - if(_CurrentBehaviour.Behaviour == MBEHAV::RANGE_ATTACK) - { - startItemAttackFXs(_CurrentBehaviour.Range.ImpactIntensity != 0, _CurrentBehaviour.Range.ImpactIntensity); - } - else - { - startItemAttackFXs(_CurrentBehaviour.Combat.ImpactIntensity != 0 && _CurrentBehaviour.Combat.HitType != HITTYPE::Failed, _CurrentBehaviour.Combat.ImpactIntensity); - } - // DeltaHP - applyBehaviourFlyingHPs(behaviourContext, behaviour, targetHitDates); - } - // In third person view (or camera mode), play the same way than for the others. - else - CPlayerCL::applyBehaviour(behaviourContext); -}// applyBehaviour // - -//--------------------------------------------------- -// setDead : -// Method to Flag the character as dead and do everything needed. -//--------------------------------------------------- -void CUserEntity::setDead() // virtual -{ - // User is dead -> NO FOLLOW - disableFollow(); - // Remove the selection. - UserEntity->selection(CLFECOMMON::INVALID_SLOT); - // Death Mode Control and view. - UserControls.mode(CUserControls::DeathMode); - // Play the FX for the death - NL3D::UParticleSystemInstance deathFX = FXMngr.instantFX(ClientCfg.DeadFXName); - if(!deathFX.empty()) - deathFX.setPos(selectBox().getCenter()); - - // Last teleport is a death - - // get player's kami fame - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - sint8 kamiFame = 0; - uint kamiFameIndex = CStaticFames::getInstance().getFactionIndex("kami"); - if (pIM && kamiFameIndex != CStaticFames::INVALID_FACTION_INDEX) - { - CCDBNodeLeaf *pLeafKamiFame = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:FAME:PLAYER%d:VALUE", kamiFameIndex - 1), false); - if (pLeafKamiFame != NULL) - kamiFame = pLeafKamiFame->getValue8(); - } - - // get player's karavan fame - sint8 karavanFame = 0; - uint karavanFameIndex = CStaticFames::getInstance().getFactionIndex("karavan"); - if (pIM && karavanFameIndex != CStaticFames::INVALID_FACTION_INDEX) - { - CCDBNodeLeaf *pLeafKaravanFame = NLGUI::CDBManager::getInstance()->getDbProp(toString("SERVER:FAME:PLAYER%d:VALUE", karavanFameIndex - 1), false); - if (pLeafKaravanFame != NULL) - karavanFame = pLeafKaravanFame->getValue8(); - } - - // set loading background depending on player's faction fame - if (kamiFame > karavanFame) - LoadingBackground = ResurectKamiBackground; - else - LoadingBackground = ResurectKaravanBackground; - - // disable or enable shadowing - updateCastShadowMap(); - - // enable death warning popup - //CInterfaceManager * pIM = CInterfaceManager::getInstance(); - if( pIM ) - { - CAHManager::getInstance()->runActionHandler("set",NULL,"dblink=UI:VARIABLES:DEATH_WARNING_WANTED|value=1"); - } -}// setDead // - -//----------------------------------------------- -// skillUp : -// Skill Up -//----------------------------------------------- -void CUserEntity::skillUp() -{ - // Play the FX for the death - NL3D::UParticleSystemInstance skillUpFX = FXMngr.instantFX(ClientCfg.SkillUpFXName); - skillUpFX.setClusterSystem(getClusterSystem()); - if(!skillUpFX.empty()) - skillUpFX.setPos(pos()); -}// skillUp // - -//----------------------------------------------- -// startColTimer : -// After a few time, if the user is still in collision with someone else, remove collisions with other entitites. -//----------------------------------------------- -void CUserEntity::startColTimer() -{ - if(_ColOn) - { - if(_ColRemoved==false) - { - if((T1-_ColStartTime) > ClientCfg.TimeToRemoveCol) - { - EntitiesMngr.removeColUserOther(); - _ColRemoved = true; - } - } - } - else - { - _ColOn = true; - _ColStartTime = T1; - } -}// startColTimer // - -//----------------------------------------------- -// stopColTimer : -// Called when the user is no more in collision with another entity. -//----------------------------------------------- -void CUserEntity::stopColTimer() -{ - // Restore collisions. - if(_ColRemoved) - { - EntitiesMngr.restoreColUserOther(); - _ColRemoved = false; - } - _ColOn = false; -}// stopColTimer // - - - -//----------------------------------------------- -// getMaxSpeed -// Return the current max speed for the entity in meter per sec -// The method return a max according to the speed factor (given by the server) -// It's also return a value according to the landscape (water) -// Also managed mounts -//----------------------------------------------- -double CUserEntity::getMaxSpeed() const // virtual -{ - // Max Defined speed according to the current factor (slow, or speed increased) - double maxSpeed = _SpeedFactor.getValue(); - // User is Dead - if(isDead()) - { - maxSpeed *= 0.0; - } - // User is sitting - else if(isSit()) - { - maxSpeed *= 0.0; - } - // User is swimming - else if(isSwimming()) - { - - // We are a Ring DM so speed up a litle - if (_R2CharMode == R2::TCharMode::Editer || _R2CharMode == R2::TCharMode::Dm) - { - maxSpeed *= ClientCfg.DmRun / 2; - } - else - { - // Run - maxSpeed *= 3.0; - } - } - else if(isRiding()) - { - // Run if mount not hungry, otherwise, use walk velocity - if (_MountHunger.canRun()) - maxSpeed *= (double)getMountRunVelocity(); - else - maxSpeed *= (double)getMountWalkVelocity(); - } - else - { - // Run - maxSpeed *= runVelocity(); - } - // Return the current max - return maxSpeed; -// return ClientCfg.Run * _SpeedFactor.getValue(); -}// getMaxSpeed // - - -//----------------------------------------------- -// snapToGround : -// Snap the user to the ground. -//----------------------------------------------- -void CUserEntity::snapToGround() -{ - CEntityCL::snapToGround(); - - updateSound (ryzomGetLocalTime ()); -}// // snapToGround // - - -//----------------------------------------------- -// updateSound : -//----------------------------------------------- -void CUserEntity::updateSound(const TTime &time) -{ - H_AUTO_USE ( RZ_Client_Update_Sound ); - - // no sound manager, no need to update sound - if (SoundMngr == NULL) - return; - - if (!(StereoHMD && true)) // TODO: ClientCfg.Headphone - { - // NOTE: StereoHMD+Headphone impl in main_loop.cpp - SoundMngr->setListenerPos(pos()); - const CMatrix &camMat = MainCam.getMatrix(); - SoundMngr->setListenerOrientation(camMat.getJ(), camMat.getK()); - } - - if (ClientCfg.Light) - return; - - // step sound of self : refind the sound animations associated to the walk and run animation - - static bool computeAnim = true; - static bool lastMode = false; - static TTime previousTime = 0; - static TTime stepTime = 0; - static bool leftRight = false; - static NLSOUND::CSoundAnimMarker *leftStep = 0; - static NLSOUND::CSoundAnimMarker *rightStep = 0; - - // TODO : Remove when bug corrected: - if (_Gender == GSGENDER::unknown) - { - nlwarning("CUserEntity::updateSound : The gender is unknown, forcing it to male"); - _Gender = GSGENDER::male; - } - - // force recompute of anim if walk/run change. - computeAnim = computeAnim || (lastMode != _Run); - - // Check the sound animation to find the time between to step - if(computeAnim && SoundMngr && _CurrentAnimSet[MOVE] != 0) // && _SoundId[MOVE] != NLSOUND::CSoundAnimationNoId) - { - lastMode = _Run; - TAnimStateId mode = _Run ? CAnimationStateSheet::Run : CAnimationStateSheet::Walk; - const CAnimationState *animStatePtr = _CurrentAnimSet[MOVE]->getAnimationState (mode); - if (animStatePtr) - { - ::CAnimation::TAnimId animId = animStatePtr->chooseAnim (_AnimJobSpecialisation, people(), getGender(), 0); - if (animId != ::CAnimation::UnknownAnim) - { - const ::CAnimation *anim = animStatePtr->getAnimation (animId); - if(anim) - { - // Select the sound ID - _SoundId[MOVE] = anim->soundId(); - - if (_SoundId[MOVE] != NLSOUND::CSoundAnimationNoId) - { - // retrieve the anim - NLSOUND::CSoundAnimManager *mgr = NLSOUND::CSoundAnimManager::instance(); - - string name = mgr->idToName(_SoundId[MOVE]); - - if (!name.empty()) - { - NLSOUND::CSoundAnimation *sanim = mgr->findAnimation(name); - if (sanim->countMarkers() != 2) - { - static set warnOnce; - if (warnOnce.find(sanim->getName()) == warnOnce.end()) - { - nlwarning("Sound animation '%s' has not 2 markers, not a biped ? (Display Once)", sanim->getName().c_str()); - warnOnce.insert(sanim->getName()); - } - } - else - { - stepTime = TTime((sanim->getMarker(1)->getTime() - sanim->getMarker(0)->getTime()) * 1000); - rightStep = sanim->getMarker(0); - leftStep = sanim->getMarker(1); - computeAnim = false; - } - } - } - } - } - } - } - - if( SoundMngr && _Mode == MBEHAV::NORMAL) - { - if (!getVelocity().isNull()) - { - if (stepTime > 0 && time-previousTime>=stepTime) - { - previousTime = time; - - // set the sound 1 meter below listener - _SoundContext.Position = pos() + CVector(0,0,-1); - _SoundContext.RelativeGain = SoundMngr->getUserEntitySoundLevel();; - - uint32 matId= getGroundType(); - //nldebug("Current material = %u", matId); - _SoundContext.Args[0] = matId; - - if (leftRight) - { - if (leftStep) - // TODO : find the correct cluster - leftStep->play(SoundMngr->getMixer(), NULL, _SoundContext); - } - else - { - if (rightStep) - // TODO : find the correct cluster - rightStep->play(SoundMngr->getMixer(), NULL, _SoundContext); - - // recompute a new sound anim - computeAnim = true; - } - - leftRight = !leftRight; - } - } - else - { - // resets the counter - previousTime = 0; - } - } -}// updateSound // - - -//----------------------------------------------- -// rotate : -// rotate the body on the left or right (front changes). -//----------------------------------------------- -void CUserEntity::rotate(float ang) -{ - // Rotate the body. - CMatrix m; - m.identity(); - m.rotateZ(ang); - front(m * front().normed()); -}// rotate // - - -//----------------------------------------------- -// rotHeadVertically : -// rotate the head vertically. -//----------------------------------------------- -void CUserEntity::rotHeadVertically(float ang) -{ - setHeadPitch(_HeadPitch+ang); -}// rotHeadVertically // - - -//----------------------------------------------- -// setHeadPitch(double hp) -//----------------------------------------------- -void CUserEntity::setHeadPitch(double hp) -{ - _HeadPitch= hp; - const double bound= Pi/2 - 0.01; // epsilon to avoid gimbal lock - clamp(_HeadPitch, -bound, bound); -} - -//--------------------------------------------------- -// slotRemoved : -// To Inform about an entity removed (to remove from selection for example). -// This will remove the entity from the target. -// \param slot : Slot of the entity that will be removed. -//--------------------------------------------------- -void CUserEntity::slotRemoved(const CLFECOMMON::TCLEntityId &slot) -{ - // parent call - CPlayerCL::slotRemoved(slot); - - // reset also selection - if(selection() == slot) - selection(CLFECOMMON::INVALID_SLOT); -}// slotRemoved // - -//--------------------------------------------------- -// selection : -// Change the entity selected. -// \param slot : slot now selected (CLFECOMMON::INVALID_SLOT for an empty selection). -// \warning Can be different from the entity targeted (in combat mode for example). -//--------------------------------------------------- -void CUserEntity::selection(const CLFECOMMON::TCLEntityId &slot) // virtual -{ - //allows reselection in Ring client: even if the selected slots is equal to the selection, - //the client must send the messages. - if ((_Selection == slot) && !ClientCfg.R2EDEnabled) - return; - - // The selection will be the entity to watch - WatchedEntitySlot = slot; - disableFollow(); - - // Send the entity selected to the server. - NetMngr.pushTarget(slot); - - - // Target the slot on client, don't wait NetWork response - targetSlot(slot); - _TargetSlotNoLag= slot; - - if (ClientCfg.R2EDEnabled) - { - R2::getEditor().inGameSelection(slot); - } - - - // Change the current selection so un color the current selection. - CEntityCL *sel = EntitiesMngr.entity(_Selection); - if(sel != NULL) - sel->visualSelectionStop(); // Blink off == restore to normal - - // Set the entity selected - _Selection = slot; - - // Update visual selection and interface - if ( sel && sel->isForageSource() ) - sel->buildInSceneInterface(); // remove focus on previous selected source - sel = EntitiesMngr.entity(_Selection); - if(sel != NULL) - { - sel->visualSelectionStart(); - if ( sel->isForageSource() ) - sel->buildInSceneInterface(); // set focus on new selected source - } - - - // **** Update Target interface - //get the new target slot and set it in the database - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:TARGET:SLOT")->setValue64(slot); - - // Get the new target UID, and set in Database - uint tgtSlot= _Selection; - uint32 tgtEntityId= CLFECOMMON::INVALID_CLIENT_DATASET_INDEX; - CEntityCL *entity = NULL; - if (tgtSlot!=CLFECOMMON::INVALID_SLOT) - { - entity = EntitiesMngr.entity(tgtSlot); - if (entity) - tgtEntityId= entity->dataSetId(); - } - - // Set the User Target - CCDBNodeLeaf *prop = NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:TARGET:UID", false); - if(prop) - prop->setValue32(tgtEntityId); - - // Bar Manager. Update now the Target View (so it takes VP if data available or 0... but result is immediate) - CBarManager::getInstance()->setLocalTarget(tgtEntityId); - - // **** Update DB for InGameMenu - // clear the entries for mission option - for(uint k = 0; k < NUM_MISSION_OPTIONS; ++k) - { - CCDBNodeLeaf *missionOption = NLGUI::CDBManager::getInstance()->getDbProp(toString("LOCAL:TARGET:CONTEXT_MENU:MISSIONS_OPTIONS:%d:TITLE", (int) k), false); - if (missionOption) - { - missionOption->setValue32(0); - } - CCDBNodeLeaf *playerGiftNeeded = NLGUI::CDBManager::getInstance()->getDbProp(toString("LOCAL:TARGET:CONTEXT_MENU:MISSIONS_OPTIONS:%d:PLAYER_GIFT_NEEDED", (int) k), false); - if (playerGiftNeeded) - { - playerGiftNeeded->setValue32(0); - } - } -/* TODO ULU : Add RP tags */ - - // update pvp tags - if ((tgtSlot!=CLFECOMMON::INVALID_SLOT) && entity) - { - CPlayerCL *pPlayer = dynamic_cast(entity); - - if (pPlayer) - { - /*// Pvp Mode - CViewBitmap * tagMode = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:target:pvp_tags:mode")); - if (tagMode) - { - if (pPlayer->getPvpMode()&PVP_MODE::PvpFaction) - tagMode->setTexture("pvp_orange.tga"); - else if (pPlayer->getPvpMode()&PVP_MODE::PvpFactionFlagged) - tagMode->setTexture("pvp_red.tga"); - else - tagMode->setTexture("alpha_10.tga"); - } -*/ - /*// Pvp available actions (attack, heal, both) - CViewBitmap * tagMode = dynamic_cast(CWidgetManager::getInstance()->getElementFromId("ui:interface:target:pvp_tags:actions")); - if (tagMode) - { - if (pPlayer->getPvpMode()&PVP_MODE::PvpFaction) - tag->setTexture("pvp_orange.tga"); - else if (pPlayer->getPvpMode()&PVP_MODE::PvpFactionFlagged) - tag->setTexture("pvp_red.tga"); - else - tag->setTexture("alpha_10.tga"); - }*/ - - } - } - - // clear web page - prop= NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:TARGET:CONTEXT_MENU:WEB_PAGE_URL", false); - if(prop) prop->setValue32(0); - prop= NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:TARGET:CONTEXT_MENU:WEB_PAGE_TITLE", false); - if(prop) prop->setValue32(0); - - // clear mission ring - for(uint k = 0; k < BOTCHATTYPE::MaxR2MissionEntryDatabase; ++k) - { - prop= NLGUI::CDBManager::getInstance()->getDbProp(toString("LOCAL:TARGET:CONTEXT_MENU:MISSION_RING:%d:TITLE", k), false); - if(prop) prop->setValue32(0); - } - - // clear programs - prop= NLGUI::CDBManager::getInstance()->getDbProp("LOCAL:TARGET:CONTEXT_MENU:PROGRAMMES", false); - if(prop) prop->setValue32(0); - prop= NLGUI::CDBManager::getInstance()->getDbProp("SERVER:TARGET:CONTEXT_MENU:PROGRAMMES"); - if(prop) prop->setValue32(0); - // increment db counter for context menu - pIM->incLocalSyncActionCounter(); - -}// selection // - -//--------------------------------------------------- -// moveToAttack : -// Method to place the user to attack the target and attack. -//--------------------------------------------------- -void CUserEntity::moveToAttack() -{ - // **** For clarity, try to launch a "default attack" found in the memory bar instead of an "anonymous" action - CSPhraseManager *pPM= CSPhraseManager::getInstance(); - uint32 memLine, memSlot; - CEntityCL *target= EntitiesMngr.entity(selection()); - - CInventoryManager *inv = CInventoryManager::getInstance(); - - // auto-equip with valid weapon - if( ClientCfg.AutoEquipTool ) - { - if(inv) - { - // if no valid weapons in had -> auto-equip with last used weapons - bool validWeaponInHand = true; - uint32 rightHandSheet = inv->getRightHandItemSheet(); - if(rightHandSheet) - { - validWeaponInHand = inv->isMeleeWeaponItem(rightHandSheet) || inv->isRangeWeaponItem(rightHandSheet); - } - if( !validWeaponInHand ) - { - autoEquipWithLastUsedWeapons(); - } - - // remember last used weapon(s) - rememberWeaponsInHand(); - } - } - - if(target && pPM->findDefaultAttack(memLine, memSlot)) - { - // launch instead a phrase execution with this phrase - executeCombatWithPhrase(target, memLine, memSlot, true); - } - // **** Else launch an anonymous "default attack" - else - { - // melee or range? - bool melee = true; - if(inv) - { - uint32 rightHandSheet = inv->getRightHandItemSheet(); - if(rightHandSheet) - melee = inv->isMeleeWeaponItem(rightHandSheet); - } - - // Move to target if melee weapon - if(melee) - moveTo(selection(), 2.0, CUserEntity::Attack); - // Just attack if range weapon. - else - attack(); - } -}// moveToAttack // - -//--------------------------------------------------- -// attack : -// Method to attack the target. -//--------------------------------------------------- -void CUserEntity::attack() -{ - // execute the default attack - CSPhraseManager *pPM= CSPhraseManager::getInstance(); - pPM->executeDefaultAttack(); - - bool melee = true; - CInventoryManager *inv = CInventoryManager::getInstance(); - if(inv) - { - uint32 rightHandSheet = inv->getRightHandItemSheet(); - if(rightHandSheet) - melee = inv->isMeleeWeaponItem(rightHandSheet); - } - - // If option ON, follow when attacking. - if(ClientCfg.FollowOnAtk) - { - // Follow only if attacking with a melee weapon - if(melee) - // enable, but don't reset camera rotation - enableFollow(false); - } -}// attack // - -//--------------------------------------------------- -// attack : -// Method to attack the target, with a special phrase -//--------------------------------------------------- -void CUserEntity::attackWithPhrase() -{ - if( !canEngageCombat() ) - return; - - CSPhraseManager *pPM= CSPhraseManager::getInstance(); - - // validate the execution on server - pPM->sendExecuteToServer(_MoveToPhraseMemoryLine, _MoveToPhraseMemorySlot, _MoveToPhraseCyclic); - - // If the Attack is a "Next", and not a cycle, do a default attack - if(!_MoveToPhraseCyclic) - pPM->executeDefaultAttack(); - - // If option ON, follow when attacking. - if(ClientCfg.FollowOnAtk) - { - bool melee = true; - CInventoryManager *inv = CInventoryManager::getInstance(); - if(inv) - { - uint32 rightHandSheet = inv->getRightHandItemSheet(); - if(rightHandSheet) - melee = inv->isMeleeWeaponItem(rightHandSheet); - } - // Follow only if attacking with a melee weapon - if(melee) - // enable, but don't reset camera rotation - enableFollow(false); - } - - // Because sendExecuteToServer() has been called, must NOT cancelClientExecute() at resetAnyMoveTo() - _MoveToAction= CUserEntity::None; -} - -//----------------------------------------------- -// assist : -// your current target become the target of your current one. -//----------------------------------------------- -void CUserEntity::assist() -{ - assist(targetSlot()); -}// assist // - -//----------------------------------------------- - -void CUserEntity::assist(uint slot) -{ - // Check the current target - if(slot == CLFECOMMON::INVALID_SLOT || slot == _Slot) - return; - // Check the target - CEntityCL *target = EntitiesMngr.entity(slot); - if(target == 0) - return; - // Check the new slot. - CLFECOMMON::TCLEntityId newSlot = target->targetSlot(); - if(newSlot == CLFECOMMON::INVALID_SLOT || newSlot == _Slot) - return; - // Select the new target. - selection(newSlot); -} - -//--------------------------------------------------- -// disengage : -// Method to disengage the target. -//--------------------------------------------------- -void CUserEntity::disengage() -{ - // Set the database in local. - if(ClientCfg.Local) - { - IngameDbMngr.setProp("Entities:E0:P" + toString(CLFECOMMON::PROPERTY_MODE), MBEHAV::NORMAL); // Mode - IngameDbMngr.setProp("Entities:E0:P" + toString(CLFECOMMON::PROPERTY_TARGET_ID), _Selection); // Target - UserEntity->updateVisualProperty(0, CLFECOMMON::PROPERTY_MODE); - UserEntity->updateVisualProperty(0, CLFECOMMON::PROPERTY_TARGET_ID); - return; - } - - // Disengage MSG. - const string msgName = "COMBAT:DISENGAGE"; - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) - NetMngr.push(out); - else - nlwarning("UE::disengage: unknown message named '%s'.", msgName.c_str()); - - // Change the current mode. - mode(MBEHAV::NORMAL); -}// disengage // - -//----------------------------------------------- -// sit : -// Ask for the client to sit/stand ('true' to sit). -//----------------------------------------------- -bool CUserEntity::sit(bool s) -{ - bool ok= false; - - // SIT - if(s) - { - if(canSit() == true) - { - // disable afk mode - setAFK(false); - - // Sit MSG. - if(mode(MBEHAV::SIT)) - { - // autowalk disabled - UserControls.autowalkState(false); - - const string msgName = "COMMAND:SIT"; - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) - { - out.serial(s); - NetMngr.push(out); - } - else - nlwarning("UE:sit: unknown message named '%s'.", msgName.c_str()); - - // mode changed - ok= true; - - // display sit msg - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - ucstring msg = CI18N::get("msgUserIsSitting"); - string cat = getStringCategory(msg, msg); - pIM->displaySystemInfo(msg, cat); - } - } - } - // STAND - else - { - if(_Mode == MBEHAV::SIT) - { - if(mode(MBEHAV::NORMAL)) - { - const string msgName = "COMMAND:SIT"; - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) - { - out.serial(s); - NetMngr.push(out); - } - else - nlwarning("UE:sit: unknown message named '%s'.", msgName.c_str()); - - // mode changed - ok= true; - - // display stand msg - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - ucstring msg = CI18N::get("msgUserIsStanding"); - string cat = getStringCategory(msg, msg); - pIM->displaySystemInfo(msg, cat); - } - } - } - - // if mode changed, Write to the UI database, to update views - if(ok) - { - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:PLAYER_STAND", false); - if(node) - node->setValue32(_Mode != MBEHAV::SIT); - } - - // mode changed - return ok; -}// sit // - -//----------------------------------------------- -// canSit : -// Return true if the user can sit. -//----------------------------------------------- -bool CUserEntity::canSit() const -{ - // If the user is not already sitting or is on a mount - if(!isSit() && (!isRiding()) && !isDead() && !isSwimming()) - { - return true; - } - else - return false; -}// canSit // - -//----------------------------------------------- -// setAFK -//----------------------------------------------- -void CUserEntity::setAFK(bool b, string afkTxt) -{ - if( isAFK() == b ) return; - - if (b) - { - if( isDead() || isRiding() || moveTo() || follow() ) - return; - - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - //sint64 start = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_TSTART")->getValue64(); - //sint64 end = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_TEND")->getValue64(); - //sint64 type = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_TYPE")->getValue64(); - //sint64 num = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_NUMBER")->getValue64(); - if( pIM ) - { - if( NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:ACT_TYPE")->getValue64() != 0 ) - return; - } - - if( !isSit() && !isSwimming() ) - { - if( !mode(MBEHAV::REST) ) - return; - } - } - else - { - if( !isSit() && !isSwimming() ) - { - if (isDead()) - return; - else - mode(MBEHAV::NORMAL); - } - } - - // send afk state - string msgName = "COMMAND:AFK"; - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream(msgName, out)) - { - out.serial(b); - NetMngr.push(out); - } - else - nlwarning("CUserEntity:setAFK: unknown message named '%s'.", msgName.c_str()); - - // custom afk txt - ucstring ucstr; - ucstr.fromUtf8( afkTxt ); - CBitMemStream outTxt; - msgName = "STRING:AFK_TXT"; - if( GenericMsgHeaderMngr.pushNameToStream(msgName,outTxt) ) - { - outTxt.serial( ucstr ); - NetMngr.push( outTxt ); - } - else - { - nlwarning("CUserEntity:setAFK: unknown message named '%s'.", msgName.c_str()); - } - - -}// setAFK // - -//----------------------------------------------- -// rollDice -//----------------------------------------------- -void CUserEntity::rollDice(sint16 min, sint16 max, bool local) -{ - if (local) - { - // no need to broadcast over network here - static NLMISC::CRandom* dice = (NLMISC::CRandom*)NULL; - if (!dice) - { - dice = new NLMISC::CRandom; - dice->srand(CTickEventHandler::getGameCycle()); - } - sint16 roll = min + (sint16)dice->rand(max-min); - - ucstring msg = CI18N::get("msgRollDiceLocal"); - strFindReplace(msg, "%min", toString(min)); - strFindReplace(msg, "%max", toString(max)); - strFindReplace(msg, "%roll", toString(roll)); - - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - - pIM->displaySystemInfo(msg, getStringCategory(msg, msg)); - return; - } - const string msgName = "COMMAND:RANDOM"; - CBitMemStream out; - if (GenericMsgHeaderMngr.pushNameToStream(msgName, out)) - { - out.serial(min); - out.serial(max); - NetMngr.push(out); - } - else - nlwarning("CUserEntity:rollDice: unknown message named '%s'.", msgName.c_str()); -}// rollDice // - -//--------------------------------------------------- -// canEngageCombat : -// return true if user can engage melee combat, else return false and display system msg -//--------------------------------------------------- -bool CUserEntity::canEngageCombat() -{ - if( isSit() ) - { - // display "you can't fight while sitting" message) - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - ucstring msg = CI18N::get("msgCantFightSit"); - string cat = getStringCategory(msg, msg); - pIM->displaySystemInfo(msg, cat); - - return false; - } - - if( isSwimming() ) - { - // display "you can't fight while swiming" message) - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - ucstring msg = CI18N::get("msgCantFightSwim"); - string cat = getStringCategory(msg, msg); - pIM->displaySystemInfo(msg, cat); - - return false; - } - - if ( isRiding() ) - { - // display "you can't fight while swimming" message) - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - ucstring msg = CI18N::get("msgCantFightRide"); - string cat = getStringCategory(msg, msg); - pIM->displaySystemInfo(msg, cat); - - return false; - } - - return true; -} // canEngageCombat // - - -//--------------------------------------------------- -// viewMode : -// Change the View (First/Third Person View). -//--------------------------------------------------- -void CUserEntity::viewMode(CUserEntity::TView viewMode, bool changeView) -{ - switch(viewMode) - { - // First Person View - case FirstPV: - if(changeView) - ClientCfg.FPV = true; - if(_Mount != CLFECOMMON::INVALID_SLOT) - { - CEntityCL *mount = EntitiesMngr.entity(_Mount); - if(mount) - mount->displayable(false); - - _HiddenMount = _Mount; - } - // Change Controls. - if( isRiding() ) - { - bool autoWalk = UserControls.autowalkState(); - UserControls.mode(CUserControls::MountMode); - if( autoWalk ) - UserControls.autowalkState( true ); - } - else - UserControls.mode(CUserControls::InterfaceMode); - break; - - // Third Person View - case ThirdPV: - if(changeView) - ClientCfg.FPV = false; - - if(_HiddenMount != CLFECOMMON::INVALID_SLOT) - { - CEntityCL *mount = EntitiesMngr.entity(_HiddenMount); - if(mount) - mount->displayable(true); - - _HiddenMount = CLFECOMMON::INVALID_SLOT; - } - // Change Controls. - UserControls.mode(CUserControls::ThirdMode); - break; - - // Unknown - default: - nlwarning("UE:viewMode: Unknown View Asked '%d'.", (sint)viewMode); - return; - } - - // Change the current View like asked. - _ViewMode = viewMode; - - // disable or enable shadowing - updateCastShadowMap(); -}// viewMode // - -//----------------------------------------------- -// toggleCamera : -// Toggle Camera (First/Third Person) -//----------------------------------------------- -void CUserEntity::toggleCamera() -{ - // You cannot change the camera view when dead. - if(isDead()) - return; - // Only if not inside a building. - if(!UserEntity->forceIndoorFPV()) - { - // Leave the 1st Person Mode -> Enter the 3rd Person View Mode - if (UserEntity->viewMode() == CUserEntity::FirstPV) - UserEntity->viewMode(CUserEntity::ThirdPV); - // Leave the 3rd Person Mode -> Enter the 1st Person View Mode - else - UserEntity->viewMode(CUserEntity::FirstPV); - } -}// toggleCamera // - -//----------------------------------------------- -// forceCameraFirstPerson : -// Force Camera to First Person View -//----------------------------------------------- -void CUserEntity::forceCameraFirstPerson() -{ - // You cannot change the camera view when dead. - if(isDead()) - return; - // Only if not inside a building. - if(!UserEntity->forceIndoorFPV()) - { - if (UserEntity->viewMode() != CUserEntity::FirstPV) - //Enter the 1st Person View Mode - UserEntity->viewMode(CUserEntity::FirstPV); - } -}// forceCameraFirstPerson // - -//--------------------------------------------------- -// getScale : -// Return the entity scale. (return 1.0 if there is any problem). -// \todo GUIGUI : do we have to take care of the user's race kwnowing it can favour him ? -//--------------------------------------------------- -float CUserEntity::getScale() const // virtual -{ - // Default Scale. - return 1.0f; -}// getScale // - -//--------------------------------------------------- -// removeCheckPrimitive : -// Remove the check primitive -//--------------------------------------------------- -void CUserEntity::removeCheckPrimitive() -{ - if(PACS && _CheckPrimitive) - PACS->removePrimitive(_CheckPrimitive); - _CheckPrimitive = 0; -} - -//--------------------------------------------------- -// removePrimitive : -// Remove the primitive -//--------------------------------------------------- -void CUserEntity::removePrimitive() // virtual (will not be called by ~CEntityCL()) -{ - // Remove the Primitive used for check - removeCheckPrimitive(); - - // Remove the other primitive - CPlayerCL::removePrimitive(); -}// removePrimitive // - -//--------------------------------------------------- -// computePrimitive : -// Create a primitive for the entity. -//--------------------------------------------------- -void CUserEntity::computePrimitive() // virtual -{ - // Initialize the primitive. - if(initPrimitive(0.5f, 2.0f, 0.0f, 0.0f, UMovePrimitive::Slide, (UMovePrimitive::TTrigger)(UMovePrimitive::OverlapTrigger | UMovePrimitive::EnterTrigger), MaskColPlayer, MaskColPlayer | MaskColNpc | MaskColDoor)) - _Primitive->insertInWorldImage(dynamicWI); - // Set the position. - pacsPos(pos()); -}// computePrimitive // - - -//--------------------------------------------------- -// isBusy : -// Return if the user is already busy (combat/bo chat/loot/ etc.). -//--------------------------------------------------- -bool CUserEntity::isBusy() const -{ - CInterfaceManager *IM = CInterfaceManager::getInstance (); - // Check Trade. - - // TODO : put the right DB entry ! - - CCDBNodeLeaf *nod = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:INVENTORY:EXCHANGE:BEGUN", false); - if(nod) - { - if(nod->getValueBool()) - return true; - } -// else -// nlwarning("UE:isBusy: Cannot get the nod 'SERVER:INVENTORY:EXCHANGE:BEGUN'."); - -/* - // Check Loot - static const uint nbSlot = 4; - uint i; - for(i=0; igetDbProp(NLMISC::toString("SERVER:INVENTORY:%d:%d:SHEET", INVENTORIES::pickup, i), false); - if(nod) - { - if(nod->getValue32() != 0) - return true; - } - else - nlwarning("UE:isBusy: Cannot get the nod 'SERVER:INVENTORY:%d:%d:SHEET'.", INVENTORIES::pickup, i); - } - - // Check Harvest - for(i=0; igetDbProp(NLMISC::toString("SERVER:INVENTORY:%d:%d:SHEET", INVENTORIES::harvest, i), false); - if(nod) - { - if(nod->getValue32() != 0) - return true; - } - else - nlwarning("UE:isBusy: Cannot get the nod 'SERVER:INVENTORY:%d:%d:SHEET'.", INVENTORIES::harvest, i); - } -*/ - - // Check Bot chat. - CBotChatPage * currPage = CBotChatManager::getInstance()->getCurrPage(); - if( currPage!= NULL ) - { - return true; - } - - // Not Busy - return false; -}// isBusy // - - -//--------------------------------------------------- -// updateVisualDisplay : -// Show/Hide all or parts of the user body. -// todo GUIGUI : it's bad for the _Face to be a separated instance -//--------------------------------------------------- -void CUserEntity::updateVisualDisplay() -{ - // We need a skeleton. - if(_Skeleton.empty()) - return; - - // 1st person View - if(UserControls.isInternalView() || View.forceFirstPersonView()) - { - // Hide the mount - if (_Mount != CLFECOMMON::INVALID_SLOT) - { - CCharacterCL *mount = dynamic_cast(EntitiesMngr.entity(_Mount)); - if(mount) - mount->displayable(false); - - _HiddenMount = _Mount; - } - else if (_HiddenMount != CLFECOMMON::INVALID_SLOT) - { - // not on mount anymore, but still in FPV - CCharacterCL *mount = dynamic_cast(EntitiesMngr.entity(_HiddenMount)); - if(mount) - mount->displayable(true); - - _HiddenMount = CLFECOMMON::INVALID_SLOT; - } - - // Hide all user body parts. - for(uint i=0; i<_Instances.size(); ++i) - if(!_Instances[i].Current.empty()) - { - _Instances[i].Current.hide(); - _Instances[i].hideStaticFXs(); - } - // Hide the face - if(!_Face.Current.empty()) - _Face.Current.hide(); - - // We want to display weapons in 1st person view when attacking. - if(modeWithHiddenItems() == false) - { - if( _Mode == MBEHAV::COMBAT_FLOAT || _Mode == MBEHAV::COMBAT ) - { - if( _ObjectsVisible ) - { - // Show just Few parts - if(!_Instances[SLOTTYPE::HANDS_SLOT].Current.empty()) - { - _Instances[SLOTTYPE::HANDS_SLOT].Current.show(); - _Instances[SLOTTYPE::HANDS_SLOT].showStaticFXs(); - } - if(!_Instances[SLOTTYPE::ARMS_SLOT].Current.empty()) - { - _Instances[SLOTTYPE::ARMS_SLOT].Current.show(); - _Instances[SLOTTYPE::ARMS_SLOT].showStaticFXs(); - } - if(!_Instances[SLOTTYPE::RIGHT_HAND_SLOT].Current.empty()) - { - _Instances[SLOTTYPE::RIGHT_HAND_SLOT].Current.show(); - _Instances[SLOTTYPE::RIGHT_HAND_SLOT].showStaticFXs(); - } - if(!_Instances[SLOTTYPE::LEFT_HAND_SLOT].Current.empty()) - { - _Instances[SLOTTYPE::LEFT_HAND_SLOT].Current.show(); - _Instances[SLOTTYPE::LEFT_HAND_SLOT].showStaticFXs(); - } - } - } - } - } - else - { - // Show the mount - CCharacterCL *mount = dynamic_cast(EntitiesMngr.entity(_Mount)); - if(mount) - { - mount->displayable(true); - - showOrHideBodyParts( objectsVisible() ); - } - - // Show the face - /* - if(!_Face.Current.empty()) - _Face.Current.show(); - */ - } -}// updateVisualDisplay // - -//--------------------------------------------------- -// light: -// Show/Hide the user light. -//--------------------------------------------------- -void CUserEntity::light() -{ - // Create the light - if(_Light.empty()) - { - // Check there is a skeleton and a bone to stick the light before to create it. - if(!_Skeleton.empty() && _NameBoneId!=-1) - { - _Light = Scene->createPointLight(); - if(!_Light.empty()) - { - // front of the player - _Light.setPos(0.f,0.3f,0.f); - // Setup the light - _Light.setupAttenuation(12.0f, 20.0f); - // Attach the light - _Skeleton.stickObject(_Light, _NameBoneId); - // The player light is the only one who can interact with Lightmapped objects - _Light.setInfluenceLightMap(true); - - // TestYoyo - /* - NL3D::UInstance inst; - inst= Scene->createInstance("box.shape"); - if(!inst.empty()) - { - inst.setScale(0.2f, 0.2f, 0.2f); - inst.parent(_Light); - } - */ - } - } - else - nlwarning("UE:light: there is no skeleton or Name Bone to stick the light."); - } - // Turn On/Off the Light - _LightOn = !_LightOn; - if(!_Light.empty()) - { - if(_LightOn) - _Light.show(); - else - _Light.hide(); - } -}// light // - -//--------------------------------------------------- -// CSpeedFactor::init : -// Initialize the Observer for the Speed Factor. -//--------------------------------------------------- -void CUserEntity::CSpeedFactor::init() -{ - _Value = 1.0f; // Default speed factor is 1. - _ServerFactor = 1.0f; - CInterfaceManager *IM = CInterfaceManager::getInstance (); - CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:SPEED_FACTOR", false); - if(pNodeLeaf) - { - /* if(!pNodeLeaf->addToLeaves(this)) - nlwarning("UE:SP:init: cannot add the observer");*/ - ICDBNode::CTextId textId; - pNodeLeaf->addObserver(this, textId); - if ( pNodeLeaf->getValue64() != 0 ) - _Value = ((float)pNodeLeaf->getValue64())/100.0f; // may have been received before - } - else - nlwarning("UE:SP:init: 'SERVER:USER:SPEED_FACTOR' does not exist."); -}// CSpeedFactor::init // - -//--------------------------------------------------- -// CMountHunger::init : -//--------------------------------------------------- -void CUserEntity::CMountHunger::init() -{} - -//--------------------------------------------------- -// CMountSpeeds::init : -//--------------------------------------------------- -void CUserEntity::CMountSpeeds::init() -{ - CInterfaceManager *IM = CInterfaceManager::getInstance (); - CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:USER:MOUNT_WALK_SPEED", false ); - BOMB_IF( ! pNodeLeaf, "MOUNT_WALK_SPEED not found", return ); - if(pNodeLeaf) - { - ICDBNode::CTextId textId; - pNodeLeaf->addObserver(this, textId); - _WalkSpeed = ((float)pNodeLeaf->getValue32()) / 1000.0f; // may have been received before - } - pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:USER:MOUNT_RUN_SPEED", false ); - BOMB_IF( ! pNodeLeaf, "MOUNT_RUN_SPEED not found", return ); - if(pNodeLeaf) - { - ICDBNode::CTextId textId; - pNodeLeaf->addObserver(this, textId); - _RunSpeed = ((float)pNodeLeaf->getValue32()) / 1000.0f; // may have been received before - } -} - -//--------------------------------------------------- - -void CUserEntity::CSpeedFactor::release() -{ - CInterfaceManager *IM = CInterfaceManager::getInstance (); - CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:SPEED_FACTOR", false); - if(pNodeLeaf) - { - /* if(!pNodeLeaf->addToLeaves(this)) - nlwarning("UE:SP:init: cannot add the observer");*/ - ICDBNode::CTextId textId; - pNodeLeaf->removeObserver(this, textId); - } - else - nlwarning("UE:SP:init: 'SERVER:USER:SPEED_FACTOR' does not exist."); -}// CSpeedFactor::init // - -void CUserEntity::CMountHunger::release() -{} - -void CUserEntity::CMountSpeeds::release() -{ - CInterfaceManager *IM = CInterfaceManager::getInstance (); - CCDBNodeLeaf *pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:USER:MOUNT_WALK_SPEED", false ); - BOMB_IF( ! pNodeLeaf, "MOUNT_WALK_SPEED not found", return ); - if(pNodeLeaf) - { - ICDBNode::CTextId textId; - pNodeLeaf->removeObserver(this, textId); - } - pNodeLeaf = NLGUI::CDBManager::getInstance()->getDbProp( "SERVER:USER:MOUNT_RUN_SPEED", false ); - BOMB_IF( ! pNodeLeaf, "MOUNT_RUN_SPEED not found", return ); - if(pNodeLeaf) - { - ICDBNode::CTextId textId; - pNodeLeaf->removeObserver(this, textId); - } -} - - -//--------------------------------------------------- -// CSpeedFactor::update : -// Callback called to update the speed factor. -//--------------------------------------------------- -void CUserEntity::CSpeedFactor::update(ICDBNode *node) // virtual -{ - CCDBNodeLeaf *leaf = safe_cast(node); - _Value = ((float)leaf->getValue64())/100.0f; - //nlinfo("SpeedFactor changed to %f / %" NL_I64 "u", _Value, leaf->getValue64()); - - // clamp the value (2.0 is the egg item or the level 6 speed up power up, nothing should be faster) - // commented because ring editor speed is in fact faster - //if(_Value > 2.0f) - //{ - //nlwarning("HACK: you try to change the speed factor to %f", _Value); - //nlstop; - //_Value = 2.0f; - //} -}// CSpeedFactor::update // - - -/* - * Return true if the mount can run. Precondition: UserEntity->isRiding(). - */ -bool CUserEntity::CMountHunger::canRun() const -{ - CEntityCL *mountEntity = UserEntity->getMountEntity(); - if ( ! mountEntity ) - return false; - - // Find the mount's db leaf and check hunger - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CCDBNodeBranch *animalsNode = safe_cast(NLGUI::CDBManager::getInstance()->getDB()->getNode( ICDBNode::CTextId( "SERVER:PACK_ANIMAL" ), false )); - BOMB_IF( ! animalsNode, "! animalsNode", return false; ); - uint nbAnimals = (uint)animalsNode->getNbNodes(); - for ( uint i=0; i!=nbAnimals; ++i ) - { - ICDBNode *beastNode = animalsNode->getNode( i ); - CCDBNodeLeaf *uidLeaf = safe_cast(beastNode->getNode( ICDBNode::CTextId( "UID" ) )); - if ( ((CLFECOMMON::TClientDataSetIndex)uidLeaf->getValue32()) == mountEntity->dataSetId() ) - { - CCDBNodeLeaf *hungerLeaf = safe_cast(beastNode->getNode( ICDBNode::CTextId( "HUNGER" ) )); - return (hungerLeaf->getValue32() != (sint)ANIMAL_TYPE::DbHungryValue); - } - } - return false; -} - - - -//--------------------------------------------------- -// CMountSpeeds::update : -// Callback called to update the mount speed. -//--------------------------------------------------- -void CUserEntity::CMountSpeeds::update(ICDBNode * /* node */) // virtual -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - _WalkSpeed = ((float)(NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:MOUNT_WALK_SPEED")->getValue32())) / 1000.0f; - _RunSpeed = ((float)(NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:MOUNT_RUN_SPEED")->getValue32())) / 1000.0f; -} - - -/* - * Return the mount entity if the user is riding, otherwise NULL - */ -CEntityCL* CUserEntity::getMountEntity() -{ - if ( _Mount < EntitiesMngr.entities().size() ) - { - return EntitiesMngr.entities()[_Mount]; - } - return NULL; -} - -/* - * Return the DB entry for the specified user's animal (NULL if not found) - */ -CCDBNodeBranch *CUserEntity::getBeastDBEntry( CLFECOMMON::TClientDataSetIndex uid ) -{ - // Find animal entry corresponding to datasetId - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - CCDBNodeBranch *animalsNode = safe_cast(NLGUI::CDBManager::getInstance()->getDB()->getNode( ICDBNode::CTextId( "SERVER:PACK_ANIMAL" ), false )); - BOMB_IF( ! animalsNode, "! animalsNode", return NULL ); - uint nbAnimals = (uint)animalsNode->getNbNodes(); - for ( uint i=0; i!=nbAnimals; ++i ) - { - ICDBNode *beastNode = animalsNode->getNode( i ); - CCDBNodeLeaf *pNodeLeaf = safe_cast(beastNode->getNode( ICDBNode::CTextId( "UID" ) )); - if ( pNodeLeaf && (pNodeLeaf->getValue32() == (sint32)uid) ) - return (CCDBNodeBranch*)beastNode; - } - return NULL; -} - - -//--------------------------------------------------- -// displayDebug : -// Display Debug Information. -//--------------------------------------------------- -void CUserEntity::displayDebug(float x, float &y, float lineStep) // virtual -{ - CPlayerCL::displayDebug(x, y, lineStep); -}// displayDebug // - -//--------------------------------------------------- -// displayModifiers : -// Display dmg/heal numbers above the head. -//--------------------------------------------------- -void CUserEntity::displayModifiers() // virtual -{ - if(!UserControls.isInternalView()) - CPlayerCL::displayModifiers(); -}// displayModifiers // - -//--------------------------------------------------- -// isVisible : -// Return 'true' is the entity is displayed. -//--------------------------------------------------- -bool CUserEntity::isVisible() const // virtual -{ - return !UserControls.isInternalView(); -}// isVisible // - - - - - - -//--------------------------------------------------- -// readWrite : -// Read/Write Variables from/to the stream. -//--------------------------------------------------- -void CUserEntity::readWrite(NLMISC::IStream &f) -{ - CPlayerCL::readWrite(f); - - // PROTECTED - f.serial(_SpeedFactor); - f.serial(_FrontVelocity); - f.serial(_LateralVelocity); - CVector dummyHead; - f.serial(dummyHead); - f.serial(_HeadPitch); - f.serial(_EyesHeight); - f.serial(_Run); - f.serial(_WalkVelocity); - f.serial(_RunVelocity); - f.serial(_CurrentVelocity); - f.serial(_Selection); - f.serial(_Trader); - f.serial(_Interlocutor); - f.serial(_Selectable); - - // PRIVATE - f.serial(_OnMount); - f.serial(_AnimAttackOn); -// f.serialEnum(_ViewMode); -}// readWrite // - -//--------------------------------------------------- -// load : -// To call after a read from a stream to re-initialize the entity. -//--------------------------------------------------- -void CUserEntity::load() // virtual -{ - CInterfaceManager *IM = CInterfaceManager::getInstance (); - // Insert the user into PACS at his saved position - pacsPos(pos()); - - // update - if(!_WaitForAppearance) - { - // Visual properties A - sint64 prop = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:Entities:E"+toString("%d", _Slot)+":P"+toString("%d", CLFECOMMON::PROPERTY_VPA))->getValue64(); - updateVisualPropertyVpa(0, prop); // Vpa udapte vpb and vpc too. - } -}// load // - - -//--------------------------------------------------- -void CUserEntity::CInvisibleObserver::update(ICDBNode* node) -{ - UserEntity->buildInSceneInterface(); -} - -//--------------------------------------------------- -void CUserEntity::CSkillPointsObserver::update(ICDBNode* node ) -{ - if (FarTP.isFarTPInProgress() || IngameDbMngr.initInProgress()) // prevent from displaying at the beginning of a FarTP (due to RESET_BANK or CDB resetData()) - return; - - CInterfaceManager *pIM = CInterfaceManager::getInstance (); - CCDBNodeLeaf *leaf = dynamic_cast(node); - if (leaf) - { - sint32 oldValue = leaf->getOldValue32(); - if (oldValue != 0) - { - sint delta = leaf->getValue32()-oldValue; - string deltaStr = toString("%+d", delta); - - // get the sp title - ucstring spTitle; - spTitle= CI18N::get(toString("uiSkillPointsBold%d",SpType)); - - // run the popup - CAHManager::getInstance()->runActionHandler("message_popup", NULL, "text1="+deltaStr+"|text0="+spTitle.toUtf8()); - - // Context help - contextHelp ("skill_point"); - } - } -} - - -//--------------------------------------------------- -// CFameObserver::update -//--------------------------------------------------- -void CUserEntity::CFameObserver::update(ICDBNode* node ) -{ - CSkillManager *pSM = CSkillManager::getInstance(); - CCDBNodeLeaf *leaf = dynamic_cast(node); - if (leaf) - { - sint32 fameValue = leaf->getValue32(); - pSM->tryToUnblockTitleFromMinFames( FactionIndex, fameValue ); - pSM->tryToUnblockTitleFromMaxFames( FactionIndex, fameValue ); - } -} - - -//--------------------------------------------------- -void CUserEntity::makeTransparent(bool t) -{ - CPlayerCL::makeTransparent(t); - - uint32 opaMin= getOpacityMin(); - uint8 opacity = (uint8)(opaMin + (255-opaMin) * (1.0 - _TranspFactor)); - - getFace()->makeInstanceTransparent(opacity, (uint8)opaMin); -}// makeTransparent // - -//--------------------------------------------------- -void CUserEntity::setDiffuse(bool onOff, NLMISC::CRGBA diffuse) -{ - CPlayerCL::setDiffuse(onOff, diffuse); - getFace()->setDiffuse(onOff, diffuse); -} - - - - -// Helper for CUserEntity::extractRM() -bool findExtractionActionInMemory( CSPhraseManager *pm, CSBrickManager *bm, uint memoryLine, uint& index ) -{ - uint x; - for ( x=0; x!=PHRASE_MAX_MEMORY_SLOT; ++x ) - { - uint32 phraseSlot = pm->getMemorizedPhrase( memoryLine, x ); - const CSPhraseCom& phraseCom = pm->getPhrase( phraseSlot ); - if ( ! phraseCom.empty() ) - { - CSBrickSheet *brickSheet = bm->getBrick( phraseCom.Bricks[0] ); - if ( brickSheet->isForageExtraction() && (!brickSheet->MandatoryFamilies.empty()) ) // assumes care root bricks have not mandatories - { - index = x; - return true; - } - } - } - return false; -} - -//--------------------------------------------------- -void CUserEntity::extractRM() -{ - CSPhraseManager *pm = CSPhraseManager::getInstance(); - uint index; - uint memoryLine; - bool autoFindPhrase = (_MoveToPhraseMemoryLine == std::numeric_limits::max()); - if ( ! autoFindPhrase ) - { - // Use clicked phrase - memoryLine = _MoveToPhraseMemoryLine; - index = _MoveToPhraseMemorySlot; - } - else - { - // Find the first extraction phrase in the memory bar - CSBrickManager *bm = CSBrickManager::getInstance(); - memoryLine = pm->getSelectedMemoryLineDB(); - if ( ! findExtractionActionInMemory( pm, bm, memoryLine, index ) ) - { - // Search in other memory bar lines (because the auto-equip does not set the current line at once) - memoryLine = std::numeric_limits::max(); - uint nbLines = pm->getNbMemoryLines(); - for ( uint j=0; j!=nbLines; ++j ) - { - if ( j == memoryLine ) - continue; - if ( findExtractionActionInMemory( pm, bm, j, index ) ) - { - memoryLine = j; - break; - } - } - } - } - - if ( memoryLine != std::numeric_limits::max() ) - { - // Open the forage (but not for care actions). Necessary for the case of redoing an extraction after a Drop All on the same source. - uint32 phraseId = pm->getMemorizedPhrase( memoryLine, index ); - if ( phraseId != 0 ) - { - const CSPhraseCom& phraseCom = pm->getPhrase( phraseId ); - if ( ! phraseCom.empty() ) - { - CSBrickSheet *rootBrick = CSBrickManager::getInstance()->getBrick( phraseCom.Bricks[0] ); - if ( rootBrick ) - { - if ( rootBrick->IndexInFamily == 1 ) // only extracting actions - CTempInvManager::getInstance()->open( TEMP_INV_MODE::Forage ); - } - } - } - - // Cast the extraction. if autoFindPhrase, clientExecute() not already called. - if ( autoFindPhrase ) - { - // decide now if cyclic or not - _MoveToPhraseCyclic= true; - if(pm->avoidCyclicForPhrase(pm->getMemorizedPhrase(memoryLine, index))) - _MoveToPhraseCyclic= false; - - // execute on client now - pm->clientExecute( memoryLine, index, _MoveToPhraseCyclic); - } - - // execute on server - pm->sendExecuteToServer( memoryLine, index, _MoveToPhraseCyclic ); - - // Because sendExecuteToServer() has been called, must NOT cancelClientExecute() at resetAnyMoveTo() - _MoveToAction= CUserEntity::None; - } - else - { - CInterfaceManager::getInstance()->displaySystemInfo( CI18N::get("uiExtractionPhraseMissing"), "CHK" ); - return; - } -} - - -// *************************************************************************** -bool CUserEntity::canCastShadowMap() const -{ - if(!CCharacterCL::canCastShadowMap()) - return false; - - // don't cast shadow in first person, but in death mode (third person actually...) - return viewMode() != FirstPV || UserControls.mode() == CUserControls::DeathMode; -} - - -// *************************************************************************** -void CUserEntity::forceLookEntity(const NLMISC::CVectorD &dir2targIn, bool updateHeadPitch, bool /* start */) -{ - CVectorD dir2targ= dir2targIn; - float frontYawBefore = 0.f; - float frontYawAfter; - - // Third person: bkup current yaw - if(viewMode()==ThirdPV) - { - frontYawBefore = frontYaw(); - } - - - // **** Look at the entity - dir2targ.normalize(); - front(dir2targ, false, false); - - - // **** FirstPerson - if(viewMode() == FirstPV) - { - if(updateHeadPitch && _FollowForceHeadPitch) - { - // rotate the head to the target - CEntityCL *target = EntitiesMngr.entity(targetSlot()); - if(target) - { - // Both Z must be correct - snapToGround(); - target->snapToGround(); - - // don't update to the real head position each frame (else jitter too much cause of target anim) - CVector targetPos= target->pos() + CVector(0,0,_FollowHeadOffset); - - // then look at this target - CVector dirToTarget = targetPos - (pos()+CVector(0,0, UserEntity->eyesHeight())); - if((dirToTarget.x != 0.0f) || (dirToTarget.y!=0.0f)) - { - dirToTarget.normalize(); - setHeadPitch(atan2(dirToTarget.z, sqrt(sqr(dirToTarget.x)+sqr(dirToTarget.y)))); - } - - // TestYoyo - /*if(ClientCfg.Fly!=0.f) - { - nlinfo("Uy: %.3f. Hp: %.3f. UPos:(%.3f,%.3f,%.3f). TPos:(%.3f,%.3f,%.3f)", - UserEntity->frontYaw(), UserEntity->getHeadPitch(), pos().x, pos().y, pos().z, - targetPos.x, targetPos.y, targetPos.z); - static float uy=0.f; - static float hp=0.f; - if( fabs(fmod(UserEntity->frontYaw()-uy, 2*Pi))>ClientCfg.Fly || - fabs(fmod(UserEntity->getHeadPitch()-hp, 2*Pi))>ClientCfg.Fly ) - { - nlinfo("YOYOBREAK: ^^^^^^^^^^"); - } - uy=UserEntity->frontYaw(); - hp=UserEntity->getHeadPitch(); - }*/ - } - } - } - // **** Third person - else if(viewMode()==ThirdPV) - { - // keep the current effective yaw. ONLY if no SmoothResetCameraYaw forced - if(!UserControls.isResetSmoothCDYForced()) - { - frontYawAfter = frontYaw(); - float deltaYaw= frontYawAfter - frontYawBefore; - - // compensate rotation (NB: it stops also any SmoothReset) - UserControls.appendCameraDeltaYaw(-deltaYaw); - } - } - - // when looking to an entity, if automatic camera, center the view on it. - if( ClientCfg.AutomaticCamera /*&& start*/ ) - { - UserControls.resetSmoothCameraDeltaYaw(); - } -} - - -// *************************************************************************** -void CUserEntity::startForceLookEntity(CLFECOMMON::TCLEntityId slot) -{ - // Start a new follow: force head pitch to follow by default - _FollowForceHeadPitch= true; - // if a follow is started in first person, reset CameraYaw - if(viewMode()==FirstPV) - UserControls.resetCameraDeltaYaw(); - - // reorient now (important else may have a time shift because of resetCameraDeltaYaw above) - CEntityCL *target = EntitiesMngr.entity(slot); - if(target) - { - /* For complex reason, the target may not be still snapped on the ground. snap it now - - this is because in common case, entities are snap only if they are visible (for speed up) - => depends on camera - - but in this case, the camera depends on real entity position (headPitch in first person) - */ - target->snapToGround(); - - // For FirstPerson targeting. Get the current target head offset - _FollowHeadOffset= 0.f; - CVector headPos; - if(target->getHeadPos(headPos)) - { - _FollowHeadOffset= headPos.z - float(target->pos().z); - } - - // Look at the entity - CVectorD dir2targ = target->pos() - pos(); - dir2targ.z = 0.0; - if(dir2targ!=CVectorD::Null) - { - forceLookEntity(dir2targ, true, true); - } - } -} - - -// *************************************************************************** -void CUserEntity::stopForceHeadPitchInFollow() -{ - _FollowForceHeadPitch= false; -} - -// *************************************************************************** -void CUserEntity::switchVelocity(bool userRequest) -{ - if (ClientCfg.R2EDEnabled && R2::getEditor().getMode() == R2::CEditor::EditionMode) - { - // when in the R2 editor, force to run all the time - _Run = true; - } - else - { - _Run = !_Run; - } - _CurrentVelocity = _Run ? runVelocity() : walkVelocity(); - - if (userRequest) - { - _RunWhenAble = _Run; - } - - // display message : your are running, you are walking - CInterfaceManager *pIM= CInterfaceManager::getInstance(); - ucstring msg; - if( _Run ) - msg = CI18N::get("msgUserIsRunning"); - else - msg = CI18N::get("msgUserIsWalking"); - string cat = getStringCategory(msg, msg); - pIM->displaySystemInfo(msg, cat); - - // Write to the UI database, to update views - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:VARIABLES:PLAYER_RUNNING", false); - if(node) - node->setValue32(_Run); -} - -//----------------------------------------------- -// autoEquipWithLastUsedWeapons -// -//----------------------------------------------- -void CUserEntity::autoEquipWithLastUsedWeapons() -{ - CInventoryManager *inv = CInventoryManager::getInstance(); - if ( !inv ) - { - return; - } - - // Clear hands - inv->unequip( "LOCAL:INVENTORY:HAND:1" ); - inv->unequip( "LOCAL:INVENTORY:HAND:0" ); - - uint ir,il; - // Equip right hand - if( _PreviousRightHandItem.Sheet != 0 ) - { - // find item in bag with same properties than last used one in right hand - for ( ir=0; irgetBagItem(ir).getSheetID() && - _PreviousRightHandItem.Quality == inv->getBagItem(ir).getQuality() && - _PreviousRightHandItem.Weight == inv->getBagItem(ir).getWeight() && - _PreviousRightHandItem.NameId == inv->getBagItem(ir).getNameId() ) - { - break; - } - } - if ( ir != MAX_BAGINV_ENTRIES ) - { - // Equip right hand - string bagPath = toString( "LOCAL:INVENTORY:BAG:%u", ir ); - inv->equip( bagPath, "LOCAL:INVENTORY:HAND:0" ); - - // Equip left hand if needed - if( _PreviousLeftHandItem.Sheet != 0 ) - { - for ( il=0; ilgetBagItem(il).getSheetID() && - _PreviousLeftHandItem.Quality == inv->getBagItem(il).getQuality() && - _PreviousLeftHandItem.Weight == inv->getBagItem(il).getWeight() && - _PreviousLeftHandItem.NameId == inv->getBagItem(il).getNameId() ) - { - break; - } - } - if ( il != MAX_BAGINV_ENTRIES ) - { - bagPath = toString( "LOCAL:INVENTORY:BAG:%u", il ); - inv->equip( bagPath, "LOCAL:INVENTORY:HAND:1" ); - } - } - return; - } - } - - - // TODO : choose the best one - -} - - -// *************************************************************************** -void CUserEntity::executeCombatWithPhrase(CEntityCL *target, uint32 memoryLine, uint32 memoryIndex, bool cyclic) -{ - nlassert(target); - CSPhraseManager *pPM= CSPhraseManager::getInstance(); - - // is a melee combat? - bool meleeCombat = false; - // empty hand => yes! - meleeCombat= true; - uint32 rightHandSheet = getInventory().getRightHandItemSheet(); - if(rightHandSheet) - meleeCombat = getInventory().isMeleeWeaponItem(rightHandSheet); - - // If melee combat, and if the user entity is not well placed for fight, or if it has changed his target - if( meleeCombat && - ( - !target->isPlacedToFight(pos(), front(), attackRadius() + ClientCfg.AttackDist) || - target->slot()!=_LastExecuteCombatSlot - ) - ) - { - _LastExecuteCombatSlot= target->slot(); - - // Cancel any follow - disableFollow(); - - // Launch the moveToCombatPhrase, canceling any old action client execution. - // NB: this will also force him to look at the entity - moveToCombatPhrase(target->slot(), 2.0, memoryLine, memoryIndex, cyclic); - - // And after (order is important), start the phrase execution on client - pPM->clientExecute(memoryLine, memoryIndex, cyclic); - } - else - { - // Cancel any moveTo(), because don't want to continue reaching the prec entity - // VERY important if previous MoveTo was a SPhrase MoveTo (because cancelClientExecute() must be called) - resetAnyMoveTo(); - - // start client execution: NB: start client execution even if it - pPM->clientExecute(memoryLine, memoryIndex, cyclic); - - // inform Server of phrase cast - pPM->sendExecuteToServer(memoryLine, memoryIndex, cyclic); - - if( !meleeCombat && !cyclic ) - { - pPM->executeDefaultAttack(); - } - } -} - -// *************************************************************************** -void CUserEntity::beginCast(const MBEHAV::CBehaviour &behaviour) -{ - if(viewMode()==ThirdPV) - { - // backup front yaw - float frontYawBefore = frontYaw(); - // begin cast - CCharacterCL::beginCast( behaviour ); - // compensate the front change using a camera move - float frontYawAfter = frontYaw(); - float deltaYaw= frontYawAfter - frontYawBefore; - UserControls.appendCameraDeltaYaw(-deltaYaw); - // if automatic camera, center the view behind the user - if( ClientCfg.AutomaticCamera ) - { - UserControls.resetSmoothCameraDeltaYaw(); - } - } - else - { - // in first person mode, reset the delta yaw - UserControls.resetCameraDeltaYaw(); - CCharacterCL::beginCast( behaviour ); - } -} - -// *************************************************************************** -void CUserEntity::updatePreCollision(const NLMISC::TTime &time, CEntityCL *target) -{ - CPlayerCL::updatePreCollision(time, target); - - // test each frame if the mode has changed - if(SoundMngr) - { - string deadMusic= "death.ogg"; - // Play/stop music if comes from or goes to dead - bool isDead= _Mode==MBEHAV::DEATH || _Mode==MBEHAV::SWIM_DEATH; - - // must start music? - if( isDead && SoundMngr->getEventMusicPlayed()!=deadMusic ) - { - SoundMngr->playEventMusic(deadMusic, 0, true); - } - - // must end music? - if( !isDead && SoundMngr->getEventMusicPlayed()==deadMusic ) - { - SoundMngr->stopEventMusic(deadMusic, CSoundManager::LoadingMusicXFade); - } - } -} - -// *************************************************************************** -void CUserEntity::buildTotem() -{ - const string msgName = "TOTEM:BUILD"; - CBitMemStream out; - if( GenericMsgHeaderMngr.pushNameToStream( msgName, out ) ) - { - NetMngr.push( out ); - nlinfo( "sending TOTEM:build message to server" ); - } -} - -// *************************************************************************** -void CUserEntity::setR2CharMode(R2::TCharMode mode) -{ - if (mode == R2::TCharMode::Editer || mode == R2::TCharMode::Dm) - { - _R2CharMode= mode; - walkVelocity(ClientCfg.DmWalk); - runVelocity(ClientCfg.DmRun); - View.setCameraDistanceMaxForDm(); - CEntityCL *user = EntitiesMngr.entity(0); - NLPACS::UMovePrimitive* prim = user?user->getPrimitive():0; - if (prim) - { - prim->setObstacle(false); - } - - } - else if (mode == R2::TCharMode::Player || mode == R2::TCharMode::Tester) - { - _R2CharMode= mode; - walkVelocity(ClientCfg.Walk); - runVelocity(ClientCfg.Run); - View.setCameraDistanceMaxForPlayer(); - CEntityCL *user = EntitiesMngr.entity(0); - NLPACS::UMovePrimitive* prim = user?user->getPrimitive():0; - if (prim) - { - prim->setObstacle(true); - } - } - else - { - nlwarning("R2Ed: Error Char Mode not handled %u", (uint32)mode.getValue()); - } -} - -bool CUserEntity::isInNpcControl() const -{ - CInterfaceManager* pIM = CInterfaceManager::getInstance(); - CCDBNodeLeaf *sheet = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:NPC_CONTROL:SHEET", false); - return sheet && NLMISC::CSheetId(sheet->getValue32())!=NLMISC::CSheetId::Unknown; -} - - -void CUserEntity::updateNpcContolSpeed() -{ - CInterfaceManager* pIM = CInterfaceManager::getInstance(); - CCDBNodeLeaf *sheet = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:NPC_CONTROL:SHEET", false); - CCDBNodeLeaf *walk = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:NPC_CONTROL:WALK", false); - CCDBNodeLeaf *run = NLGUI::CDBManager::getInstance()->getDbProp("SERVER:USER:NPC_CONTROL:RUN", false); - if (!sheet || !walk || !run) - { - return; - } - - static NLMISC::CSheetId oldSheet = NLMISC::CSheetId::Unknown; - static float oldRun=0.f; - static float oldWalk=0.f; - - NLMISC::CSheetId sheetId(sheet->getValue32()); - float newRun = float(run->getValue32()) / 1000.0f; - float newWalk = float(walk->getValue32()) / 1000.0f; - - if (sheetId == oldSheet && oldRun == newRun && oldWalk == newWalk ) - { - return; - } - - oldSheet = sheetId; - oldRun = newRun; - oldWalk = newWalk; - - if (sheetId != NLMISC::CSheetId::Unknown) - { - walkVelocity(newWalk); - runVelocity(newRun); - } - else - { - setR2CharMode(_R2CharMode); - } - -} - -//----------------------------------------------- -// cancelAllPhrases -//----------------------------------------------- -void CUserEntity::cancelAllPhrases() -{ - CBitMemStream out; - if(GenericMsgHeaderMngr.pushNameToStream("PHRASE:CANCEL_ALL", out)) - { - NetMngr.push(out); - } - else - { - nlwarning(" unknown message name '%s'", "PHRASE:CANCEL_ALL"); - } -} - - -//----------------------------------------------- -// canChangeFront -//----------------------------------------------- -bool CUserEntity::canChangeFront() -{ - return !(_CurrentBehaviour.Behaviour == MBEHAV::EXTRACTING - || (_CurrentBehaviour.Behaviour == MBEHAV::RANGE_ATTACK && _Mode==MBEHAV::COMBAT && !UserControls.isMoving()) - || (_CurrentBehaviour.Behaviour >= MBEHAV::MAGIC_CASTING_BEHAVIOUR_BEGIN && _CurrentBehaviour.Behaviour <= MBEHAV::MAGIC_CASTING_BEHAVIOUR_END)); -} - - -//----------------------------------------------- -// rememberWeaponsInHand -// -//----------------------------------------------- -void CUserEntity::rememberWeaponsInHand() -{ - CInventoryManager * inv = CInventoryManager::getInstance(); - if( !inv ) - { - return; - } - - // keep right hand item - CItemImage * rightItemImg = inv->getHandItem(0); - if( rightItemImg ) - { - if( inv->isMeleeWeaponItem(rightItemImg->getSheetID()) || inv->isRangeWeaponItem(rightItemImg->getSheetID()) ) - { - _PreviousRightHandItem = CItemSnapshot(*rightItemImg); - - // keep left hand item too (could be ammo, second weapon, etc ..) - CItemImage * leftItemImg = inv->getHandItem(1); - if( leftItemImg ) - { - _PreviousLeftHandItem = CItemSnapshot(*leftItemImg); - } - else - { - _PreviousLeftHandItem = CItemSnapshot(); - } - } - } -} - - -//----------------------------------------------- -// snapshot of a CItemImage -// -//----------------------------------------------- -CUserEntity::CItemSnapshot::CItemSnapshot( const CItemImage& i ) -{ - Sheet = i.getSheetID(); - Quality = i.getQuality(); - Quantity = i.getQuantity(); - UserColor = i.getUserColor(); - Price = i.getPrice(); - Weight = i.getWeight(); - NameId = i.getNameId(); - InfoVersion = i.getInfoVersion(); -} - -sint CUserEntity::getLevel() const -{ - CInterfaceManager *pIM = CInterfaceManager::getInstance(); - sint level = -1; - for(uint i=0;igetDbProp(toString("SERVER:USER:SKILL_POINTS_%d:VALUE", i), false); - if(node) - { - level = std::max(level, (sint) node->getValue32()); - } - } - return level; -} - -//----------------------------------------------- -// interlocutor -//----------------------------------------------- -void CUserEntity::interlocutor( const CLFECOMMON::TCLEntityId &slot) -{ - CLFECOMMON::TCLEntityId prevInterlocutor = _Interlocutor; - _Interlocutor = slot; - - // Refresh (hide or unhide) the icon for the interlocutor NPC - if (prevInterlocutor != CLFECOMMON::INVALID_SLOT) - EntitiesMngr.refreshInsceneInterfaceOfFriendNPC(prevInterlocutor); - if (_Interlocutor != CLFECOMMON::INVALID_SLOT) - EntitiesMngr.refreshInsceneInterfaceOfFriendNPC(_Interlocutor); -} - -//----------------------------------------------- -// trader -//----------------------------------------------- -void CUserEntity::trader(const CLFECOMMON::TCLEntityId &slot) -{ - CLFECOMMON::TCLEntityId prevTrader = _Trader; - _Trader = slot; - - // Refresh (hide or unhide) the icon for the trader NPC - if (prevTrader != CLFECOMMON::INVALID_SLOT) - EntitiesMngr.refreshInsceneInterfaceOfFriendNPC(prevTrader); - if (_Trader != CLFECOMMON::INVALID_SLOT) - EntitiesMngr.refreshInsceneInterfaceOfFriendNPC(_Trader); -} -