Skip to content

Commit 36f9556

Browse files
committed
第一次提交
1 parent 4c76149 commit 36f9556

File tree

616 files changed

+151856
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

616 files changed

+151856
-0
lines changed

.DS_Store

10 KB
Binary file not shown.

common/.DS_Store

6 KB
Binary file not shown.

common/game_proto.lua

+4,244
Large diffs are not rendered by default.

common/login_proto.lua

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
--[[
2+
login protocol
3+
4+
we may use srp in the future.
5+
srp can achieve no password login.
6+
this is commonly used by programmers such as "ssh login".
7+
8+
author: tangyiyang
9+
]]
10+
11+
local login_proto = {}
12+
13+
login_proto.c2s = [[
14+
.package {
15+
type 0 : integer
16+
session 1 : integer
17+
}
18+
19+
.server_info {
20+
name 0 : string
21+
host 1 : string
22+
port 2 : integer
23+
}
24+
25+
auth 1 {
26+
request {
27+
user_id 0 : string
28+
}
29+
30+
response {
31+
ok 0 : boolean
32+
error_code 1 : integer
33+
user_id 2 : string
34+
token 3 : string
35+
game_server_info 4: server_info
36+
}
37+
}
38+
39+
40+
auth_old 2 {
41+
request {
42+
username 0 : string
43+
password 1 : string # encrypted password.
44+
}
45+
response {
46+
ok 0 : boolean
47+
token 1 : string
48+
error_code 2 : integer
49+
}
50+
}
51+
52+
]]
53+
54+
login_proto.s2c = [[
55+
.package {
56+
type 0 : integer
57+
session 1 : integer
58+
}
59+
]]
60+
61+
return login_proto

lib/.DS_Store

10 KB
Binary file not shown.

lib/lua-aes/lua-aes.c

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include <lua.h>
2+
#include <lauxlib.h>
3+
4+
#include <openssl/evp.h>
5+
#include <openssl/md5.h>
6+
#include <openssl/aes.h>
7+
8+
#define AES_KEY_LENGTH 16
9+
10+
static int
11+
lencrypt (lua_State *L) {
12+
size_t len = 0;
13+
const char *text = lua_tolstring (L, 1, &len);
14+
const char *key = lua_tostring (L, 2);
15+
16+
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
17+
unsigned char iv[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
18+
char *output = malloc (len + AES_BLOCK_SIZE);
19+
int olen1;
20+
int olen2;
21+
22+
EVP_EncryptInit (ctx, EVP_aes_256_cbc(), (unsigned char *)key, iv);
23+
EVP_EncryptUpdate (ctx, (unsigned char *)output, &olen1, (const unsigned char *)text, len);
24+
int ok = EVP_EncryptFinal (ctx, (unsigned char *)output + olen1, &olen2);
25+
if (!ok) {
26+
free (output);
27+
EVP_CIPHER_CTX_free (ctx);
28+
return 0;
29+
}
30+
31+
lua_pushlstring (L, output, olen1 + olen2);
32+
free (output);
33+
EVP_CIPHER_CTX_free (ctx);
34+
return 1;
35+
}
36+
37+
static int
38+
ldecrypt (lua_State *L) {
39+
size_t len = 0;
40+
const char *text = lua_tolstring (L, 1, &len);
41+
const char *key = lua_tostring (L, 2);
42+
43+
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
44+
unsigned char iv[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
45+
char *output = malloc (len);
46+
int olen1;
47+
int olen2;
48+
49+
EVP_DecryptInit (ctx, EVP_aes_256_cbc(), (unsigned char *)key, iv);
50+
EVP_DecryptUpdate (ctx, (unsigned char *)output, &olen1, (const unsigned char *)text, len);
51+
int ok = EVP_DecryptFinal (ctx, (unsigned char *)(output + olen1), &olen2);
52+
if (!ok) {
53+
free (output);
54+
fprintf(stderr, "lua-aes error: aes decript failed, error code = %d\n", ok);
55+
EVP_CIPHER_CTX_free (ctx);
56+
return 0;
57+
}
58+
59+
lua_pushlstring (L, output, olen1 + olen2);
60+
free (output);
61+
EVP_CIPHER_CTX_free (ctx);
62+
return 1;
63+
}
64+
65+
int
66+
luaopen_aes (lua_State *L) {
67+
luaL_checkversion (L);
68+
luaL_Reg l[] = {
69+
{ "encrypt", lencrypt },
70+
{ "decrypt", ldecrypt },
71+
{ NULL, NULL },
72+
};
73+
luaL_newlib (L,l);
74+
return 1;
75+
}

lib/lua-cjson/.DS_Store

6 KB
Binary file not shown.

lib/lua-cjson/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.so

lib/lua-cjson/CMakeLists.txt

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# If Lua is installed in a non-standard location, please set the LUA_DIR
2+
# environment variable to point to prefix for the install. Eg:
3+
# Unix: export LUA_DIR=/home/user/pkg
4+
# Windows: set LUA_DIR=c:\lua51
5+
6+
project(lua-cjson C)
7+
cmake_minimum_required(VERSION 2.6)
8+
9+
option(USE_INTERNAL_FPCONV "Use internal strtod() / g_fmt() code for performance")
10+
option(MULTIPLE_THREADS "Support multi-threaded apps with internal fpconv - recommended" ON)
11+
12+
if(NOT CMAKE_BUILD_TYPE)
13+
set(CMAKE_BUILD_TYPE Release CACHE STRING
14+
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
15+
FORCE)
16+
endif()
17+
18+
find_package(Lua51 REQUIRED)
19+
include_directories(${LUA_INCLUDE_DIR})
20+
21+
if(NOT USE_INTERNAL_FPCONV)
22+
# Use libc number conversion routines (strtod(), sprintf())
23+
set(FPCONV_SOURCES fpconv.c)
24+
else()
25+
# Use internal number conversion routines
26+
add_definitions(-DUSE_INTERNAL_FPCONV)
27+
set(FPCONV_SOURCES g_fmt.c dtoa.c)
28+
29+
include(TestBigEndian)
30+
TEST_BIG_ENDIAN(IEEE_BIG_ENDIAN)
31+
if(IEEE_BIG_ENDIAN)
32+
add_definitions(-DIEEE_BIG_ENDIAN)
33+
endif()
34+
35+
if(MULTIPLE_THREADS)
36+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
37+
find_package(Threads REQUIRED)
38+
if(NOT CMAKE_USE_PTHREADS_INIT)
39+
message(FATAL_ERROR
40+
"Pthreads not found - required by MULTIPLE_THREADS option")
41+
endif()
42+
add_definitions(-DMULTIPLE_THREADS)
43+
endif()
44+
endif()
45+
46+
# Handle platforms missing isinf() macro (Eg, some Solaris systems).
47+
include(CheckSymbolExists)
48+
CHECK_SYMBOL_EXISTS(isinf math.h HAVE_ISINF)
49+
if(NOT HAVE_ISINF)
50+
add_definitions(-DUSE_INTERNAL_ISINF)
51+
endif()
52+
53+
set(_MODULE_LINK "${CMAKE_THREAD_LIBS_INIT}")
54+
get_filename_component(_lua_lib_dir ${LUA_LIBRARY} PATH)
55+
56+
if(APPLE)
57+
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
58+
"${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup")
59+
endif()
60+
61+
if(WIN32)
62+
# Win32 modules need to be linked to the Lua library.
63+
set(_MODULE_LINK ${LUA_LIBRARY} ${_MODULE_LINK})
64+
set(_lua_module_dir "${_lua_lib_dir}")
65+
# Windows sprintf()/strtod() handle NaN/inf differently. Not supported.
66+
add_definitions(-DDISABLE_INVALID_NUMBERS)
67+
else()
68+
set(_lua_module_dir "${_lua_lib_dir}/lua/5.1")
69+
endif()
70+
71+
add_library(cjson MODULE lua_cjson.c strbuf.c ${FPCONV_SOURCES})
72+
set_target_properties(cjson PROPERTIES PREFIX "")
73+
target_link_libraries(cjson ${_MODULE_LINK})
74+
install(TARGETS cjson DESTINATION "${_lua_module_dir}")
75+
76+
# vi:ai et sw=4 ts=4:

lib/lua-cjson/Makefile

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
##### Available defines for CJSON_CFLAGS #####
2+
##
3+
## USE_INTERNAL_ISINF: Workaround for Solaris platforms missing isinf().
4+
## DISABLE_INVALID_NUMBERS: Permanently disable invalid JSON numbers:
5+
## NaN, Infinity, hex.
6+
##
7+
## Optional built-in number conversion uses the following defines:
8+
## USE_INTERNAL_FPCONV: Use builtin strtod/dtoa for numeric conversions.
9+
## IEEE_BIG_ENDIAN: Required on big endian architectures.
10+
## MULTIPLE_THREADS: Must be set when Lua CJSON may be used in a
11+
## multi-threaded application. Requries _pthreads_.
12+
13+
##### Build defaults #####
14+
LUA_VERSION = 5.1
15+
TARGET = cjson.so
16+
PREFIX = /usr/local
17+
#CFLAGS = -g -Wall -pedantic -fno-inline
18+
CFLAGS = -O3 -Wall -pedantic -DNDEBUG
19+
CJSON_CFLAGS = -fpic
20+
CJSON_LDFLAGS = -shared
21+
LUA_INCLUDE_DIR = $(PREFIX)/include
22+
LUA_CMODULE_DIR = $(PREFIX)/lib/lua/$(LUA_VERSION)
23+
LUA_MODULE_DIR = $(PREFIX)/share/lua/$(LUA_VERSION)
24+
LUA_BIN_DIR = $(PREFIX)/bin
25+
26+
##### Platform overrides #####
27+
##
28+
## Tweak one of the platform sections below to suit your situation.
29+
##
30+
## See http://lua-users.org/wiki/BuildingModules for further platform
31+
## specific details.
32+
33+
## Linux
34+
35+
## FreeBSD
36+
#LUA_INCLUDE_DIR = $(PREFIX)/include/lua51
37+
38+
## MacOSX (Macports)
39+
#PREFIX = /opt/local
40+
#CJSON_LDFLAGS = -bundle -undefined dynamic_lookup
41+
42+
## Solaris
43+
#PREFIX = /home/user/opt
44+
#CC = gcc
45+
#CJSON_CFLAGS = -fpic -DUSE_INTERNAL_ISINF
46+
47+
## Windows (MinGW)
48+
#TARGET = cjson.dll
49+
#PREFIX = /home/user/opt
50+
#CJSON_CFLAGS = -DDISABLE_INVALID_NUMBERS
51+
#CJSON_LDFLAGS = -shared -L$(PREFIX)/lib -llua51
52+
#LUA_BIN_SUFFIX = .lua
53+
54+
##### Number conversion configuration #####
55+
56+
## Use Libc support for number conversion (default)
57+
FPCONV_OBJS = fpconv.o
58+
59+
## Use built in number conversion
60+
#FPCONV_OBJS = g_fmt.o dtoa.o
61+
#CJSON_CFLAGS += -DUSE_INTERNAL_FPCONV
62+
63+
## Compile built in number conversion for big endian architectures
64+
#CJSON_CFLAGS += -DIEEE_BIG_ENDIAN
65+
66+
## Compile built in number conversion to support multi-threaded
67+
## applications (recommended)
68+
#CJSON_CFLAGS += -pthread -DMULTIPLE_THREADS
69+
#CJSON_LDFLAGS += -pthread
70+
71+
##### End customisable sections #####
72+
73+
TEST_FILES = README bench.lua genutf8.pl test.lua octets-escaped.dat \
74+
example1.json example2.json example3.json example4.json \
75+
example5.json numbers.json rfc-example1.json \
76+
rfc-example2.json types.json
77+
DATAPERM = 644
78+
EXECPERM = 755
79+
80+
ASCIIDOC = asciidoc
81+
82+
BUILD_CFLAGS = -I$(LUA_INCLUDE_DIR) $(CJSON_CFLAGS)
83+
OBJS = lua_cjson.o strbuf.o $(FPCONV_OBJS)
84+
85+
.PHONY: all clean install install-extra doc
86+
87+
.SUFFIXES: .html .txt
88+
89+
.c.o:
90+
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(BUILD_CFLAGS) -o $@ $<
91+
92+
.txt.html:
93+
$(ASCIIDOC) -n -a toc $<
94+
95+
all: $(TARGET)
96+
97+
doc: manual.html performance.html
98+
99+
$(TARGET): $(OBJS)
100+
$(CC) $(LDFLAGS) $(CJSON_LDFLAGS) -o $@ $(OBJS)
101+
102+
install: $(TARGET)
103+
mkdir -p $(DESTDIR)/$(LUA_CMODULE_DIR)
104+
cp $(TARGET) $(DESTDIR)/$(LUA_CMODULE_DIR)
105+
chmod $(EXECPERM) $(DESTDIR)/$(LUA_CMODULE_DIR)/$(TARGET)
106+
107+
install-extra:
108+
mkdir -p $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/tests \
109+
$(DESTDIR)/$(LUA_BIN_DIR)
110+
cp lua/cjson/util.lua $(DESTDIR)/$(LUA_MODULE_DIR)/cjson
111+
chmod $(DATAPERM) $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/util.lua
112+
cp lua/lua2json.lua $(DESTDIR)/$(LUA_BIN_DIR)/lua2json$(LUA_BIN_SUFFIX)
113+
chmod $(EXECPERM) $(DESTDIR)/$(LUA_BIN_DIR)/lua2json$(LUA_BIN_SUFFIX)
114+
cp lua/json2lua.lua $(DESTDIR)/$(LUA_BIN_DIR)/json2lua$(LUA_BIN_SUFFIX)
115+
chmod $(EXECPERM) $(DESTDIR)/$(LUA_BIN_DIR)/json2lua$(LUA_BIN_SUFFIX)
116+
cd tests; cp $(TEST_FILES) $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/tests
117+
cd tests; chmod $(DATAPERM) $(TEST_FILES); chmod $(EXECPERM) *.lua *.pl
118+
119+
clean:
120+
rm -f *.o $(TARGET)

0 commit comments

Comments
 (0)