Skip to content

Commit

Permalink
Refactor|Client: Took ServerLink into use
Browse files Browse the repository at this point in the history
Todo: Drop LegacyNetwork.
  • Loading branch information
skyjake committed Feb 21, 2013
1 parent 8dc6709 commit 4efac5c
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 414 deletions.
2 changes: 1 addition & 1 deletion doomsday/client/include/de_network.h
Expand Up @@ -41,8 +41,8 @@
#endif

#ifdef __CLIENT__
# include "network/net_demo.h"
# include "api_client.h"
# include "network/net_demo.h"
# include "client/cl_def.h"
# include "client/cl_player.h"
# include "client/cl_mobj.h"
Expand Down
2 changes: 1 addition & 1 deletion doomsday/client/include/network/net_event.h
Expand Up @@ -31,7 +31,7 @@
typedef enum neteventtype_e {
NE_CLIENT_ENTRY,
NE_CLIENT_EXIT,
NE_END_CONNECTION
//NE_END_CONNECTION
//NE_TERMINATE_NODE
} neteventtype_t;

Expand Down
3 changes: 3 additions & 0 deletions doomsday/client/include/network/net_main.h
Expand Up @@ -29,6 +29,7 @@
#include "dd_share.h"
#include "net_msg.h"
#include "map/p_mapdata.h"
#include <de/Record>
#include <de/smoother.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -262,6 +263,8 @@ void Net_PrintServerInfo(int index, serverinfo_t *info);
*/
boolean Net_StringToServerInfo(char const *valuePair, serverinfo_t *info);

void Net_RecordToServerInfo(de::Record const &rec, serverinfo_t *info);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
35 changes: 9 additions & 26 deletions doomsday/client/include/network/sys_network.h
Expand Up @@ -31,40 +31,23 @@
#include "net_buf.h"
#include "net_main.h"
#include "monitor.h"

#ifdef __cplusplus
extern "C" {
#endif
#include "serverlink.h"

extern boolean allowSending;
extern int maxQueuePackets;

extern char *nptIPAddress;
extern int nptIPPort;

void N_Register(void);

void N_SystemInit(void);
void N_SystemShutdown(void);
void N_PrintInfo(void);
void N_Listen(void);
void N_ListenNodes(void);

boolean N_LookForHosts(const char *address, int port, expectedresponder_t responder);
void N_ClientHandleResponseToInfoQuery(int nodeId, const byte *data, int size);
boolean N_Connect(void);
boolean N_Disconnect(void);
ServerLink &Net_ServerLink(void);

int N_GetNodeSocket(nodeid_t id);
boolean N_HasNodeJoined(nodeid_t id);
void N_Register(void);

int N_GetHostCount(void);
boolean N_GetHostInfo(int index, struct serverinfo_s *info);

void N_PrintNetworkStatus(void);

#ifdef __cplusplus
} // extern "C"
#endif
void N_SystemInit(void);
void N_SystemShutdown(void);
void N_PrintInfo(void);
int N_GetHostCount(void);
boolean N_GetHostInfo(int index, struct serverinfo_s *info);
void N_PrintNetworkStatus(void);

#endif /* LIBDENG_SYSTEM_NETWORK_H */
17 changes: 7 additions & 10 deletions doomsday/client/src/network/net_buf.cpp
Expand Up @@ -204,12 +204,7 @@ void N_ReleaseMessage(netmessage_t *msg)
{
if(msg->handle)
{
#ifdef __CLIENT__
LegacyNetwork_FreeBuffer((unsigned char *)msg->handle);
#endif
#ifdef __SERVER__
delete [] reinterpret_cast<byte *>(msg->handle);
#endif
msg->handle = 0;
}
M_Free(msg);
Expand Down Expand Up @@ -245,7 +240,9 @@ void N_ClearMessages(void)
*/
void N_SendPacket(int flags)
{
#ifdef __SERVER__
uint dest = 0;
#endif

// Is the network available?
if(!allowSending)
Expand Down Expand Up @@ -285,12 +282,12 @@ void N_SendPacket(int flags)
numOutBytes += netBuffer.headerLength + netBuffer.length;

#ifdef __CLIENT__
Protocol_Send(&netBuffer.msg, netBuffer.headerLength + netBuffer.length, dest);
#endif
#ifdef __SERVER__
App_ServerSystem().user(dest)
<< de::ByteRefArray(&netBuffer.msg, netBuffer.headerLength + netBuffer.length);
de::Transmitter &out = Net_ServerLink();
#else
de::Transmitter &out = App_ServerSystem().user(dest);
#endif

out << de::ByteRefArray(&netBuffer.msg, netBuffer.headerLength + netBuffer.length);
}

void N_AddSentBytes(size_t bytes)
Expand Down
4 changes: 2 additions & 2 deletions doomsday/client/src/network/net_event.cpp
Expand Up @@ -256,7 +256,7 @@ void N_Update(void)
#endif // __SERVER__

#ifdef __CLIENT__
case NE_END_CONNECTION:
/*case NE_END_CONNECTION:
// A client receives this event when the connection is
// terminated.
if(netGame)
Expand All @@ -266,7 +266,7 @@ void N_Update(void)
Con_Message("N_Update: Connection was terminated.\n");
N_Disconnect();
}
break;
break;*/
#endif

default:
Expand Down
86 changes: 44 additions & 42 deletions doomsday/client/src/network/net_main.cpp
Expand Up @@ -57,6 +57,8 @@
#include "dd_loop.h"
#include "map/p_players.h"

#include <de/Value>

// MACROS ------------------------------------------------------------------

#define OBSOLETE CVF_NO_ARCHIVE|CVF_HIDE // Old ccmds.
Expand Down Expand Up @@ -509,7 +511,6 @@ void Net_Update(void)

// Check for received packets.
#ifdef __CLIENT__
N_ListenNodes();
Cl_GetPackets();
#endif
}
Expand Down Expand Up @@ -1123,6 +1124,7 @@ D_CMD(SetConsole)
return true;
}

#if 0
void Net_FinishConnection(int nodeId, const byte* data, int size)
{
serverinfo_t info;
Expand All @@ -1144,42 +1146,15 @@ void Net_FinishConnection(int nodeId, const byte* data, int size)
Con_Message("Net_FinishConnection: Failed to retrieve server info.\n");
}
}
#endif

int Net_StartConnection(const char* address, int port)
{
Con_Message("Net_StartConnection: Connecting to %s...\n", address);

// Start searching at the specified location.
return N_LookForHosts(address, port, Net_FinishConnection);


/*
if(N_GetHostInfo(0, &param->info))
{ // Found something!
Con_Execute(CMDS_CONSOLE, "net connect 0", false, false);
returnValue = true;
isDone = true;
}
else
{ // Nothing yet, should we wait a while longer?
if(Sys_GetSeconds() - startTime >= netConnectTimeout)
isDone = true;
else
Sys_Sleep(250); // Wait a while.
}
}
if(!returnValue)
Con_Message("No response from %s.\n", param->address);
}
else
{
Con_Message("TCP/IP not available.\n");
}
BusyMode_WorkerEnd();
return returnValue;*/
Net_ServerLink().connectDomain(de::String(address) + ":" + port, 7 /*timeout*/);
return true;
}

/**
Expand Down Expand Up @@ -1294,10 +1269,9 @@ D_CMD(Net)
return false;
}

if((success = N_Disconnect()) != false)
{
Con_Message("Disconnected.\n");
}
Net_ServerLink().disconnect();

Con_Message("Disconnected.\n");
}
#endif
else
Expand Down Expand Up @@ -1351,25 +1325,25 @@ D_CMD(Net)
#ifdef __CLIENT__
if(!stricmp(argv[1], "search"))
{
success = N_LookForHosts(argv[2], 0, 0);
Net_ServerLink().discover(argv[2]);
}
else if(!stricmp(argv[1], "connect"))
{
int idx;

if(netGame)
{
Con_Printf("Already connected.\n");
return false;
}

idx = strtol(argv[2], NULL, 10); // ignored!
CmdReturnValue = success = N_Connect();
Net_ServerLink().connectDomain(argv[2], 5);

//idx = strtol(argv[2], NULL, 10); // ignored!
//CmdReturnValue = success = N_Connect();
/*
if(success)
{
Con_Message("Connected.\n");
}
}*/
}
else if(!stricmp(argv[1], "mconnect"))
{
Expand Down Expand Up @@ -1398,7 +1372,8 @@ D_CMD(Net)
{
if(!stricmp(argv[1], "search"))
{
success = N_LookForHosts(argv[2], strtol(argv[3], 0, 0), 0);
//success = N_LookForHosts(argv[2], strtol(argv[3], 0, 0), 0);
Net_ServerLink().discover(de::String(argv[2]) + ":" + argv[3]);
}
}
#endif
Expand Down Expand Up @@ -1431,6 +1406,33 @@ static boolean tokenize(char const *line, char *label, char *value, int max)
return true;
}

void Net_RecordToServerInfo(de::Record const &rec, serverinfo_t *info)
{
memset(info, 0, sizeof(*info));

info->port = (int) rec["port"].value().asNumber();
info->version = (int) rec["ver" ].value().asNumber();
info->loadedFilesCRC = (uint) rec["wcrc"].value().asNumber();
info->numPlayers = (int) rec["nump"].value().asNumber();
info->maxPlayers = (int) rec["maxp"].value().asNumber();
info->canJoin = rec["open"].value().isTrue();

#define COPY_STR(Member, VarName) \
strncpy(Member, rec[VarName].value().asText().toUtf8(), sizeof(Member) - 1);

COPY_STR(info->name, "name" );
COPY_STR(info->description, "info" );
COPY_STR(info->plugin, "game" );
COPY_STR(info->gameIdentityKey, "mode" );
COPY_STR(info->gameConfig, "setup");
COPY_STR(info->iwad, "iwad" );
COPY_STR(info->pwads, "pwads");
COPY_STR(info->map, "map" );
COPY_STR(info->clientNames, "plrn" );

#undef COPY_STR
}

boolean Net_StringToServerInfo(const char *valuePair, serverinfo_t *info)
{
char label[SVINFO_TOKEN_LEN], value[SVINFO_TOKEN_LEN];
Expand Down
3 changes: 3 additions & 0 deletions doomsday/client/src/network/protocol.cpp
Expand Up @@ -16,6 +16,8 @@
* 02110-1301 USA</small>
*/

#if 0

#include <de/memory.h>
#include <de/memoryzone.h>
#include <de/c_wrapper.h>
Expand Down Expand Up @@ -78,3 +80,4 @@ void Protocol_Send(void *data, size_t size, nodeid_t destination)

LegacyNetwork_Send(N_GetNodeSocket(destination), data, size);
}
#endif 0

0 comments on commit 4efac5c

Please sign in to comment.