/** * @brief This function allows you to send network commands from commandline * @note This function is only for debugging and testing purposes * It is dangerous to leave this activated in final releases * packet [destination] [contents] * Contents allows \n escape character */ static void CL_Packet_f (void) { if (Cmd_Argc() != 4) { Com_Printf("Usage: %s <destination> <port> <contents>\n", Cmd_Argv(0)); return; } struct net_stream* s = NET_Connect(Cmd_Argv(1), Cmd_Argv(2)); if (!s) { Com_Printf("Could not connect to %s at port %s\n", Cmd_Argv(1), Cmd_Argv(2)); return; } const char* in = Cmd_Argv(3); const int l = strlen(in); char buf[MAX_STRING_TOKENS]; char* out = buf; for (int i = 0; i < l; i++) { if (in[i] == '\\' && in[i + 1] == 'n') { *out++ = '\n'; i++; } else { *out++ = in[i]; } } *out = 0; NET_OOB_Printf(s, "%s %i", out, PROTOCOL_VERSION); NET_StreamFinished(s); }
/* ===================== CL_EstablishConnection Host should be either "local" or a net address to be passed on ===================== */ void CL_EstablishConnection(char *host) { if (cls.state == ca_dedicated) { return; } if (cls.demoplayback) { return; } CL_Disconnect(); cls.netcon = NET_Connect(host); if (!cls.netcon) { Host_Error("CL_Connect: connect failed\n"); } Con_DPrintf("CL_EstablishConnection: connected to %s\n", host); cls.demonum = -1; // not in the demo loop now cls.state = ca_connected; cls.signon = 0; // need all the signon messages before playing }
/** * @note Only call @c CL_Connect if there is no connection yet (@c cls.netStream is @c nullptr) * @sa CL_Disconnect * @sa CL_SendChangedUserinfos */ static void CL_Connect (void) { Com_SetUserinfoModified(false); assert(!cls.netStream); if (cls.servername[0] != '\0') { assert(cls.serverport[0] != '\0'); Com_Printf("Connecting to %s %s...\n", cls.servername, cls.serverport); cls.netStream = NET_Connect(cls.servername, cls.serverport, CL_FreeClientStream); } else { Com_Printf("Connecting to localhost...\n"); cls.netStream = NET_ConnectToLoopBack(CL_FreeClientStream); } if (cls.netStream) { char info[MAX_INFO_STRING]; NET_OOB_Printf(cls.netStream, SV_CMD_CONNECT " %i \"%s\"\n", PROTOCOL_VERSION, Cvar_Userinfo(info, sizeof(info))); cls.connectTime = CL_Milliseconds(); } else { if (cls.servername[0] != '\0') { assert(cls.serverport[0]); Com_Printf("Could not connect to %s %s\n", cls.servername, cls.serverport); } else { Com_Printf("Could not connect to localhost\n"); } } }