// clear ops and i/o void net_clear_user_ops(void) { /// no... net_deinit(); add_sys_ops(); }
// unpickle the network! u8* net_unpickle(const u8* src) { u32 i, count, val; op_id_t id; op_t* op; // reset operator count, param count, pool offset, etc // no system operators after this net_deinit(); // confusingly though, we don't call deinit() after this. // system ops are in the pickled scene data along with everything else. // net_deinit() should maybe be renamed. // get count of operators // (use 4 bytes for alignment) src = unpickle_32(src, &count); #ifdef PRINT_PICKLE print_dbg("\r\n count of ops: "); print_dbg_ulong(count); #endif // loop over operators for(i=0; i<count; ++i) { // get operator class id src = unpickle_32(src, &val); id = (op_id_t)val; #ifdef PRINT_PICKLE print_dbg("\r\n adding op, class id: "); print_dbg_ulong(id); #endif // add and initialize from class id /// .. this should update the operator count, inodes and onodes net_add_op(id); // unpickle operator state (if needed) op = net->ops[net->numOps - 1]; if(op->unpickle != NULL) { #ifdef PRINT_PICKLE print_dbg(" ... unpickling op .... "); print_dbg_ulong(id); #endif src = (*(op->unpickle))(op, src); } } /// copy ALL i/o nodes, even unused! print_dbg("\r\n reading all input nodes "); for(i=0; i < (NET_INS_MAX); ++i) { #ifdef PRINT_PICKLE print_dbg("\r\n unpickling input node, idx: "); print_dbg_ulong(i); #endif src = inode_unpickle(src, &(net->ins[i])); } #ifdef PRINT_PICKLE print_dbg("\r\n reading all output nodes"); #endif // read output nodes for(i=0; i < NET_OUTS_MAX; ++i) { #ifdef PRINT_PICKLE print_dbg("\r\n unpickling output node, idx: "); print_dbg_ulong(i); #endif src = onode_unpickle(src, &(net->outs[i])); if(i < net->numOuts) { if(net->outs[i].target >= 0) { // reconnect so the parent operator knows what to do net_connect(i, net->outs[i].target); } } } // get count of parameters src = unpickle_32(src, &val); net->numParams = (u16)val; #ifdef PRINT_PICKLE print_dbg("\r\n reading params, count: "); print_dbg_ulong(net->numParams); #endif // read parameter nodes (includes value and descriptor) for(i=0; i<(net->numParams); ++i) { #ifdef PRINT_PICKLE print_dbg("\r\n unpickling param, idx: "); print_dbg_ulong(i); #endif src = param_unpickle(&(net->params[i]), src); } return (u8*)src; }
void NetworkShutdown() { net_deinit(); networkInitialized = false; }
static void * WiiloadThread(void *arg) { int netInit = 0; int netReady = 0; int wc24cleared = 0; stopNetworkThread = 0; errors = 0; strcpy(wiiload.ip, "<unknown>"); printopt("Net thread running, ready !"); while (!stopNetworkThread) { if (!netInit) { s32 res; res = net_init_async(NULL, NULL); Debug ("net_init_async %d", res); if (res != 0) { errors ++; continue; } netInit = 1; } if (netInit) { if (errors > 5 && !wc24cleared) { Debug ("Cleareing net_wc24cleanup"); net_deinit (); net_wc24cleanup(); errors = 0; netInit = 0; wc24cleared = 1; } s32 res; res = net_get_status(); Debug ("net_get_status %d", res); if (res == 0) { struct in_addr hostip; hostip.s_addr = net_gethostip(); if (hostip.s_addr) { strcpy(wiiload.ip, inet_ntoa(hostip)); netReady = 1; } } else errors ++; } if (netReady) { if (!StartWiiLoadServer ()) errors ++; } sleep (1); if (errors > 10) { Debug ("too many errors"); stopNetworkThread = 1; } } stopNetworkThread = 2; wiiload.status = WIILOAD_STOPPED; net_deinit(); return NULL; }
int main_dbghelper(int argc, char *argv[]) { main_argc = argc; main_argv = argv; #ifdef DEDI if(argc <= 1) return print_usage(argv[0]); #else if(argc <= 1) { //print_usage(argv[0]); net_port = 0; mod_basedir = "pkg/iceball/halp"; printf("Starting server on port %i, mod \"%s\"\n", net_port, mod_basedir); main_largstart = 4; boot_mode = 3; } else #endif #ifndef DEDI if((!strcmp(argv[1], "-h")) || (!strcmp(argv[1], "/?")) || (!strcmp(argv[1], "-?")) || (!strcmp(argv[1], "--help"))) { return print_usage(argv[0]); } else if(!strcmp(argv[1], "-c")) { if(argc <= 3) return print_usage(argv[0]); net_addr = argv[2]; net_port = atoi(argv[3]); printf("Connecting to \"%s\" port %i (ENet mode)\n", net_addr, net_port); mod_basedir = NULL; main_largstart = 4; boot_mode = 1 | 16; } else if(!strcmp(argv[1], "-C")) { if(argc <= 3) return print_usage(argv[0]); net_addr = argv[2]; net_port = atoi(argv[3]); printf("Connecting to \"%s\" port %i (TCP mode)\n", net_addr, net_port); mod_basedir = NULL; main_largstart = 4; boot_mode = 1; //return 101; } else if(!strcmp(argv[1], "-s")) { if(argc <= 3) return print_usage(argv[0]); net_port = atoi(argv[2]); mod_basedir = argv[3]; printf("Starting server on port %i, mod \"%s\" (local mode client)\n", net_port, mod_basedir); main_largstart = 4; boot_mode = 3; } else #endif if(!strcmp(argv[1], "-d")) { if(argc <= 3) return print_usage(argv[0]); net_port = atoi(argv[2]); mod_basedir = argv[3]; printf("Starting headless/dedicated server on port %i, mod \"%s\"\n", net_port, mod_basedir); main_largstart = 4; boot_mode = 2; //return 101; } else { return print_usage(argv[0]); } if(boot_mode & 2) { if(memcmp(mod_basedir,"pkg/",4)) { fprintf(stderr, "ERROR: package base dir must start with \"pkg/\"!\n"); return 109; } if(strlen(mod_basedir) < 5) { fprintf(stderr, "ERROR: package base dir can't actually be \"pkg/\"!\n"); return 109; } } #ifndef DEDI if((!(boot_mode & 1)) || !platform_init()) { #endif if(!net_init()) { if(!icelua_init()) { if((!(boot_mode & 2)) || !net_bind()) { #ifndef DEDI if((!(boot_mode & 1)) || !net_connect()) { if((!(boot_mode & 1)) || !video_init()) { if((!(boot_mode & 1)) || !wav_init()) { if((!(boot_mode & 1)) || !render_init(screen->w, screen->h)) { #endif run_game(); #ifndef DEDI if(boot_mode & 1) render_deinit(); } if(boot_mode & 1) wav_deinit(); } if(boot_mode & 1) video_deinit(); } if(boot_mode & 1) net_disconnect(); #endif } if(boot_mode & 2) net_unbind(); } icelua_deinit(); } net_deinit(); #ifndef DEDI } if(boot_mode & 1) platform_deinit(); } #endif return 0; }
static void * netcb (void *arg) { s32 res=-1; int retry; int wait; static bool prevInit = false; while(netHalt != 2) { retry = 5; while (retry>0 && (netHalt != 2)) { if(prevInit) { int i; net_deinit(); for(i=0; i < 400 && (netHalt != 2); i++) // 10 seconds to try to reset { res = net_get_status(); if(res != -EBUSY) // trying to init net so we can't kill the net { usleep(2000); net_wc24cleanup(); //kill the net prevInit=false; // net_wc24cleanup is called only once usleep(20000); break; } usleep(20000); } } usleep(2000); res = net_init_async(NULL, NULL); if(res != 0) { sleep(1); retry--; continue; } res = net_get_status(); wait = 400; // only wait 8 sec while (res == -EBUSY && wait > 0 && (netHalt != 2)) { usleep(20000); res = net_get_status(); wait--; } if(res==0) break; retry--; usleep(2000); } if (res == 0) { struct in_addr hostip; hostip.s_addr = net_gethostip(); if (hostip.s_addr) { strcpy(wiiIP, inet_ntoa(hostip)); networkInit = true; prevInit = true; } } if(netHalt != 2) LWP_SuspendThread(networkthread); } return NULL; }