MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / DedicatedReadTelnet

Function DedicatedReadTelnet

Descent3/dedicated_server.cpp:963–1065  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

961}
962
963void DedicatedReadTelnet(void) {
964 dedicated_socket *conn;
965 char buf[5];
966 conn = Head_sock;
967
968 while (conn) {
969 int bytesread = 1;
970 while (bytesread >= 0 && conn) {
971 // Read one byte at a time, looking for a CR
972 bytesread = recv(conn->sock, buf, 1, 0);
973 if (bytesread == 0) {
974 // Connection closed. Remove it from the list, and inform the other(?) users.
975 conn = DedicatedLogoutTelnet(conn);
976 break;
977 } else if (bytesread > 0) {
978 buf[1] = '\0';
979 // When we see a CR, process the line
980 if ((buf[0] == 0x0a) || (buf[0] == 0x0d)) {
981 if (conn->input[0] == 0) {
982 continue;
983 }
984 send(conn->sock, "\r\n", strlen("\r\n"), 0);
985 if (conn->validated) {
986 char command[255] = {}; // operand
987 char operand[255]; // operand
988
989 if (!stricmp(conn->input, "logout")) {
990 // log the connection out
991 conn = DedicatedLogoutTelnet(conn);
992 } else {
993 // Process the string
994 PrintDedicatedMessage("[%s] %s\n", inet_ntoa(conn->addr.sin_addr), conn->input);
995 if (conn->input[0] == '$') {
996 DLLInfo.input_string = conn->input;
997 CallGameDLL(EVT_CLIENT_INPUT_STRING, &DLLInfo);
998 conn->input[0] = '\0';
999 return;
1000 }
1001
1002 ParseLine(conn->input, command, operand, 255, 255);
1003 conn->input[0] = '\0';
1004 if (!command[0])
1005 return;
1006
1007 int index = DedicatedServerLex(command);
1008
1009 if (index < 0) {
1010 PrintDedicatedMessage(TXT_DS_BADCOMMAND);
1011 PrintDedicatedMessage("\n");
1012 return;
1013 }
1014
1015 // Everything ok, set command
1016 SetCVar(CVars[index].varname, operand, false);
1017 }
1018 } else {
1019 // All we want to see from them is the correct password
1020 if (strcmp(conn->input, dedicated_telnet_password) == 0) {

Callers 1

DoDedicatedServerFrameFunction · 0.85

Calls 6

DedicatedLogoutTelnetFunction · 0.85
PrintDedicatedMessageFunction · 0.85
CallGameDLLFunction · 0.85
ParseLineFunction · 0.85
DedicatedServerLexFunction · 0.85
SetCVarFunction · 0.85

Tested by

no test coverage detected