# include & lt; Winsock2. H>
#include
#include
#include
#include
#include
#include
#include
#include
#include
# pragma comment (lib, "ws2_32. Lib")
# define STR_MAX_LEN 200
# define NAME_LEN 20
# define PWD_LEN 16
# define MML_LEN 10
# define SEND_LEN STR_MAX_LEN + NAME_LEN + 2
# define DK 5327
using namespace std;
Ofstream Sf.
Const int MAX_ONLINE=20;
Const char Server_IP []="172.17.0.3";//"127.0.0.1";
Const char Warn_Buf []="It 's over Max connect!" ,
Aok [2]="0",
Anok [2]="1",
Anok2 [2]="2",
Azok [2]="0",
Aznok [2]="1",
Ml [100]="";
The list & lt; The SOCKET & gt; The online;
Bool online_using=0;
Char name [NAME_LEN];
The FILE * fp, * fp2;
Void NewHandle (SOCKET & amp; SockFrom);
Void Wrong_exit (const char * Error_place, int _Code) {
Printf (" % s wrong! At: % d \ n ", Error_place, _Code);
system("pause");
The exit (_Code);
}
Void show_time () {
The static char time_l [20], time_n [20].
The static time_t timep;
{
Time (& amp; Timep);
Strftime (time_n, sizeof (time_n), "% % Y - m - H: % d % % m", a localtime (& amp; Timep));
If (STRCMP (time_l time_n)) {
Strcpy (time_l time_n);
Printf ("//% s \ n ", time_n);
}
}
}
Void broadcast (const char * name, const char * send_buf) {
The static char ls_send [SEND_LEN];
Strcpy (ls_send, name);
Strcat (ls_send, ":");
Strcat (ls_send send_buf);
Freopen (" rr. TXT ", "a", stdout);
Printf (" % s \ n ", ls_send);
Freopen (" CON ", "a", stdout);
While (online_using);
Online_using=1;
For (auto I=online. The begin (); i !=online. The end (); I++)
Send (* I, ls_send SEND_LEN, 0).
Online_using=0;
//cout<& lt;" Aaas \ n ";
}
Void flash_online_num () {
The static char title [100].
If (online. The empty ()) strcpy (title, "the title=bb - xjrjyy - Server");
The else sprintf (title, "the title=bb - xjrjyy - Server online_now: : % d", online. The size ());
The system (the title);
}
DWORD WINAPI child_thread (LPVOID V_sock) {
The SOCKET hsock=(SOCKET) V_sock;
Char PWD [PWD_LEN], PWDTMP [PWD_LEN], MML [MML_LEN];
Char recvbuf [STR_MAX_LEN], tmpbuf [NAME_LEN + 10], TMPCD [NAME_LEN + 105].
Bool fa=0, ydl=1;
Int FHZ=1;
While (ydl) {
While (online_using);
Online_using=1;
Bool ZCF=0, DLF=0;
FHZ=recv (hsock, MML, MML_LEN, 0);
If (STRCMP (MML, "tc")==0/* STRCMP (MML, "zc")==0 | | STRCMP (MML, "dl")==0 */) {
FHZ=recv (hsock, MML, MML_LEN, 0);
}
If (STRCMP (MML, "zc")==0) {
ZCF=1;
}
If (STRCMP (MML, "dl")==0) {
DLF=1;
}
FHZ=recv (hsock, name, NAME_LEN, 0);
FHZ=recv (hsock, PWD, PWD_LEN, 0);
//for (int iz=0; Iz//cout//cout<1 & lt; Sprintf (TMPCD, "% s % s.t xt, ml, name);
If (ZCF) {
Freopen (TMPCD, "r", stdin);
If (the scanf (" % s ", PWDTMP)!=1 & amp; & STRCMP (PWDTMP, "")!=0) {
Send (hsock aznok, strlen (aznok) + 1, 0).
The fclose (stdin);
Online_using=0;
continue;
}
The fclose (stdin);
Fp=fopen (TMPCD, "w");
Fprintf (fp, "% s", the PWD).
fclose(fp);
//freopen (TMPCD, "w", stdout);
//printf (" % s ", the PWD);
//freopen (" CON ", "a", stdout);
Printf (" % s register Successful! \ n ", name);
Send (hsock azok, strlen (azok) + 1, 0).
//return 0;
Online_using=0;
continue;
} the else
If (DLF) {
//send (hsock, aok, strlen (aok), 0).
Freopen (TMPCD, "r", stdin);
If (the scanf (" % s ", PWDTMP)==1 | | STRCMP (PWDTMP, "")==0) {
Send (hsock anok2, strlen (anok2) + 1, 0).
The fclose (stdin);
Online_using=0;
continue;
}
The fclose (stdin);
If (STRCMP (PWD, PWDTMP)==0) {
Online_using=0;
Send (hsock aok, strlen (aok), 0).
} else {
Online_using=0;
Send (hsock anok, strlen (anok) + 1, 0).
continue;
}
} else {
Online_using=0;
continue;
}
//recv (SockFrom, recvbuf STR_MAX_LEN, 0).
Online. The push_back (hsock);
//coutOnline_using=0;
Ydl=0;
}
Show_time ();
Printf (" % s login Successful! \ n ", name);
Flash_online_num ();
While (true) {
FHZ=recv (hsock, MML, MML_LEN, 0);
if(! STRCMP (recvbuf, "word: : EXIT") | | FHZ==0 | | FHZ==SOCKET_ERROR) break;
If (STRCMP (MML, "lt")==0) {
FHZ=recv (hsock, recvbuf STR_MAX_LEN, 0).
if(! STRCMP (recvbuf, "word: : EXIT") | | FHZ==0 | | FHZ==SOCKET_ERROR) break;
Broadcast (name, recvbuf);
} else {
If (STRCMP (MML, "tc")==0/* STRCMP (MML, "zc")==0 | | STRCMP (MML, "dl")==0 */) {
Fa=1; break;
}
}
Sleep (10);
}
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull