Exemplo n.º 1
0
void work::loginmsg(int st,int o_userid,const char* passwd)
{
	struct msg_t msg;
	memset(&msg,0,sizeof(msg));
	msg.head[0] = 2;
	msg.head[2] = 0;
	msg.head[3] = 0;
	
	if( (o_userid < 0) || (o_userid >= CLIENTCOUNT) )
	{
	     printf("login failed, %d:invaild userid\n",o_userid);
	     msg.head[1] = 1;
	     send(st,(const char*)&msg,sizeof(msg.head),0);
	     close(st);
	     return ;
	} 	
	if(!auth_passwd(o_userid,passwd))
	{
	   printf("login failed ,userid = %d ,passwd = %s :invailed password\n",o_userid,passwd);
	   msg.head[1] = 2;
	   send(st,(const char*)&msg,sizeof(msg.head),0);
	  close(st);
	 return ;
	   
	}
	printf("%d: login success\n",o_userid);
	fix_socket_client(o_userid,st);
	broadcast_user_status();	
}
Exemplo n.º 2
0
void work::loginmsg(int st, int o_userid, const char *passwd) //处理login消息
{
	struct msg_t msg;
	memset(&msg, 0, sizeof(msg));
	msg.head[0] = 2; //系统消息
	msg.head[2] = 0; //暂时保留,填0
	msg.head[3] = 0; //暂时保留,填0

	if ((o_userid < 0) || (o_userid >= CLIENTCOUNT)) //无效的userid
	{
		printf("login failed, %d:invalid userid\n", o_userid);
		msg.head[1] = 1; //无效userid
		send(st, (const char *) &msg, sizeof(msg.head), 0);
		close(st);
		return;
	}
	if (!auth_passwd(o_userid, passwd))//验证用户登录UserId和密码
	{
		printf("login failed, userid=%d,passwd=%s:invalid password\n", o_userid,
				passwd);
		msg.head[1] = 2; //无效密码
		//给client端socket下发系统消息
		send(st, (const char *) &msg, sizeof(msg.head), 0);
		close(st);//验证失败,关闭client socket,函数返回
		return;
	}

	printf("%d:login success\n", o_userid);
	fix_socket_client(o_userid, st); //将登录密码验证通过的客户端client安装到socket_client[]的数组中
	broadcast_user_status(); //向socket_client数组中所有socket广播用户状态消息
}