Browse files

Banner in config ausgelagert. + kleinkram

git-svn-id: http://infon.googlecode.com/svn/trunk@133 8171fb75-e542-0410-96e4-03d5dd800671
  • Loading branch information...
1 parent 8f8b888 commit 6e639027e4b877560eb123c0ba1052f127390b7e @dividuum committed Dec 15, 2006
Showing with 109 additions and 23 deletions.
  1. +9 −1 Makefile
  2. +15 −1 config.lua
  3. +9 −0 game.c
  4. +16 −5 infond.lua
  5. +4 −1 lua-5.1.1/src/lvm.c
  6. +32 −0 luacore.c
  7. +10 −0 player.lua
  8. +8 −0 server.c
  9. +6 −15 server.lua
View
10 Makefile
@@ -92,6 +92,14 @@ endif
$(INFOND_EXECUTABLE): CFLAGS += -Ilua-5.1.1/src/ # -DCHEATS
$(INFOND_EXECUTABLE): LDFLAGS += -levent -lz -lm
+# Experimental usage of 'all of lua in one file' as seen in lua-5.1.1/etc/all.c
+ifdef OPTIMIZE
+$(INFOND_EXECUTABLE): luacore.o
+luacore.o : CFLAGS += -DLUA_USE_POSIX
+else
+$(INFOND_EXECUTABLE): lua-5.1.1/src/liblua.a
+endif
+
$(SDL_RENDERER) : CFLAGS += -fPIC -I$(SDLDIR)/include/SDL
$(SDL_RENDERER) : LDFLAGS += -lSDL -lSDL_image -lSGE -lSDL_gfx
@@ -138,7 +146,7 @@ linux-client-dist: $(INFON_EXECUTABLE) $(SDL_RENDERER) $(NULL_RENDERER)
linux-server-dist: $(INFOND_EXECUTABLE)
tar cfvz infond-linux-i386-r$(REVISION).tgz README $(INFOND_EXECUTABLE) $(INFOND_EXECUTABLE)-static *.lua level/*.lua rules/*.lua
-$(INFOND_EXECUTABLE): infond.o server.o listener.o map.o path.o misc.o packet.o player.o world.o creature.o scroller.o game.o lua-5.1.1/src/liblua.a
+$(INFOND_EXECUTABLE): infond.o server.o listener.o map.o path.o misc.o packet.o player.o world.o creature.o scroller.o game.o
$(CC) $^ $(LDFLAGS) -o $@
$(CC) $^ $(LDFLAGS) -static -o $@-static
View
16 config.lua
@@ -34,4 +34,18 @@ acl = {{ pattern = "^ip:127\.0\..*" },
highlevel = { 'player-highlevel' }
-- show banner?
--- no_banner = true
+banner = [[
+ .___ `.
+ ___ `~\\ | \\
+ o~ `. | /' |
+ .----._ `| ,' /' _./'
+ `o `\\|___ __,|----'~~~~T-----,__ _,'~
+ /~~o `~>-/|~ ' ' , ' ' ~~\\_
+ |_ <~ | ' , ' ' ' ' , ' \\
+ `-...-'~\./' ' ' ' ' ' , ' >
+ `-, __' , ' ' , ' , '_,'-'
+ /' `~~~~~~~|`--------~~\\
+ /' ,' `.
+ ~~`---' / |
+ ,-' _/'
+]] -- von http://www.asciiworld.com/animals_birds.html
View
9 game.c
@@ -101,6 +101,11 @@ static int luaScrollerAdd(lua_State *L) {
return 0;
}
+static int luaShutdown(lua_State *L) {
+ game_exit = 1;
+ return 0;
+}
+
static int luaGameIntermission(lua_State *L) {
snprintf(intermission, sizeof(intermission), "%s", luaL_checkstring(L, 1));
game_send_intermission(SEND_BROADCAST);
@@ -150,6 +155,7 @@ void game_init() {
lua_register(L, "scroller_add", luaScrollerAdd);
lua_register(L, "hex_decode", luaHexDecode);
+ lua_register(L, "shutdown", luaShutdown);
lua_pushnumber(L, MAXPLAYERS);
lua_setglobal(L, "MAXPLAYERS");
@@ -210,6 +216,9 @@ void game_one_game() {
}
lasttick = tick;
+
+ // GC
+ lua_gc(L, LUA_GCSTEP, 1);
if (!game_paused) {
// Runde starten
View
21 infond.lua
@@ -326,6 +326,16 @@ function world_rotate_map()
map = maps[current_map]
end
+function world_get_dummy()
+ return {
+ level_size = function () return 3,3 end;
+ level_koth_pos = function () return 1,1 end;
+ level_init = function () end;
+ level_tick = function () end;
+ level_spawn_point = function () end;
+ }
+end
+
function world_load(map)
local world_code = assert(loadfile(PREFIX .. "level/" .. map .. ".lua"))
@@ -390,12 +400,13 @@ function world_init()
stats.num_maps = stats.num_maps + 1
local ok, w, h, kx, ky = pcall(world_load, map)
if not ok then
- world_tick = coroutine.wrap(function () while true do coroutine.yield() end end)
- error("cannot load world '" .. map .. "': " .. w .. ". using dummy world")
- else
- world_tick = coroutine.wrap(world_main)
- return w, h, kx, ky
+ print("cannot load world '" .. map .. "': " .. w .. ". using dummy world")
+ world = world_get_dummy()
+ w, h = world.level_size()
+ kx, ky = world.level_koth_pos()
end
+ world_tick = coroutine.wrap(world_main)
+ return w, h, kx, ky
end
function world_main()
View
5 lua-5.1.1/src/lvm.c
@@ -380,7 +380,10 @@ static void cpu_limit_exceeded(lua_State *L) {
lua_assert(L->ci->top <= L->stack_last);
lua_unlock(L);
lua_set_cycles(L, 0xFFFFFF);
- G(L)->cpu_exceeded(L);
+ if (G(L)->cpu_exceeded)
+ G(L)->cpu_exceeded(L);
+ else
+ lua_pushliteral(L, "cycles exceeded");
lua_set_cycles(L, cpu_exceeded_grace_cycles);
lua_error(L);
abort();
View
32 luacore.c
@@ -0,0 +1,32 @@
+#define luaall_c
+
+#include "lapi.c"
+#include "lcode.c"
+#include "ldebug.c"
+#include "ldo.c"
+#include "ldump.c"
+#include "lfunc.c"
+#include "lgc.c"
+#include "llex.c"
+#include "lmem.c"
+#include "lobject.c"
+#include "lopcodes.c"
+#include "lparser.c"
+#include "lstate.c"
+#include "lstring.c"
+#include "ltable.c"
+#include "ltm.c"
+#include "lundump.c"
+#include "lvm.c"
+#include "lzio.c"
+
+#include "lauxlib.c"
+#include "lbaselib.c"
+#include "ldblib.c"
+#include "liolib.c"
+#include "linit.c"
+#include "lmathlib.c"
+#include "loadlib.c"
+#include "loslib.c"
+#include "lstrlib.c"
+#include "ltablib.c"
View
10 player.lua
@@ -132,6 +132,16 @@ function info()
end
------------------------------------------------------------------------
+-- compatibility
+------------------------------------------------------------------------
+
+function nearest_enemy(...)
+ print(_TRACEBACK("calling 'nearest_enemy' is deprecated. use 'get_nearest_enemy' instead.", 2))
+ nearest_enemy = get_nearest_enemy
+ return get_nearest_enemy(...)
+end
+
+------------------------------------------------------------------------
-- Load Highlevel API
------------------------------------------------------------------------
View
8 server.c
@@ -53,6 +53,8 @@ static client_t *guiclients = NULL;
static client_t clients[MAXCLIENTS];
static client_t *output_client = NULL;
+static int traffic = 0;
+
static void server_readable(int fd, short event, void *arg);
static void server_writable(int fd, short event, void *arg);
@@ -243,6 +245,7 @@ void server_start_compression(client_t *client) {
void server_writeto(client_t *client, const void *data, size_t size) {
if (size == 0)
return;
+ traffic += size;
if (client->is_demo_dumper) {
write(client_num(client), data, size);
return;
@@ -500,6 +503,10 @@ static int luaClientPrint(lua_State *L) {
return 0;
}
+static int luaGetTraffic(lua_State *L) {
+ lua_pushnumber(L, traffic);
+ return 1;
+}
void server_tick() {
lua_set_cycles(L, 0xFFFFFF);
@@ -550,6 +557,7 @@ void server_init() {
lua_register(L, "client_print", luaClientPrint);
lua_register(L, "cprint", luaClientPrint);
lua_register(L, "server_start_demo", luaStartDemoWriter);
+ lua_register(L, "server_get_traffic", luaGetTraffic);
// XXX: HACK: stdin client starten
#ifndef NO_CONSOLE_CLIENT
View
21 server.lua
@@ -273,13 +273,17 @@ function Client:info()
self:writeln("uptime | " .. (os.time() - stats.start_time) .. "s")
self:writeln("cpu usage | " .. os.clock() .. "s")
self:writeln("memory | " .. string.format("%d", collectgarbage("count")) .. "kb")
+ self:writeln("traffic | " .. server_get_traffic())
self:writeln("-------------------+------------------------------")
self:writeln("accepted clients | " .. stats.num_clients)
self:writeln("refused clients | " .. stats.num_refused)
self:writeln("joined players | " .. stats.num_players)
self:writeln("played maps | " .. stats.num_maps)
self:writeln("code executions | " .. stats.num_exec)
self:writeln("-------------------+------------------------------")
+ local w, h = world.level_size()
+ self:writeln("map | " .. map .. " (" .. w .. "x" .. h .. ")")
+ self:writeln("game time | " .. string.format("%ds", game_time() / 1000))
self:writeln("time limit | " .. (time_limit and string.format("%ds", time_limit / 1000) or "none"))
self:writeln("score limit | " .. (score_limit or "none"))
self:writeln("-------------------------------------------------")
@@ -421,21 +425,8 @@ function Client:handler()
self:centerln("Hello " .. self.addr .. "!")
self:centerln("Welcome to " .. GAME_NAME)
self:writeln("")
- -- von http://www.asciiworld.com/animals_birds.html
- if not no_banner then
- self:writeln(" .___ `.")
- self:writeln(" ___ `~\\ | \\")
- self:writeln(" o~ `. | /' |")
- self:writeln(" .----._ `| ,' /' _./'")
- self:writeln(" `o `\\|___ __,|----'~~~~T-----,__ _,'~")
- self:writeln(" /~~o `~>-/|~ ' ' , ' ' ~~\\_")
- self:writeln(" |_ <~ | ' , ' ' ' ' , ' \\")
- self:writeln(" `-...-'~\./' ' ' ' ' ' , ' >")
- self:writeln(" `-, __' , ' ' , ' , '_,'-'")
- self:writeln(" /' `~~~~~~~|`--------~~\\")
- self:writeln(" /' ,' `.")
- self:writeln(" ~~`---' / |")
- self:writeln(" ,-' _/'")
+ if banner then
+ self:write(banner:match("\r\n") and banner or banner:gsub("\n", "\r\n"))
self:writeln("")
end
self:writeln("enter '?' for help")

0 comments on commit 6e63902

Please sign in to comment.