Permalink
Browse files

[0.0-49] kicks are handled gracefully now; server can kick from the l…

…ua side; framework starting to be laid for ENet support
  • Loading branch information...
iamgreaser committed Jun 23, 2013
1 parent d03c7bb commit 087cfd1cea8fdf645199df6c798cb496809e7cd6
Showing with 203 additions and 46 deletions.
  1. +2 −1 Makefile
  2. +2 −1 Makefile.dedi
  3. +4 −1 Makefile.glmingw
  4. +4 −1 Makefile.mingw
  5. +2 −1 Makefile.opengl
  6. +5 −11 README.txt
  7. +17 −3 docs/modding_lua.txt
  8. +14 −2 include/common.h
  9. +21 −0 pkg/base/client_start.lua
  10. +10 −0 pkg/base/commands.lua
  11. +10 −0 pkg/base/main_client.lua
  12. +5 −3 pkg/base/version.lua
  13. +1 −0 src/lua.c
  14. +34 −0 src/lua_net.h
  15. +71 −21 src/network.c
  16. +1 −1 zipdist.sh
View
@@ -12,11 +12,12 @@ HEADERS_Lua = #-I /usr/include/lua5.1
LDFLAGS = -pg -g $(LDFLAGS_EXTRA) -fopenmp
LIBS_SDL = `sdl-config --libs`
+LIBS_ENet = xlibinc/libenet.a
LIBS_Lua = -llua
# Lua is not an acronym. Get used to typing it with lower case u/a.
LIBS_zlib = -lz
LIBS_sackit = -lsackit
-LIBS = -Lxlibinc -lm $(LIBS_Lua) $(LIBS_SDL) $(LIBS_zlib) $(LIBS_sackit)
+LIBS = -Lxlibinc -lm $(LIBS_Lua) $(LIBS_SDL) $(LIBS_zlib) $(LIBS_sackit) $(LIBS_ENet)
BINNAME = iceball
View
@@ -10,11 +10,12 @@ CFLAGS = -DDEDI -pg -O2 -fno-strict-aliasing -g -Wall -Wextra \
HEADERS_Lua =
LDFLAGS = -pg -g -fopenmp $(LDFLAGS_EXTRA)
+LIBS_ENet = xlibinc/libenet.a
LIBS_Lua = -llua
# Lua is not an acronym. Get used to typing it with lower case u/a.
LIBS_zlib = -lz
LIBS_sackit = -lsackit
-LIBS = -Lxlibinc/ -lm $(LIBS_Lua) $(LIBS_zlib) $(LIBS_sackit)
+LIBS = -Lxlibinc/ -lm $(LIBS_Lua) $(LIBS_zlib) $(LIBS_sackit) $(LIBS_ENet)
BINNAME = dedi_iceball
OBJDIR = build/dedi
View
@@ -7,6 +7,8 @@
# - Stash Lua includes in winlibs/*.h.
# - lua.h, lualib.h, lauxlib.h, luaconf.h
# - Stash sackit.h and libsackit.a in winlibs/.
+# - Stash libenet.a in winlibs/.
+# - Stash ENet includes from enet/*.h in winlibs/enet/*.h.
#
CFLAGS = -O2 -fno-strict-aliasing -g -Wall -Wextra \
@@ -20,12 +22,13 @@ CFLAGS = -O2 -fno-strict-aliasing -g -Wall -Wextra \
LDFLAGS = -g $(LDFLAGS_EXTRA)
LIBS_SDL = -lSDLmain -lSDL
+LIBS_ENet = winlibs/libenet.a
LIBS_Lua = -llua
LIBS_Winsuck = -lws2_32
# Lua is not an acronym. Get used to typing it with lower case u/a.
LIBS_zlib = -lz
LIBS_sackit = -lsackit
-LIBS = -Lwinlibs -lm -lmingw32 $(LIBS_Lua) $(LIBS_SDL) $(LIBS_zlib) $(LIBS_Winsuck) $(LIBS_sackit) ./glew32.dll -lopengl32
+LIBS = -Lwinlibs -lm -lmingw32 $(LIBS_Lua) $(LIBS_SDL) $(LIBS_zlib) $(LIBS_Winsuck) $(LIBS_sackit) ./glew32.dll -lopengl32 $(LIBS_ENet)
BINNAME = iceball-gl.exe
RENDERER = gl
View
@@ -7,6 +7,8 @@
# - Stash Lua includes in winlibs/*.h.
# - lua.h, lualib.h, lauxlib.h, luaconf.h
# - Stash sackit.h and libsackit.a in winlibs/.
+# - Stash libenet.a in winlibs/.
+# - Stash ENet includes from enet/*.h in winlibs/enet/*.h.
#
CFLAGS = -O2 -fno-strict-aliasing -g -Wall -Wextra \
@@ -20,12 +22,13 @@ CFLAGS = -O2 -fno-strict-aliasing -g -Wall -Wextra \
LDFLAGS = -g -fopenmp $(LDFLAGS_EXTRA)
LIBS_SDL = -lSDLmain -lSDL
+LIBS_ENet = winlibs/libenet.a
LIBS_Lua = -llua
LIBS_Winsuck = -lws2_32
# Lua is not an acronym. Get used to typing it with lower case u/a.
LIBS_zlib = -lz
LIBS_sackit = -lsackit
-LIBS = -Lwinlibs -lm -lmingw32 $(LIBS_Lua) $(LIBS_SDL) $(LIBS_zlib) $(LIBS_Winsuck) $(LIBS_sackit)
+LIBS = -Lwinlibs -lm -lmingw32 $(LIBS_Lua) $(LIBS_SDL) $(LIBS_zlib) $(LIBS_Winsuck) $(LIBS_sackit) $(LIBS_ENet)
BINNAME = iceball.exe
OBJDIR = build/mingw32
View
@@ -12,11 +12,12 @@ HEADERS_Lua = #-I /usr/include/lua5.1
LDFLAGS = -pg -g $(LDFLAGS_EXTRA)
LIBS_SDL = `sdl-config --libs`
+LIBS_ENet = xlibinc/libenet.a
LIBS_Lua = -llua
# Lua is not an acronym. Get used to typing it with lower case u/a.
LIBS_zlib = -lz
LIBS_sackit = -lsackit
-LIBS = -Lxlibinc -lm $(LIBS_Lua) $(LIBS_SDL) $(LIBS_zlib) $(LIBS_sackit) -lGL -lGLEW
+LIBS = -Lxlibinc -lm $(LIBS_Lua) $(LIBS_SDL) $(LIBS_zlib) $(LIBS_sackit) -lGL -lGLEW $(LIBS_ENet)
BINNAME = iceball-gl
RENDERER = gl
View
@@ -1,19 +1,12 @@
GUYS GUYS GUYS
FIRST THING YOU NEED TO READ:
-docs/READ_THIS_FIRST.txt might work.
+docs/READ_THIS_FIRST.txt might work (OK, it's out of date right now. Try running the tutorial.)
If not, there's a tutorial on the forums:
http://iceballga.me
------------------------------------------------------------------------------
-This is FINALLY a game, BUT is not ready to be released yet.
-
-NOTE:
-By Stack's request, this project is now known as "Iceball".
-
-mesa.vxl is by Triplefox, and is currently being used to test load/render.
-
LICENSING NOTES:
Iceball is licensed under the regular GNU GPL version 3.
Ice Lua Components is licensed under the LGPL version 3.
@@ -42,6 +35,7 @@ REQUIREMENTS:
- zlib - http://zlib.net/
- sackit - https://github.com/iamgreaser/sackit/
- you should copy libsackit.a and sackit.h to xlibinc.
+- enet 1.3 - http://enet.bespin.org/
- GNU make
- if someone has BSD make, please tell us :)
@@ -52,10 +46,10 @@ STUFF TO DO BEFORE 0.1 CAN BE RELEASED:
- make kicking not suck
MSVC readme (wip):
-- create a folder 'winlibs' in the buldenthesnip dir
+- create a folder 'winlibs' in the iceball dir
dump all dll's + lib's in this folder (opengl,lua,zlib, sdl, glew)
dump all includes in submaps (glew in glew submap, and so on)
- /buldenthesnip/
+ /iceball/
/winlibs/
/glew/
/lua/
@@ -79,7 +73,7 @@ for the git starters:
- git update-index --assume-unchanged clsave\pub\user.json
and to get updates from the main repo:
-- git remote add upstream git://github.com/iamgreaser/buldthensnip.git
+- git remote add upstream git://github.com/iamgreaser/iceball.git
- git pull --rebase upstream master
- git push origin master
View
@@ -520,22 +520,36 @@ success = common.net_send(sockfd, str) @
"sockfd" is ignored C->S and should be nil
S->C local multiplayer should set "sockfd" to "true"
+ COMPATIBILITY WARNING:
+ [ writing this before I actually do it --GM ]
+ before 0.0-50, sockfd pertains to an ACTUAL sockfd.
+ from 0.0-50 onwards, sockfd pertains to a CLIENT HANDLE.
+
+ this should not be of any concern to you unless you do Really Stupid Stuff.
+ having said that, DO NOT EXPECT THIS TO BE A ONE-TO-ONE MAPPING TO CLIENT INDICES.
+
+ oh, and as expected, same applies to common.net_recv and every other case you see a sockfd.
+
str, sockfd = common.net_recv() @
receives a packet
for C->S "sockfd" is nil
S->C local multiplayer will result in "sockfd" being "true"
- returns nil if nothing is there
+ returns nil, nil if nothing is there
+ returns false, nil on the client if the connection was terminated
-server.net_kick(sockfd, reason)
+server.net_kick(sockfd, reason) @
kicks a client from the server
- fails silently if sockfd is invalid,
+ fails silently if sockfd is invalid (but still a plausible parameter),
or sockfd is closed / errors out
throws a lua error for other weird errors.
+client.hook_kick = fn(reason) @
+ sets a hook called when the player gets kicked
+
wav = common.wav_load(fname) @
loads a sound with filename "fname"
remember to free it when you're done
View
@@ -19,7 +19,7 @@
#define VERSION_X 0
#define VERSION_Y 0
#define VERSION_A 0
-#define VERSION_Z 48
+#define VERSION_Z 49
// Remember to bump "Z" basically every time you change the engine!
// Remember to bump the version in Lua too!
// Remember to document API changes in a new version!
@@ -76,6 +76,8 @@ typedef unsigned __int64 uint64_t;
#include <math.h>
+#include <enet/enet.h>
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -108,6 +110,9 @@ extern "C" {
// just so we can get getaddrinfo
// you will need Windows 2000 at least!
+#ifdef _WIN32_WINNT
+#undef _WIN32_WINNT
+#endif
#define _WIN32_WINNT 0x0501
#include <windows.h>
#include <winsock2.h>
@@ -355,10 +360,14 @@ struct packet
typedef struct client
{
+ // legacy proto only
packet_t *head, *tail;
packet_t *send_head, *send_tail;
int sockfd;
int isfull;
+
+ // enet proto only
+ ENetPeer *peer;
// client only
char *cfetch_ubuf;
@@ -374,7 +383,7 @@ typedef struct client
int sfetch_cpos;
int sfetch_udtype;
- // serialisation
+ // serialisation - legacy proto only
char rpkt_buf[PACKET_LEN_MAX*2];
int rpkt_len;
char spkt_buf[PACKET_LEN_MAX*2];
@@ -384,6 +393,7 @@ typedef struct client
#define SOCKFD_NONE -1
#define SOCKFD_LOCAL -2
+#define SOCKFD_ENET -3
enum
{
@@ -498,6 +508,8 @@ int net_packet_push(int len, const char *data, int sockfd, packet_t **head, pack
int net_packet_push_lua(int len, const char *data, int sockfd, packet_t **head, packet_t **tail);
packet_t *net_packet_pop(packet_t **head, packet_t **tail);
void net_packet_free(packet_t *pkt, packet_t **head, packet_t **tail);
+void net_kick_sockfd_immediate(int sockfd, const char *msg);
+void net_kick_client_immediate(client_t *cli, const char *msg);
void net_flush(void);
int net_connect(void);
void net_disconnect(void);
View
@@ -858,6 +858,27 @@ client.hook_mouse_button = h_mouse_button
client.hook_mouse_motion = h_mouse_motion
client.hook_window_activate = h_window_activate
+function client.hook_kick(reason)
+ print("Kicked - "..reason)
+ function client.hook_tick()
+ client.mouse_lock_set(false)
+ client.mouse_visible_set(true)
+ return 0.01
+ end
+ local old_render = client.hook_render
+ local new_render = nil
+ function new_render_fn(...)
+ client.hook_render = old_render
+ local ret = client.hook_render(...)
+ old_render = client.hook_render
+ client.hook_render = new_render
+ font_large.print(30, 30, 0xFFAA0000, "KICKED")
+ font_mini.print(30, 65, 0xFFAA0000, reason)
+ end
+ new_render = new_render_fn
+ client.hook_render = new_render
+end
+
print("pkg/base/client_start.lua loaded.")
--dofile("pkg/base/plug_snow.lua")
View
@@ -82,6 +82,16 @@ command_register({
end
})
+-- for testing. not like it can be abused. well, i hope it can't be abused. --GM
+command_register({
+ command = "kickme",
+ permission = nil,
+ usage = "/kickme",
+ func = function(plr, plrid, sockfd, prms, msg)
+ server.net_kick(sockfd, "requested!")
+ end
+})
+
command_register({
command = "me",
permission = "me",
View
@@ -15,6 +15,16 @@
along with Ice Lua Components. If not, see <http://www.gnu.org/licenses/>.
]]
+function client.hook_kick(reason)
+ print("Kicked - "..reason)
+ function client.hook_tick()
+ error("Kicked - "..reason)
+ end
+ function client.hook_render()
+ error("Kicked - "..reason)
+ end
+end
+
dofile("pkg/base/preconf.lua")
-- if you don't want music, set FILE_MUSIC to "true".
View
@@ -16,9 +16,9 @@
]]
VERSION_ENGINE = {
- cmp={0,0,0,0,48},
- num=48,
- str="0.0-48",
+ cmp={0,0,0,0,49},
+ num=49,
+ str="0.0-49",
}
VERSION_BUGS = {
@@ -74,5 +74,7 @@ VERSION_BUGS = {
{renderer="gl", intro=nil, fix=48, msg="[OpenGL] Chunk count is static and does not adapt to different fog values"},
{intro=nil, fix=48, msg="No way to determine from the Lua end what renderer a client is using"},
{renderer="gl", intro=nil, fix=48, msg="[OpenGL] Chunk generation pattern kinda sucks"},
+{intro=nil, fix=49, msg="Kick not handled gracefully"},
+{intro=49, fix=nil, msg="Kick message isn't communicated properly"},
}
View
@@ -166,6 +166,7 @@ struct icelua_entry icelua_common_client[] = {
#endif
struct icelua_entry icelua_common_server[] = {
+ {icelua_fn_server_net_kick, "net_kick"},
{NULL, NULL}
};
View
@@ -370,7 +370,14 @@ int icelua_fn_common_net_recv(lua_State *L)
} else {
packet_t *pkt = net_packet_pop(&(to_client_local.head), &(to_client_local.tail));
if(pkt == NULL)
+ {
+ if(to_client_local.sockfd == SOCKFD_NONE)
+ {
+ lua_pushboolean(L, 0);
+ return 1;
+ }
return 0;
+ }
if(pkt->data[0] >= 0x40 && pkt->data[0] <= 0x7E)
lua_pushlstring(L, &pkt->data[1], pkt->len-1);
@@ -386,3 +393,30 @@ int icelua_fn_common_net_recv(lua_State *L)
return 2;
}
}
+
+int icelua_fn_server_net_kick(lua_State *L)
+{
+ int top = icelua_assert_stack(L, 2, 2);
+
+ const char *msg = lua_tostring(L, 2);
+ if(msg == NULL)
+ return luaL_error(L, "not a string");
+
+ if(lua_isboolean(L, 1) && lua_toboolean(L, 1))
+ {
+ // local player kick
+ net_kick_sockfd_immediate(SOCKFD_LOCAL, msg);
+ } else if(lua_isnumber(L, 1)) {
+ // remote player kick
+ int sockfd = lua_tointeger(L, 1);
+ if(sockfd >= 0)
+ net_kick_sockfd_immediate(sockfd, msg);
+ else
+ return luaL_error(L, "invalid sockfd");
+ } else {
+ return luaL_error(L, "invalid sockfd");
+ }
+
+ return 0;
+}
+
Oops, something went wrong.

0 comments on commit 087cfd1

Please sign in to comment.