From f4091c5c6b53514583bcdedb3e02836a5bde82a2 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Tue, 28 Jul 2020 23:24:17 +0200 Subject: [PATCH] add missing header, expose GoOnline to lua --- CMakeLists.txt | 2 + src/include/online_service.h | 6 +++ src/network/online_service.cpp | 4 +- src/network/xsha1.h | 77 ++++++++++++++++++++++++++++++++++ src/tolua/online_service.pkg | 3 ++ 5 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 src/include/online_service.h create mode 100644 src/network/xsha1.h create mode 100644 src/tolua/online_service.pkg diff --git a/CMakeLists.txt b/CMakeLists.txt index a9ebc8a64..d60679d1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -363,6 +363,7 @@ source_group(win32 FILES ${win32_SRCS}) set(tolua_FILES src/tolua/ai.pkg src/tolua/editor.pkg + src/tolua/online_service.pkg src/tolua/font.pkg src/tolua/game.pkg src/tolua/map.pkg @@ -527,6 +528,7 @@ set(stratagus_generic_HDRS src/include/cursor.h src/include/depend.h src/include/editor.h + src/include/online_service.h src/include/font.h src/include/game.h src/include/icons.h diff --git a/src/include/online_service.h b/src/include/online_service.h new file mode 100644 index 000000000..12d14f22e --- /dev/null +++ b/src/include/online_service.h @@ -0,0 +1,6 @@ +#ifndef __ONLINE_SERVICE_H__ +#define __ONLINE_SERVICE_H__ + +void GoOnline(); + +#endif // !__EDITOR_H__ diff --git a/src/network/online_service.cpp b/src/network/online_service.cpp index c383079df..ced60ff42 100644 --- a/src/network/online_service.cpp +++ b/src/network/online_service.cpp @@ -1,3 +1,5 @@ +#include "online_service.h" + #include #include #include @@ -1526,7 +1528,7 @@ class PasswordInputListener : public gcn::ActionListener { } }; -static void GoOnline() { +void GoOnline() { std::string nc, rc; GetDefaultTextColors(nc, rc); diff --git a/src/network/xsha1.h b/src/network/xsha1.h new file mode 100644 index 000000000..75bfb3e4c --- /dev/null +++ b/src/network/xsha1.h @@ -0,0 +1,77 @@ +/* +MBNCSUtil -- Managed Battle.net Authentication Library +Copyright (C) 2005-2008 by Robert Paveza +X-SHA-1 ported to C by wjlafrance, January 3rd 2013. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1.) Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +2.) Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. +3.) The name of the author may not be used to endorse or promote products derived +from this software without specific prior written permission. + +See LICENSE.TXT that should have accompanied this software for full terms and +conditions. +*/ + +#include +#include +#include + +uint32_t ROL(uint32_t val, uint32_t shift) { + shift &= 0x1f; + val = (val >> (0x20 - shift)) | (val << shift); + return val; +} + +void xsha1_calcHashDat(uint32_t* data, uint32_t* result) { + for (int i = 16; i < 80; i++) { + data[i] = ROL(1, (int) (data[i-16] ^ data[i-8] ^ data[i-14] ^ data[i-3]) % 32); + } + + uint32_t A = 0x67452301; + uint32_t B = 0xefcdab89; + uint32_t C = 0x98badcfe; + uint32_t D = 0x10325476; + uint32_t E = 0xc3d2e1f0; + + uint32_t temp = 0; + for (int i = 0; i < 20; i++) { + temp = *data++ + ROL(A, 5) + E + ((B & C) | (~B & D)) + 0x5A827999; + E = D; D = C; C = ROL(B, 30); B = A; A = temp; + } + + for (int i = 0; i < 20; i++) { + temp = (D ^ C ^ B) + E + ROL(temp, 5) + *data++ + 0x6ed9eba1; + E = D; D = C; C = ROL(B, 30); B = A; A = temp; + } + + for (int i = 0; i < 20; i++) { + temp = *data++ + ROL(temp, 5) + E + ((C & B) | (D & C) | (D & B)) - 0x70E44324; + E = D; D = C; C = ROL(B, 30); B = A; A = temp; + } + + for (int i = 0; i < 20; i++) { + temp = (D ^ C ^ B) + E + ROL(temp, 5) + *data++ - 0x359d3e2a; + E = D; D = C; C = ROL(B, 30); B = A; A = temp; + } + + result[0] = A + 0x67452301; + result[1] = B + 0xefcdab89; + result[2] = C + 0x98badcfe; + result[3] = D + 0x10325476; + result[4] = E + 0xc3d2e1f0; +} + +void xsha1_calcHashBuf(const char* input, size_t length, uint32_t* result) { + void *dataptr = malloc(1024); + memset(dataptr, 0, 1024); + uint32_t *data = (uint32_t *) dataptr; + memcpy(data, input, length); + xsha1_calcHashDat(data, result); + free(dataptr); +} diff --git a/src/tolua/online_service.pkg b/src/tolua/online_service.pkg new file mode 100644 index 000000000..831419847 --- /dev/null +++ b/src/tolua/online_service.pkg @@ -0,0 +1,3 @@ +$#include "online_service.h" + +void GoOnline();