login::login(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::login)
{
    ui->setupUi(this);


    setWindowTitle("Welcome to Crypt-Chat!");


    mysocket = new QTcpSocket(this);
    buffer = new QBuffer(this);
    buffer->open(QIODevice::ReadWrite);
    ui->login_2->setDefault(true);


    this->connect(ui->createnew,SIGNAL(clicked()),this,SLOT(opennew()));
    this->connect(ui->changepass,SIGNAL(clicked()),this,SLOT(changepassw()));
    this->connect(ui->login_2,SIGNAL(clicked()),this,SLOT(checklogin()));
    connect(this, SIGNAL(enterlogin()), this, SLOT(checklogin()));
    this->connect(ui->settingsbutton,SIGNAL(clicked()), this, SLOT(settingsb()));

    connect(mysocket, SIGNAL(readyRead()), SLOT(receiveMessage()));
    connect(this, SIGNAL(loginfosend(string*)), SLOT(sendMessage(string*)));
    connect(this, SIGNAL(sendforkey(string*)), SLOT(sendMessage(string*)));
    connect(this, SIGNAL(logconnect()), SLOT(toggleConnection()));
    connect(this, SIGNAL(connectfailed()), this, SLOT(connectfalse()));
    connect(this, SIGNAL(connectworked()), this, SLOT(connecttrue()));

 }
Пример #2
0
qbool SV_Login(client_t *cl)
{
	extern cvar_t sv_registrationinfo;
	char info[256];
	char *ip;

	// is sv_login is disabled, login is not necessery
	if (!(int)sv_login.value)
	{
		SV_Logout(cl);
		cl->logged = -1;
		return true;
	}

	// if we're already logged return (probobly map change)
	if (cl->logged > 0)
		return true;

	// sv_login == 1 -> spectators don't login
	if ((int)sv_login.value == 1 && cl->spectator)
	{
		SV_Logout(cl);
		cl->logged = -1;
		return true;
	}

	// check for account for ip
	ip = va("%d.%d.%d.%d", cl->realip.ip[0], cl->realip.ip[1], cl->realip.ip[2], cl->realip.ip[3]);
	if ((cl->logged = checklogin(ip, ip, cl - svs.clients + 1, use_ip)) > 0)
	{
		strlcpy(cl->login, accounts[cl->logged-1].pass, CLIENT_LOGIN_LEN);
		return true;
	}

	// need to login before connecting
	cl->logged = false;
	cl->login[0] = 0;

	if (sv_registrationinfo.string[0])
	{
		strlcpy (info, sv_registrationinfo.string, 254);
		strlcat (info, "\n", 255);
		MSG_WriteByte (&cl->netchan.message, svc_print);
		MSG_WriteByte (&cl->netchan.message, PRINT_HIGH);
		MSG_WriteString (&cl->netchan.message, info);
	}
	MSG_WriteByte (&cl->netchan.message, svc_print);
	MSG_WriteByte (&cl->netchan.message, PRINT_HIGH);
	MSG_WriteString (&cl->netchan.message, "Enter your login and password:\n");

	return false;
}
Пример #3
0
void login(){
    int a;
    memmove(&comingbuf[0],&comingbuf[1], 1);
    char *User = strtok(comingbuf,"%");
    char *Pass = strtok(NULL,"%");
    a = checklogin(User,Pass);
    if (a == 0){
        write(sockfd,error,1);
    }
    if(a == 1){
        write(sockfd,succ,1);
    }
    bzero(comingbuf,LENG);
}
Пример #4
0
int main(){
int listen_sock;
int server_len, client_len;
struct sockaddr_in server_address;
struct sockaddr_in client_address;

listen_sock = socket(AF_INET, SOCK_STREAM, 0);
if (listen_sock == -1)
 {
    printf("khong tao duoc socket\n");
    return 0;
 }
 printf("Tao socket thanh cong\n");

server_address.sin_family = AF_INET;
inet_aton("127.0.0.1",&server_address.sin_addr);
server_address.sin_port = htons(5500);
server_len = sizeof(server_address);

if(bind(listen_sock, (struct sockaddr *)&server_address,server_len)<0)
{
	printf("bind failed.\n");
    return 0;
}
printf("bind done\n");
int check = listen(listen_sock, 10);
if (check == -1)
 {
 printf("error");
 return 0;
 }
printf("waiting connect ...\n");
while(1) {

client_len = sizeof(client_address);
conn_sock = accept(listen_sock,(struct sockaddr *)&client_address, &client_len);
if(conn_sock==-1){
	printf("error connect\n");
	return 0;
}else{
	printf("Accept new connection\n");
}
if(fork() == 0){
	close(listen_sock);
    //thiet lap truyen nhan giu lieu lien tuc
	int sentBytes,revedBytes,i;
    time_t start;
    struct tm * timeinfo;
    char name[30];
    char pass[16];
    struct userinfo acc1;
    char s[2]="|";
    char *token;
    int flag;
    char str_flag[3];
    char filename[]="data.txt";
    int stop = 0;
    FILE *f;
    FILE *result;
    int login;
    while((revedBytes = recv(conn_sock,buff,1024,0)) >= 0){
        buff[revedBytes]='\0';
        token = strtok(buff, s);
        strcpy(str_flag,token);
        flag=atoi(str_flag);
        //nhan va kiem tra co bao
        switch(flag){
            case 0:
                //kiem tra dang nhap neu dang nhap thang cong tra ve buff[0] = 5 
                //neu khong dung tra ve buff[0]=4 va buff[1] la ma loi
                printf("Dang nhap\n");
                token =strtok(NULL,s);
                strcpy(name,token);
                token=strtok(NULL,s);
                strcpy(pass,token);
                login = checklogin(name,pass);
                if(login==1){
                result =fopen(name,"w");
                buff[0] = 5;
                sentBytes = send(conn_sock,buff,1024,0);
                }else{
                    buff[0] = 4;
                    buff[1] = login;
                    sentBytes = send(conn_sock,buff,1024,0);
                }
            break;
            case 1: 
                token =strtok(NULL,s);
                strcpy(name,token);
                token=strtok(NULL,s);
                strcpy(pass,token);
                if(findAcc(name)==1){
                    buff[0] = 4;
                    buff[1] = 1;
                    buff[2] = '\0';
                    sentBytes = send(conn_sock,buff,1024,0);
                    break;
                }
                f =fopen(filename,"a");
                fprintf(f, "%s\t%s\n",name,pass );
                fclose(f);
                buff[0] = 5;
                buff[1] = '\0';
                sentBytes = send(conn_sock,buff,1024,0);
            break;
            case 2:
                side = 1 ;xside = 0;
                time (&start );
                timeinfo = localtime ( &start );
                fprintf(result,"IP address is: %s\n", inet_ntoa(client_address.sin_addr));
                fprintf (result,"time start :%s\n", asctime (timeinfo) );
                InitGen();
                while(1){
                    if(side == computerside){
                        ComputerThink();
                        printf("%d may choi\n",side);
                        fprintf(result,"%s-%s\n",indexChar(newmove.from),indexChar(newmove.dest));
                        UpdateNewMove();
                        buff[0] = 3;
                        buff[1] = newmove.from;
                        buff[2] = newmove.dest;
                        buff[3] = check_thua();stop = buff[3];
                        buff[4] = '\0';
                        send(conn_sock,buff,1024,0);
                        if(stop == 1)  break;
                    }
                    else 
                        if(GetHumanMove(0,1)==0){
                        fprintf(result,"%s-%s\t",indexChar(newmove.from),indexChar(newmove.dest));
                        UpdateNewMove();
                        printf("%d nguoi choi\n",side);                     
                        buff[0] = 3;
                        buff[1] = 1;
                        buff[2] = 0;
                        buff[3] = check_thang(); stop = buff[3];
                        buff[4] = '\0';
                        send(conn_sock,buff,1024,0);
                        //tra ve neu di thanh cong
                        if(stop == 1) break;
                    };
                    side = xside; xside = 1-xside;
                    printf("%d-%d-%d\n",side,newmove.from,newmove.dest);
            	}
            printf("Dung choi\n");
            time (&start );
            timeinfo = localtime ( &start );
            fprintf (result,"time end :%s\n", asctime (timeinfo));
            fclose(result);
            result = fopen(name,"r");
            while(!feof(result)){
                if (fgets(buff,81,result) != NULL ){
                sentBytes=send(conn_sock,buff,1024,0);
                }
            }
            buff[0] = 'Q';
            buff[1] = '\0';
            sentBytes=send(conn_sock,buff,1024,0);
            break;
            default:
            break;
        	    
        }
    }
    close(conn_sock);
    exit(0);
}
signal(SIGCHLD,sig_chld);
close(conn_sock);
}
return 1;
}
Пример #5
0
void SV_ParseLogin(client_t *cl)
{
	extern cvar_t sv_forcenick;
	char *log1, *pass;

	if (Cmd_Argc() > 2)
	{
		log1 = Cmd_Argv(1);
		pass = Cmd_Argv(2);
	}
	else
	{ // bah usually whole text in 'say' is put into ""
		log1 = pass = Cmd_Argv(1);
		while (*pass && *pass != ' ')
			pass++;

		if (*pass)
			*pass++ = 0;

		while (*pass == ' ')
			pass++;
	}

	// if login is parsed, we read just a password
	if (cl->login[0])
	{
		pass = log1;
		log1 = cl->login;
	}
	else
	{
		strlcpy(cl->login, log1, CLIENT_LOGIN_LEN);
	}

	if (!*pass)
	{
		strlcpy(cl->login, log1, CLIENT_LOGIN_LEN);
		MSG_WriteByte (&cl->netchan.message, svc_print);
		MSG_WriteByte (&cl->netchan.message, PRINT_HIGH);
		MSG_WriteString (&cl->netchan.message, va("Password for %s:\n", cl->login));

		return;
	}

	cl->logged = checklogin(log1, pass, cl - svs.clients + 1, use_log);

	switch (cl->logged)
	{
	case -2:
		MSG_WriteByte (&cl->netchan.message, svc_print);
		MSG_WriteByte (&cl->netchan.message, PRINT_HIGH);
		MSG_WriteString (&cl->netchan.message, "Login blocked\n");
		cl->logged = 0;
		cl->login[0] = 0;
		break;
	case -1:
		MSG_WriteByte (&cl->netchan.message, svc_print);
		MSG_WriteByte (&cl->netchan.message, PRINT_HIGH);
		MSG_WriteString (&cl->netchan.message, "Login in use!\ntry again:\n");
		cl->logged = 0;
		cl->login[0] = 0;
		break;
	case 0:
		MSG_WriteByte (&cl->netchan.message, svc_print);
		MSG_WriteByte (&cl->netchan.message, PRINT_HIGH);
		MSG_WriteString (&cl->netchan.message, va("Access denied\nPassword for %s:\n", cl->login));
		break;
	default:
		Sys_Printf("%s logged in as %s\n", cl->name, cl->login);
		MSG_WriteByte (&cl->netchan.message, svc_print);
		MSG_WriteByte (&cl->netchan.message, PRINT_HIGH);
		MSG_WriteString (&cl->netchan.message, va("Welcome %s\n", log1));

		//VVD: forcenick ->
		if ((int)sv_forcenick.value && cl->login)
		{
			char oldval[MAX_EXT_INFO_STRING];
			strlcpy (oldval, cl->name, MAX_EXT_INFO_STRING);

			Info_Set (&cl->_userinfo_ctx_, "name", cl->login);

			ProcessUserInfoChange (cl, "name", oldval);

			// Change name cvar in client
			MSG_WriteByte (&cl->netchan.message, svc_stufftext);
			MSG_WriteString (&cl->netchan.message, va("name %s\n", cl->login));
		}
		//<-

		MSG_WriteByte (&cl->netchan.message, svc_stufftext);
		MSG_WriteString (&cl->netchan.message, "cmd new\n");
	}
}