Signal to need networking, no diff between client/server
This commit is contained in:
parent
0cc7f69662
commit
32f4ee7b8f
|
@ -12,7 +12,7 @@ function oct_init()
|
||||||
card1["y"] = 0;
|
card1["y"] = 0;
|
||||||
card2["x"] = 50;
|
card2["x"] = 50;
|
||||||
card2["y"] = 50;
|
card2["y"] = 50;
|
||||||
return OCT_TYPE_CLIENT, OCT_NEEDS_TERMBOX;
|
return OCT_NOT_NEEDS_NETWORKING, OCT_NEEDS_TERMBOX;
|
||||||
end
|
end
|
||||||
|
|
||||||
function oct_loop(key)
|
function oct_loop(key)
|
||||||
|
|
16
main.c
16
main.c
|
@ -37,7 +37,7 @@ struct {
|
||||||
// e.g. if I ever want to allow downloading a script from peer
|
// e.g. if I ever want to allow downloading a script from peer
|
||||||
char lua_file[OCT_MAX_FILENAME_SIZE];
|
char lua_file[OCT_MAX_FILENAME_SIZE];
|
||||||
int needs_termbox;
|
int needs_termbox;
|
||||||
int type;
|
int needs_networking;
|
||||||
} config;
|
} config;
|
||||||
|
|
||||||
void usage();
|
void usage();
|
||||||
|
@ -232,7 +232,7 @@ int initialize_everything(char* lua_file) {
|
||||||
OCT_LOG_INFO("Begin running oct_init()");
|
OCT_LOG_INFO("Begin running oct_init()");
|
||||||
lua_getglobal(L, "oct_init");
|
lua_getglobal(L, "oct_init");
|
||||||
lua_call(L, 0, 2);
|
lua_call(L, 0, 2);
|
||||||
config.type = lua_tointeger(L, -2);
|
config.needs_networking = lua_tointeger(L, -2);
|
||||||
config.needs_termbox = lua_tointeger(L, -1);
|
config.needs_termbox = lua_tointeger(L, -1);
|
||||||
OCT_LOG_INFO("Finish running oct_init()");
|
OCT_LOG_INFO("Finish running oct_init()");
|
||||||
|
|
||||||
|
@ -242,19 +242,15 @@ int initialize_everything(char* lua_file) {
|
||||||
oct_tb_change_oct_tb_sprite_new(L);
|
oct_tb_change_oct_tb_sprite_new(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.type == OCT_TYPE_SERVER) {
|
OCT_LOG_INFO("Lua script %s networking", config.needs_networking ? "requires" : "does not require");
|
||||||
OCT_LOG_INFO("Lua script is server type");
|
|
||||||
|
if (config.needs_networking) {
|
||||||
if (!oct_network_node_init(config.port, L)) {
|
if (!oct_network_node_init(config.port, L)) {
|
||||||
OCT_LOG_ERROR("Could not establish a socket on port %s\n", config.port);
|
OCT_LOG_ERROR("Could not establish a socket on port %s\n", config.port);
|
||||||
return OCT_NETWORK_ERROR;
|
return OCT_NETWORK_ERROR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (config.type == OCT_TYPE_CLIENT) {
|
|
||||||
//oct_network_client_init();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// Do nothing, offline
|
|
||||||
}
|
|
||||||
if (config.needs_termbox) {
|
if (config.needs_termbox) {
|
||||||
tb_init();
|
tb_init();
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,6 +124,7 @@ int oct_network_send_msg() {
|
||||||
and) try the next address. */
|
and) try the next address. */
|
||||||
|
|
||||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||||
|
|
||||||
sfd = socket(rp->ai_family, rp->ai_socktype,
|
sfd = socket(rp->ai_family, rp->ai_socktype,
|
||||||
rp->ai_protocol);
|
rp->ai_protocol);
|
||||||
if (sfd == -1)
|
if (sfd == -1)
|
||||||
|
|
|
@ -6,9 +6,6 @@
|
||||||
|
|
||||||
#define BUFFER_SIZE 1024
|
#define BUFFER_SIZE 1024
|
||||||
|
|
||||||
#define OCT_TYPE_SERVER 1
|
|
||||||
#define OCT_TYPE_CLIENT 2
|
|
||||||
|
|
||||||
#define OCT_DEFAULT_PORT "20000"
|
#define OCT_DEFAULT_PORT "20000"
|
||||||
|
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
|
|
|
@ -7,8 +7,8 @@ function load_termbox_sprite(file_name)
|
||||||
return contents;
|
return contents;
|
||||||
end
|
end
|
||||||
|
|
||||||
OCT_TYPE_SERVER = 1;
|
OCT_NEEDS_NETWORKING = 1;
|
||||||
OCT_TYPE_CLIENT = 2;
|
OCT_NOT_NEEDS_NETWORKING = 0;
|
||||||
OCT_NEEDS_TERMBOX = 1;
|
OCT_NEEDS_TERMBOX = 1;
|
||||||
OCT_NOT_NEEDS_TERMBOX = 0;
|
OCT_NOT_NEEDS_TERMBOX = 0;
|
||||||
|
|
||||||
|
|
2
pong.lua
2
pong.lua
|
@ -85,7 +85,7 @@ function oct_init()
|
||||||
score_p2_sprite["shape"] = "Player 2: " .. tostring(score_p2);
|
score_p2_sprite["shape"] = "Player 2: " .. tostring(score_p2);
|
||||||
init_text["shape"] = "Press SPACE to begin";
|
init_text["shape"] = "Press SPACE to begin";
|
||||||
pause();
|
pause();
|
||||||
return OCT_TYPE_CLIENT, OCT_NEEDS_TERMBOX;
|
return OCT_NOT_NEEDS_NETWORKING, OCT_NEEDS_TERMBOX;
|
||||||
end
|
end
|
||||||
|
|
||||||
function oct_loop(key, ch)
|
function oct_loop(key, ch)
|
||||||
|
|
|
@ -10,7 +10,7 @@ function oct_init()
|
||||||
-- text["x"] = 50;
|
-- text["x"] = 50;
|
||||||
-- text["y"] = 10;
|
-- text["y"] = 10;
|
||||||
OCT_LOG_INFO("THIS IS A TEST CLIENT");
|
OCT_LOG_INFO("THIS IS A TEST CLIENT");
|
||||||
return OCT_TYPE_SERVER, OCT_NOT_NEEDS_TERMBOX;
|
return OCT_NEEDS_NETWORKING, OCT_NOT_NEEDS_TERMBOX;
|
||||||
end
|
end
|
||||||
|
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
|
@ -10,7 +10,7 @@ function oct_init()
|
||||||
-- text["x"] = 50;
|
-- text["x"] = 50;
|
||||||
-- text["y"] = 10;
|
-- text["y"] = 10;
|
||||||
OCT_LOG_INFO("THIS IS A TEST SERVER");
|
OCT_LOG_INFO("THIS IS A TEST SERVER");
|
||||||
return OCT_TYPE_SERVER, OCT_NOT_NEEDS_TERMBOX;
|
return OCT_NEEDS_NETWORKING, OCT_NOT_NEEDS_TERMBOX;
|
||||||
end
|
end
|
||||||
|
|
||||||
function oct_loop(key)
|
function oct_loop(key)
|
||||||
|
|
Loading…
Reference in New Issue