@@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
32
32
#include " filesys.h"
33
33
#include " settings.h"
34
34
#include " util/auth.h"
35
+ #include " util/base64.h"
35
36
#include < algorithm>
36
37
37
38
// log([level,] text)
@@ -320,6 +321,34 @@ int ModApiUtil::l_decompress(lua_State *L)
320
321
return 1 ;
321
322
}
322
323
324
+ // encode_base64(string)
325
+ int ModApiUtil::l_encode_base64 (lua_State *L)
326
+ {
327
+ NO_MAP_LOCK_REQUIRED;
328
+
329
+ size_t size;
330
+ const char *data = luaL_checklstring (L, 1 , &size);
331
+
332
+ std::string out = base64_encode ((const unsigned char *)(data), size);
333
+
334
+ lua_pushlstring (L, out.data (), out.size ());
335
+ return 1 ;
336
+ }
337
+
338
+ // decode_base64(string)
339
+ int ModApiUtil::l_decode_base64 (lua_State *L)
340
+ {
341
+ NO_MAP_LOCK_REQUIRED;
342
+
343
+ size_t size;
344
+ const char *data = luaL_checklstring (L, 1 , &size);
345
+
346
+ std::string out = base64_decode (std::string (data, size));
347
+
348
+ lua_pushlstring (L, out.data (), out.size ());
349
+ return 1 ;
350
+ }
351
+
323
352
// mkdir(path)
324
353
int ModApiUtil::l_mkdir (lua_State *L)
325
354
{
@@ -433,6 +462,9 @@ void ModApiUtil::Initialize(lua_State *L, int top)
433
462
API_FCT (get_dir_list);
434
463
435
464
API_FCT (request_insecure_environment);
465
+
466
+ API_FCT (encode_base64);
467
+ API_FCT (decode_base64);
436
468
}
437
469
438
470
void ModApiUtil::InitializeAsync (AsyncEngine& engine)
@@ -459,5 +491,8 @@ void ModApiUtil::InitializeAsync(AsyncEngine& engine)
459
491
460
492
ASYNC_API_FCT (mkdir);
461
493
ASYNC_API_FCT (get_dir_list);
494
+
495
+ ASYNC_API_FCT (encode_base64);
496
+ ASYNC_API_FCT (decode_base64);
462
497
}
463
498
1 commit comments
HybridDog commentedon Jul 18, 2016
@red-001 Since complex Unicode text can't always be put into clipboard, can this be used to send custom player skins to the server (
/send_skin <ctrl+v>
)?