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

Function ConnectToChatServer

netcon/mtclient/chat_api.cpp:123–270  ·  view source on GitHub ↗

Return codes: -2 Already connected -1 Failed to connect 0 Connecting 1 Connected Call it once with the server IP address, and it will return immediately with 0. Keep calling it until it returns something other than 0 note: the nickname may be changed if someone with that name already exists (Scourge1 for instance)

Source from the content-addressed store, hash-verified

121// note: the nickname may be changed if someone with that name already
122// exists (Scourge1 for instance)
123int ConnectToChatServer(const char *serveraddr, int16_t chat_port, char *nickname, char *trackerid) {
124 char signon_str[100];
125
126 // if(Socket_connected && ) return -2;
127
128 if (!Socket_connecting) {
129 strcpy(Nick_name, nickname);
130 for (uint32_t l = 0; l < strlen(Nick_name); l++)
131 if (Nick_name[l] == ' ')
132 Nick_name[l] = '_';
133 strcpy(Orignial_nick_name, nickname);
134 strcpy(Chat_tracker_id, trackerid);
135
136 Firstuser = nullptr;
137 Firstcommand = nullptr;
138 Chat_server_connected = 0;
139 FlushChatCommandQueue();
140
141 if (chat_port == 0) {
142 // AfxMessageBox("Invalid chat port, must be host.com:port (ie. irc.dal.net:6667)");
143 return -1;
144 }
145
146 Chatsock = socket(AF_INET, SOCK_STREAM, 0);
147 if (INVALID_SOCKET == Chatsock) {
148 // AfxMessageBox("Unable to open socket!");
149 return -1;
150 }
151
152 memset(&Chataddr, 0, sizeof(SOCKADDR_IN));
153 Chataddr.sin_family = AF_INET;
154 Chataddr.sin_addr.s_addr = INADDR_ANY;
155 Chataddr.sin_port = 0;
156
157 if (SOCKET_ERROR == bind(Chatsock, (SOCKADDR *)&Chataddr, sizeof(sockaddr))) {
158 // AfxMessageBox("Unable to bind socket!");
159 return -1;
160 }
161
162#ifdef WIN32
163 unsigned long arg = 1;
164 ioctlsocket(Chatsock, FIONBIO, &arg);
165#else // WIN32
166 fcntl(Chatsock, F_SETFL, fcntl(Chatsock, F_GETFL, 0) | O_NONBLOCK);
167#endif
168
169 /*
170 HOSTENT *he;
171 he = gethostbyname(chat_server);
172 if(!he)
173 {
174 //AfxMessageBox("Unable to gethostbyname.\n");
175 return -1;
176 }
177
178 memcpy(&Chataddr.sin_addr.s_addr, he->h_addr_list[0],4);//&iaddr, 4);
179
180 */

Callers 1

MainMultiplayerMenuFunction · 0.85

Calls 2

FlushChatCommandQueueFunction · 0.85
SendChatStringFunction · 0.85

Tested by

no test coverage detected