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;
|
||||
card2["x"] = 50;
|
||||
card2["y"] = 50;
|
||||
return OCT_TYPE_CLIENT, OCT_NEEDS_TERMBOX;
|
||||
return OCT_NOT_NEEDS_NETWORKING, OCT_NEEDS_TERMBOX;
|
||||
end
|
||||
|
||||
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
|
||||
char lua_file[OCT_MAX_FILENAME_SIZE];
|
||||
int needs_termbox;
|
||||
int type;
|
||||
int needs_networking;
|
||||
} config;
|
||||
|
||||
void usage();
|
||||
|
@ -232,7 +232,7 @@ int initialize_everything(char* lua_file) {
|
|||
OCT_LOG_INFO("Begin running oct_init()");
|
||||
lua_getglobal(L, "oct_init");
|
||||
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);
|
||||
OCT_LOG_INFO("Finish running oct_init()");
|
||||
|
||||
|
@ -241,20 +241,16 @@ int initialize_everything(char* lua_file) {
|
|||
if (!config.needs_termbox) {
|
||||
oct_tb_change_oct_tb_sprite_new(L);
|
||||
}
|
||||
|
||||
OCT_LOG_INFO("Lua script %s networking", config.needs_networking ? "requires" : "does not require");
|
||||
|
||||
if (config.type == OCT_TYPE_SERVER) {
|
||||
OCT_LOG_INFO("Lua script is server type");
|
||||
if (config.needs_networking) {
|
||||
if (!oct_network_node_init(config.port, L)) {
|
||||
OCT_LOG_ERROR("Could not establish a socket on port %s\n", config.port);
|
||||
return OCT_NETWORK_ERROR;
|
||||
}
|
||||
}
|
||||
else if (config.type == OCT_TYPE_CLIENT) {
|
||||
//oct_network_client_init();
|
||||
}
|
||||
else {
|
||||
// Do nothing, offline
|
||||
}
|
||||
|
||||
if (config.needs_termbox) {
|
||||
tb_init();
|
||||
}
|
||||
|
|
|
@ -124,6 +124,7 @@ int oct_network_send_msg() {
|
|||
and) try the next address. */
|
||||
|
||||
for (rp = result; rp != NULL; rp = rp->ai_next) {
|
||||
|
||||
sfd = socket(rp->ai_family, rp->ai_socktype,
|
||||
rp->ai_protocol);
|
||||
if (sfd == -1)
|
||||
|
|
|
@ -6,9 +6,6 @@
|
|||
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
#define OCT_TYPE_SERVER 1
|
||||
#define OCT_TYPE_CLIENT 2
|
||||
|
||||
#define OCT_DEFAULT_PORT "20000"
|
||||
|
||||
// Forward declarations
|
||||
|
|
|
@ -7,8 +7,8 @@ function load_termbox_sprite(file_name)
|
|||
return contents;
|
||||
end
|
||||
|
||||
OCT_TYPE_SERVER = 1;
|
||||
OCT_TYPE_CLIENT = 2;
|
||||
OCT_NEEDS_NETWORKING = 1;
|
||||
OCT_NOT_NEEDS_NETWORKING = 0;
|
||||
OCT_NEEDS_TERMBOX = 1;
|
||||
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);
|
||||
init_text["shape"] = "Press SPACE to begin";
|
||||
pause();
|
||||
return OCT_TYPE_CLIENT, OCT_NEEDS_TERMBOX;
|
||||
return OCT_NOT_NEEDS_NETWORKING, OCT_NEEDS_TERMBOX;
|
||||
end
|
||||
|
||||
function oct_loop(key, ch)
|
||||
|
|
|
@ -10,7 +10,7 @@ function oct_init()
|
|||
-- text["x"] = 50;
|
||||
-- text["y"] = 10;
|
||||
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
|
||||
|
||||
counter = 0;
|
||||
|
|
|
@ -10,7 +10,7 @@ function oct_init()
|
|||
-- text["x"] = 50;
|
||||
-- text["y"] = 10;
|
||||
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
|
||||
|
||||
function oct_loop(key)
|
||||
|
|
Loading…
Reference in New Issue