| 54 | } |
| 55 | |
| 56 | void connectserv_(const char *servername, int serverport = 0, const char *password = NULL, int role = CR_DEFAULT) |
| 57 | { |
| 58 | if(serverport <= 0) serverport = CUBE_DEFAULT_SERVER_PORT; |
| 59 | if(watchingdemo) enddemoplayback(); |
| 60 | |
| 61 | if(connpeer) |
| 62 | { |
| 63 | conoutf("aborting connection attempt"); |
| 64 | abortconnect(); |
| 65 | } |
| 66 | connectrole = role; |
| 67 | copystring(clientpassword, password ? password : ""); |
| 68 | ENetAddress address; |
| 69 | address.port = serverport; |
| 70 | |
| 71 | if(servername) |
| 72 | { |
| 73 | addserver(servername, serverport, 0); |
| 74 | conoutf("\f2attempting to %sconnect to \f5%s\f4:%d\f2", role==CR_DEFAULT?"":"\f8admin\f2", servername, serverport); |
| 75 | if(!resolverwait(servername, &address)) |
| 76 | { |
| 77 | conoutf("\f2could \f3not resolve\f2 server \f5%s\f2", servername); |
| 78 | clientpassword[0] = '\0'; |
| 79 | connectrole = CR_DEFAULT; |
| 80 | return; |
| 81 | } |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | conoutf("\f2attempting to connect over \f1LAN\f2"); |
| 86 | address.host = ENET_HOST_BROADCAST; |
| 87 | } |
| 88 | |
| 89 | if(!clienthost) |
| 90 | clienthost = enet_host_create(NULL, 2, 3, 0, 0); |
| 91 | |
| 92 | if(clienthost) |
| 93 | { |
| 94 | connpeer = enet_host_connect(clienthost, &address, 3, 0); |
| 95 | enet_host_flush(clienthost); |
| 96 | connmillis = totalmillis; |
| 97 | connattempts = 0; |
| 98 | if(!m_mp(gamemode)) gamemode = GMODE_TEAMDEATHMATCH; |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | conoutf("\f2could \f3not connect\f2 to server"); |
| 103 | clientpassword[0] = '\0'; |
| 104 | connectrole = CR_DEFAULT; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void connectserv(char *servername, int *serverport, char *password) |
| 109 | { |
no test coverage detected