Pol  Revision:cb584c9
tildecmd.cpp
Go to the documentation of this file.
1 
7 #include "tildecmd.h"
8 
9 #include <iostream>
10 #include <stdlib.h>
11 #include <string>
12 
13 #include <format/format.h>
14 #include "../clib/clib_endian.h"
15 #include "../clib/logfacility.h"
16 #include "../plib/systemstate.h"
17 #include "spells.h"
18 
19 namespace Pol
20 {
21 namespace Core
22 {
23 void invoke( Network::Client* client, const char* spellidstr )
24 {
25  u16 spellnum = static_cast<u16>( strtoul( spellidstr, nullptr, 0 ) );
26  do_cast( client, spellnum );
27 }
28 
29 void invoke( Network::Client* client, const u16* wspellidstr )
30 {
31  std::wstring wstr = L"";
32  for ( size_t i = 0; wspellidstr[i] != L'\0'; i++ )
33  wstr += static_cast<const wchar_t>( cfBEu16( wspellidstr[i] ) );
34  u16 spellnum = static_cast<u16>( wcstoul( wstr.c_str(), nullptr, 0 ) );
35  do_cast( client, spellnum );
36 }
37 
38 bool process_tildecommand( Network::Client* client, const char* textbuf )
39 {
40  if ( textbuf[0] == 'I' && textbuf[1] == 'N' )
41  {
42  INFO_PRINT_TRACE( 6 ) << "INVOKE: " << textbuf << "\n";
43 
44  invoke( client, textbuf + 2 );
45  return true;
46  }
47  return false;
48 }
49 
50 bool process_tildecommand( Network::Client* client, const u16* wtextbuf )
51 {
52  using std::wcout;
53 
54  if ( wtextbuf[0] == ctBEu16( L'I' ) && wtextbuf[1] == ctBEu16( L'N' ) )
55  {
56  if ( Plib::systemstate.config.loglevel >= 6 )
57  {
58  fmt::Writer tmp;
59  tmp << "INVOKE: ";
60  for ( size_t i = 0; wtextbuf[i] != L'\0'; i++ )
61  tmp << wcout.narrow( static_cast<wchar_t>( cfBEu16( wtextbuf[i] ) ), '?' );
62  tmp << "\n";
63  INFO_PRINT << tmp.str();
64  }
65 
66  invoke( client, wtextbuf + 2 );
67  return true;
68  }
69  return false;
70 }
71 }
72 }
SystemState systemstate
Definition: systemstate.cpp:12
bool process_tildecommand(Network::Client *client, const char *textbuf)
Definition: tildecmd.cpp:38
#define ctBEu16(x)
Definition: clib_endian.h:46
void invoke(Network::Client *client, const char *spellidstr)
Definition: tildecmd.cpp:23
void do_cast(Network::Client *client, u16 spellid)
Definition: spells.cpp:278
unsigned short u16
Definition: rawtypes.h:26
#define cfBEu16(x)
Definition: clib_endian.h:44
#define INFO_PRINT_TRACE(n)
Definition: logfacility.h:226
#define INFO_PRINT
Definition: logfacility.h:223
Definition: berror.cpp:12