Exemplo n.º 1
0
static int on_bnetd_accountloginreply(t_connection * c, t_packet * packet)
{
	unsigned int	seqno;
	t_sq		* sq;
	t_packet	* opacket, * rpacket;
	t_connection	* client;
	int		result, reply;
	char const	* account;
	t_elem		* elem;

	if (!packet || !c)
	    return -1;

	seqno=bn_int_get(packet->u.d2cs_bnetd.h.seqno);
	if (!(sq=sqlist_find_sq(seqno))) {
		eventlog(eventlog_level_error,__FUNCTION__,"seqno %d not found",seqno);
		return -1;
	}
	if (!(client=d2cs_connlist_find_connection_by_sessionnum(sq_get_clientid(sq)))) {
		eventlog(eventlog_level_error,__FUNCTION__,"client %d not found",sq_get_clientid(sq));
		sq_destroy(sq,&elem);
		return -1;
	}
	if (!(opacket=sq_get_packet(sq))) {
		eventlog(eventlog_level_error,__FUNCTION__,"previous packet missing (seqno: %d)",seqno);
		sq_destroy(sq,&elem);
		return -1;
	}
	result=bn_int_get(packet->u.bnetd_d2cs_accountloginreply.reply);
	if (result==BNETD_D2CS_CHARLOGINREPLY_SUCCEED) {
		reply=D2CS_CLIENT_LOGINREPLY_SUCCEED;
		account=packet_get_str_const(opacket,sizeof(t_client_d2cs_loginreq),MAX_CHARNAME_LEN);
		d2cs_conn_set_account(client,account);
		d2cs_conn_set_state(client,conn_state_authed);
		eventlog(eventlog_level_info,__FUNCTION__,"account %s authed",account);
	} else {
		eventlog(eventlog_level_warn,__FUNCTION__,"client %d login request was rejected by bnetd",sq_get_clientid(sq));
		reply=D2CS_CLIENT_LOGINREPLY_BADPASS;
	}
	if ((rpacket=packet_create(packet_class_d2cs))) {
		packet_set_size(rpacket,sizeof(t_d2cs_client_loginreply));
		packet_set_type(rpacket,D2CS_CLIENT_LOGINREPLY);
		bn_int_set(&rpacket->u.d2cs_client_loginreply.reply,reply);
		conn_push_outqueue(client,rpacket);
		packet_del_ref(rpacket);
	}
	sq_destroy(sq,&elem);
	return 0;
}
Exemplo n.º 2
0
int main(void)
{
  StackQueue* sq = sq_create(10);
  printf("Create: "); sq_print(sq);
  printf("Push: "); sq_push(sq, 5); sq_print(sq);
  printf("Enqueue: "); sq_enqueue(sq, 6); sq_print(sq);
  printf("Push: "); sq_push(sq, 7); sq_print(sq);
  printf("Popped: %u ", sq_pop(sq)); sq_print(sq);
  printf("Dequeued: %u ", sq_dequeue(sq)); sq_print(sq);

  // Extra
  printf("Push: "); sq_push(sq, 1); sq_print(sq);
  printf("Push: "); sq_push(sq, 2); sq_print(sq);
  printf("Push: "); sq_push(sq, 3); sq_print(sq);
  printf("Push: "); sq_push(sq, 4); sq_print(sq);
  printf("Push: "); sq_push(sq, 5); sq_print(sq);
  printf("Push: "); sq_push(sq, 6); sq_print(sq);
  printf("Dequeued: %u ", sq_dequeue(sq)); sq_print(sq);
  printf("Dequeued: %u ", sq_dequeue(sq)); sq_print(sq);
  printf("Dequeued: %u ", sq_dequeue(sq)); sq_print(sq);
  printf("Dequeued: %u ", sq_dequeue(sq)); sq_print(sq);
  printf("Dequeued: %u ", sq_dequeue(sq)); sq_print(sq);
  printf("Dequeued: %u ", sq_dequeue(sq)); sq_print(sq);
  printf("Dequeued: %u ", sq_dequeue(sq)); sq_print(sq);

  sq_destroy(sq);

  return EXIT_SUCCESS;
}
Exemplo n.º 3
0
extern int sqlist_destroy(void)
{
	t_sq	 * sq;

	BEGIN_LIST_TRAVERSE_DATA_CONST(sqlist_head,sq)
	{
		sq_destroy(sq,(t_elem **)curr_elem_);
	}
Exemplo n.º 4
0
int main()
{
    // 创建或打开队列
	long shmkey = 0x1234;
	int element_size = 64; // 基本块的大小,如果数据小于1个块,就按1个块存储,否则,存储到连续多个块中,只有第一个块有块头部信息
	int element_count = 1024; // 队列的长度,总共有多少个块
	struct sq_head_t *sq = sq_create(0x1234, element_size, element_count);

	// 如果需要开启signal通知功能,设置一下通知的参数
	sq_set_sigparam(sq, SIGUSR1, 1, 2);

	// 现在可以开始写数据了
	char *data = "hello hello I am writer";
	if(sq_put(sq, data, strlen(data))<0)
	{
		// 队列满了。。。
	}
      sq_destroy(sq);
	return 0;
}
Exemplo n.º 5
0
static int on_bnetd_charloginreply(t_connection * c, t_packet * packet)
{
	unsigned int	seqno;
	t_sq		* sq;
	t_connection	* client;
	t_packet	* opacket, * rpacket;
	int		result, reply, type;
	char const	* charname;
	t_elem		* elem;

	if (!packet || !c)
	    return -1;

	seqno=bn_int_get(packet->u.d2cs_bnetd.h.seqno);
	if (!(sq=sqlist_find_sq(seqno))) {
		eventlog(eventlog_level_error,__FUNCTION__,"seqno %d not found",seqno);
		return -1;
	}
	if (!(client=d2cs_connlist_find_connection_by_sessionnum(sq_get_clientid(sq)))) {
		eventlog(eventlog_level_error,__FUNCTION__,"client %d not found",sq_get_clientid(sq));
		sq_destroy(sq,&elem);
		return -1;
	}
	if (!(opacket=sq_get_packet(sq))) {
		eventlog(eventlog_level_error,__FUNCTION__,"previous packet missing (seqno: %d)",seqno);
		sq_destroy(sq,&elem);
		return -1;
	}
	type=packet_get_type(opacket);
	result=bn_int_get(packet->u.bnetd_d2cs_charloginreply.reply);
	if (type==CLIENT_D2CS_CREATECHARREQ) {
		charname=packet_get_str_const(opacket,sizeof(t_client_d2cs_createcharreq),MAX_CHARNAME_LEN);
		if (result==BNETD_D2CS_CHARLOGINREPLY_SUCCEED) {
			if (conn_check_multilogin(client,charname)<0) {
				eventlog(eventlog_level_error,__FUNCTION__,"character %s is already logged in",charname);
				reply = D2CS_CLIENT_CHARLOGINREPLY_FAILED;
			} else {
				reply= D2CS_CLIENT_CREATECHARREPLY_SUCCEED;
				eventlog(eventlog_level_info,__FUNCTION__,"character %s authed",charname);
				d2cs_conn_set_charname(client,charname);
				d2cs_conn_set_state(client,conn_state_char_authed);
			}
		} else {
			reply = D2CS_CLIENT_CREATECHARREPLY_FAILED;
			eventlog(eventlog_level_error,__FUNCTION__,"failed to auth character %s",charname);
		}
		if ((rpacket=packet_create(packet_class_d2cs))) {
			packet_set_size(rpacket,sizeof(t_d2cs_client_createcharreply));
			packet_set_type(rpacket,D2CS_CLIENT_CREATECHARREPLY);
			bn_int_set(&rpacket->u.d2cs_client_createcharreply.reply,reply);
			conn_push_outqueue(client,rpacket);
			packet_del_ref(rpacket);
		}
	} else if (type==CLIENT_D2CS_CHARLOGINREQ) {
		charname=packet_get_str_const(opacket,sizeof(t_client_d2cs_charloginreq),MAX_CHARNAME_LEN);
		if (result==BNETD_D2CS_CHARLOGINREPLY_SUCCEED) {
			if (conn_check_multilogin(client,charname)<0) {
				eventlog(eventlog_level_error,__FUNCTION__,"character %s is already logged in",charname);
				reply = D2CS_CLIENT_CHARLOGINREPLY_FAILED;
			} else {
				reply = D2CS_CLIENT_CHARLOGINREPLY_SUCCEED;
				eventlog(eventlog_level_info,__FUNCTION__,"character %s authed",charname);
				d2cs_conn_set_charname(client,charname);
				d2cs_conn_set_state(client,conn_state_char_authed);
			}
		} else {
			reply = D2CS_CLIENT_CHARLOGINREPLY_FAILED;
			eventlog(eventlog_level_error,__FUNCTION__,"failed to auth character %s",charname);
		}
		if ((rpacket=packet_create(packet_class_d2cs))) {
			packet_set_size(rpacket,sizeof(t_d2cs_client_charloginreply));
			packet_set_type(rpacket,D2CS_CLIENT_CHARLOGINREPLY);
			bn_int_set(&rpacket->u.d2cs_client_charloginreply.reply,reply);
			conn_push_outqueue(client,rpacket);
			packet_del_ref(rpacket);
		}
	} else {
		eventlog(eventlog_level_error,__FUNCTION__,"got bad packet type %d",type);
		sq_destroy(sq,&elem);
		return -1;
	}
	sq_destroy(sq,&elem);
	return 0;
}