Exemplo n.º 1
0
void PlayerUpdate( )
{
	uint8_t i;
	struct Player * p = &Players[playerid];

	if( latch_setting_value )
	{
	}
	if( hasset_value )
	{
		hasset_value--;
	}
	SblockInternal( 4, 64, 2, 69, hasset_value?6:14 );
	SblockInternal( 4, 64, 1, 69, latch_setting_value?6:14 );

	switch( p->update_number & 7 )
	{
	case 0:
		SblockInternal( 3, 64, 3, 68, 2 ); //create sign
		SignUp( 3, 64, 3, "Addr", regaddr_set );
		for( i = 0; i < 8; i++ )
		{
			SblockInternal( 4, 64, i+4, 69, ((regaddr_set)&(1<<i))?17:9 );
			SblockInternal( 3, 64, i+4, 35, ((regaddr_set)&(1<<i))?0:15 );
		}
		break;
	case 1:
		SblockInternal( 6, 64, 3, 68, 2 ); //create sign
		SignUp( 6, 64, 3, "Value", regval_set );
		for( i = 0; i < 8; i++ )
		{
			SblockInternal( 7, 64, i+4, 69, ((regval_set)&(1<<i))?17:9 );
			SblockInternal( 6, 64, i+4, 35, ((regval_set)&(1<<i))?0:15 );
		}
		break;
	case 2:
		SblockInternal( 9, 64, 3, 68, 2 ); //create sign
		SignUp( 9, 64, 3, "Read", regaddr_get );
		for( i = 0; i < 8; i++ )
		{
			SblockInternal( 10, 64, i+4, 69, ((regaddr_get)&(1<<i))?17:9 );
			SblockInternal( 9, 64, i+4, 35, ((regaddr_get)&(1<<i))?0:15 );
		}
		break;
	case 3:
	{
		SblockInternal( 12, 64, 3, 68, 2 ); //create sign
		SignUp( 12, 64, 3, "Read Value", regval_get );
		for( i = 0; i < 8; i++ )
		{
			SblockInternal( 12, 64, i+4, 35, ((regval_get)&(1<<i))?0:15 );
		}
		break;
	}
	default:
		break;
	}
}
Exemplo n.º 2
0
//void newProcessForClient(int conn_fd, struct sockaddr_in serv_addr, struct OnlineUser * userlist)
void newPthreadForClient(int * conn_fd) 
{
	char buf[500];
	char recvfrom[10];
	char message[500];
	char sendto[10];
	int i, j;
	int stat;
	int CONN_FD;
	struct UserInfo user;
	struct Package package;
	int send_to_fd;
	char oder[20];
	
	CONN_FD = *conn_fd;
	
	printf("##server : now is newProcessForClient \n##Waiting for Log in\n");
	printf("##server : conn_fd : %d\n", CONN_FD);
	if(recv(CONN_FD, &user,sizeof(user), 0) == 0)
	{
		pthread_exit(0);
	}
	
	printf("##server : received %d\n", user.flag);
	printf("##server : received %s\n", user.name);
	printf("##server : received %s\n", user.passwd);
	
	if(user.flag == 1)
	{
		//登陆 signIn
		stat = SignIn(CONN_FD,user);
		printf("stat = %d\n", stat);
		if(stat == 1)
		{
			AddUser(user.name,CONN_FD);
			ShowUser();
			send(CONN_FD, &stat, sizeof(stat), 0);
		}
		else
		{
			send(CONN_FD, &stat, sizeof(stat), 0);
			pthread_exit(0);		
		}
	}
	
	if(user.flag == 2)
	{
		//注册signUp
		SignUp(CONN_FD, user); 
		pthread_exit(0);
	}
//	strcpy(recvfrom ,  user.name);
	OnLineHint(user.name);	
	while(1)  
	{ //解析信息
		printf("##server : waitting for massage form %s\n", user.name);
		memset(buf, 0, sizeof(buf));		
				
		if(recv(CONN_FD, &package, sizeof(package), 0) == 0)
		{
			printf("%s off line\n", user.name);
			OffLine(user.name);
			pthread_exit(0);
		} //下线
		
			
		
		if(package.order == 1 && strcmp(package.sendto, "all") == 0)
			{
				SendToAll(package);
				printf("now is send all\n");
				continue;
			}
		
		send_to_fd = find_fd(package.sendto);
		if(package.order == 1)
		{	
			if(send_to_fd == -1)
			{
				continue;
			}
			if(send(send_to_fd, &package, sizeof(package), 0) == 0)
			{
				printf("send error\n");
				continue;
			}			
		}	
		
		if(package.order == 2)
		{
			if(strcmp(package.message, "show") == 0)
			{
				ShowOnlineUser(CONN_FD);
			}
		}
	}	
}