mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-27 04:41:23 +00:00
Merge branch 'revert-mserv' into 'master'
Revert mserv See merge request KartKrew/Kart-Public!144
This commit is contained in:
commit
815f237b22
1 changed files with 36 additions and 27 deletions
63
src/mserv.c
63
src/mserv.c
|
@ -661,19 +661,11 @@ FUNCMATH static const char *int2str(INT32 n)
|
||||||
#ifndef NONET
|
#ifndef NONET
|
||||||
static INT32 ConnectionFailed(void)
|
static INT32 ConnectionFailed(void)
|
||||||
{
|
{
|
||||||
time(&MSLastPing);
|
|
||||||
con_state = MSCS_FAILED;
|
con_state = MSCS_FAILED;
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("Connection to Master Server failed\n"));
|
CONS_Alert(CONS_ERROR, M_GetText("Connection to Master Server failed\n"));
|
||||||
CloseConnection();
|
CloseConnection();
|
||||||
return MS_CONNECT_ERROR;
|
return MS_CONNECT_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
static INT32 ConnectionFailedwerrno(int no)
|
|
||||||
{
|
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error: %s\n"),
|
|
||||||
strerror(no));
|
|
||||||
return ConnectionFailed();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** Tries to register the local game server on the master server.
|
/** Tries to register the local game server on the master server.
|
||||||
|
@ -690,43 +682,57 @@ static INT32 AddToMasterServer(boolean firstadd)
|
||||||
msg_server_t *info = (msg_server_t *)msg.buffer;
|
msg_server_t *info = (msg_server_t *)msg.buffer;
|
||||||
INT32 room = -1;
|
INT32 room = -1;
|
||||||
fd_set tset;
|
fd_set tset;
|
||||||
|
time_t timestamp = time(NULL);
|
||||||
UINT32 signature, tmp;
|
UINT32 signature, tmp;
|
||||||
const char *insname;
|
const char *insname;
|
||||||
|
|
||||||
if (socket_fd == (SOCKET_TYPE)ERRSOCKET)/* Woah, our socket was closed! */
|
|
||||||
{
|
|
||||||
if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0))
|
|
||||||
return ConnectionFailedwerrno(errno);
|
|
||||||
}
|
|
||||||
|
|
||||||
M_Memcpy(&tset, &wset, sizeof (tset));
|
M_Memcpy(&tset, &wset, sizeof (tset));
|
||||||
res = select(255, NULL, &tset, NULL, &select_timeout);
|
res = select(255, NULL, &tset, NULL, &select_timeout);
|
||||||
if (res == ERRSOCKET)
|
if (res != ERRSOCKET && !res)
|
||||||
return ConnectionFailedwerrno(errno);
|
|
||||||
if (res == 0)/* nothing selected */
|
|
||||||
{
|
{
|
||||||
/*
|
if (retry++ > 30) // an about 30 second timeout
|
||||||
Timeout next call because SendPingToMasterServer
|
|
||||||
(our calling function) already calls this once
|
|
||||||
every two minutes.
|
|
||||||
*/
|
|
||||||
if (retry++ == 1)
|
|
||||||
{
|
{
|
||||||
retry = 0;
|
retry = 0;
|
||||||
CONS_Alert(CONS_ERROR, M_GetText("Master Server timed out\n"));
|
CONS_Alert(CONS_ERROR, M_GetText("Master Server timed out\n"));
|
||||||
|
MSLastPing = timestamp;
|
||||||
return ConnectionFailed();
|
return ConnectionFailed();
|
||||||
}
|
}
|
||||||
return MS_CONNECT_ERROR;
|
return MS_CONNECT_ERROR;
|
||||||
}
|
}
|
||||||
retry = 0;
|
retry = 0;
|
||||||
|
/*
|
||||||
|
Somehow we can still select our old socket despite it being closed(?).
|
||||||
|
Atleast, that's what I THINK is happening. Anyway, we have to check that we
|
||||||
|
haven't open a socket, and actually open it!
|
||||||
|
*/
|
||||||
|
/*if (res == ERRSOCKET)*//* wtf? no! */
|
||||||
|
if (socket_fd == (SOCKET_TYPE)ERRSOCKET)
|
||||||
|
{
|
||||||
|
if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0))
|
||||||
|
{
|
||||||
|
CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error #%u: %s\n"), errno, strerror(errno));
|
||||||
|
MSLastPing = timestamp;
|
||||||
|
return ConnectionFailed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// so, the socket is writable, but what does that mean, that the connection is
|
// so, the socket is writable, but what does that mean, that the connection is
|
||||||
// ok, or bad... let see that!
|
// ok, or bad... let see that!
|
||||||
j = (socklen_t)sizeof (i);
|
j = (socklen_t)sizeof (i);
|
||||||
if (getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j) == ERRSOCKET)
|
getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j);
|
||||||
return ConnectionFailedwerrno(errno);
|
/*
|
||||||
|
This is also wrong. If getsockopt fails, i doesn't have to be set. Plus, if
|
||||||
|
it is set (which it appearantly is on linux), we check errno anyway. And in
|
||||||
|
the case that i is returned as normal, we don't even report the correct
|
||||||
|
value! So we accomplish NOTHING, except returning due to dumb luck.
|
||||||
|
If you care, fix this--I don't. -James (R.)
|
||||||
|
*/
|
||||||
if (i) // it was bad
|
if (i) // it was bad
|
||||||
return ConnectionFailedwerrno(i);
|
{
|
||||||
|
CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error #%u: %s\n"), errno, strerror(errno));
|
||||||
|
MSLastPing = timestamp;
|
||||||
|
return ConnectionFailed();
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef PARANOIA
|
#ifdef PARANOIA
|
||||||
if (ms_RoomId <= 0)
|
if (ms_RoomId <= 0)
|
||||||
|
@ -759,12 +765,15 @@ static INT32 AddToMasterServer(boolean firstadd)
|
||||||
msg.length = (UINT32)sizeof (msg_server_t);
|
msg.length = (UINT32)sizeof (msg_server_t);
|
||||||
msg.room = 0;
|
msg.room = 0;
|
||||||
if (MS_Write(&msg) < 0)
|
if (MS_Write(&msg) < 0)
|
||||||
|
{
|
||||||
|
MSLastPing = timestamp;
|
||||||
return ConnectionFailed();
|
return ConnectionFailed();
|
||||||
|
}
|
||||||
|
|
||||||
if(con_state != MSCS_REGISTERED)
|
if(con_state != MSCS_REGISTERED)
|
||||||
CONS_Printf(M_GetText("Master Server update successful.\n"));
|
CONS_Printf(M_GetText("Master Server update successful.\n"));
|
||||||
|
|
||||||
time(&MSLastPing);
|
MSLastPing = timestamp;
|
||||||
con_state = MSCS_REGISTERED;
|
con_state = MSCS_REGISTERED;
|
||||||
CloseConnection();
|
CloseConnection();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue