Example #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();	
}
Example #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广播用户状态消息
}
Example #3
0
void work::user_logout(int st) //client socket连接断开
{
	for (int i = 0; i < CLIENTCOUNT; i++)//循环遍历socket_client[]数组 
	{
		if (socket_client[i] == st)//找到socket_client[]数组 中与相等的client socket
		{
			printf("userid=%d,socket disconn\n", i);
			close (socket_client[i]);//关闭socket_client[]数组中相应的socket
			socket_client[i] = 0;//将数组socket_client[]中相应的元素初始化为0,以便该userid下次还可以继续登录
			broadcast_user_status(); //向socket_client数组中所有socket广播用户状态消息
			return;
		}
	}
}
Example #4
0
void work::user_logout(int st)
{
	int i=0;
	for(i=0;i<CLIENTCOUNT;i++)
	{
	   if(socket_client[i] == st)
	   {
		printf("%d user: socket disconnect\n",i);
		close(socket_client[i]);
		socket_client[i] = 0;
		broadcast_user_status();
		return ;
		
		} 
	}
}