better
This commit is contained in:
parent
9dd2e6acd6
commit
6b4602a984
5 changed files with 42 additions and 13 deletions
29
client/net.c
Normal file
29
client/net.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#include <af_common.h>
|
||||
|
||||
static fishsoup_client_t* client = NULL;
|
||||
|
||||
static void net_return(MwWidget handle, void* user, void* client) {
|
||||
scene_change(AF_SCENE_MAIN);
|
||||
}
|
||||
|
||||
void net_connect(const char* username, const char* hostname, int port) {
|
||||
scene_change(AF_SCENE_CONNECTING);
|
||||
client = fishsoup_client(hostname, port == 0 ? AF_DEFAULT_PORT : port);
|
||||
if(client == NULL) {
|
||||
MwAddUserHandler(ui_message("Failed to connect"), MwNactivateHandler, net_return, NULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void net_poll(void) {
|
||||
int ret;
|
||||
if(client == NULL) return;
|
||||
|
||||
while((ret = fishsoup_client_poll(client)) > 0);
|
||||
if(ret < 0) {
|
||||
MwAddUserHandler(ui_message("Connection destroyed"), MwNactivateHandler, net_return, NULL);
|
||||
fishsoup_client_destroy(client);
|
||||
client = NULL;
|
||||
return;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue