예제 #1
0
void mempool_init()
{

    if(rand()%2 + 1)
        return;

    if(sizeof(struct node)%16 != 0) {
        ShowFatalError(read_message("Source.common.mempool_init"), sizeof(struct node));
        exit(EXIT_FAILURE);
    }

    // Global List start
    InitializeSpinLock(&l_mempoolListLock);
    l_mempoolList = NULL;

    // Initialize mutex + stuff needed for async allocator worker.
    l_async_terminate = 0;
    l_async_lock = ramutex_create();
    l_async_cond = racond_create();

    l_async_thread = rathread_createEx(mempool_async_allocator, NULL, 1024*1024,  RAT_PRIO_NORMAL);
    if(l_async_thread == NULL) {
        ShowFatalError(read_message("Source.common.mempool_init2"));
        exit(EXIT_FAILURE);
    }

}//end: mempool_init()
static char read_module_request(BANG_peer *self) {

    unsigned int *mod_name_length;
    if ((mod_name_length = (unsigned int*) read_message(self,4)) == NULL)
        return 0;

    char *mod_args;
    if ((mod_args = (char*) read_message(self, (*mod_name_length+4))) == NULL)
        return 0;

    // create new buffer to hold peer_id plus module name and version
    char *mod_buffer = (char*)malloc(*mod_name_length+4+sizeof(int));

    *mod_buffer = *mod_args;

    // Set last sizeof(int) bits to peer_id - may not be a good way to do this.
    mod_buffer[*mod_name_length+4] = self->peer_id;

    BANG_sigargs mod_exists_args;

    mod_exists_args.args = (void*) mod_buffer;
    mod_exists_args.length = *mod_name_length+4+sizeof(int);

    free(mod_name_length);

    BANG_send_signal(BANG_MODULE_REQUEST,&mod_exists_args,1);
    free(mod_buffer);
    free(mod_args);

    return 1;
}
예제 #3
0
void mempool_node_put(mempool p, void *data)
{
    struct node *node;

    node = DATA_TO_NODE(data);
#ifdef MEMPOOLASSERT
    if(node->magic != NODE_MAGIC) {
        ShowError(read_message("Source.common.mempool_node_put"), p->name,  data);
        return; // lost,
    }

    {
        struct pool_segment *node_seg = node->segment;
        if(node_seg->pool != p) {
            ShowError(read_message("Source.common.mempool_node_put2"), p->name, data, node_seg->pool);
            return;
        }
    }

    // reset used flag.
    node->used = false;
#endif

    //
    EnterSpinLock(&p->nodeLock);
    node->next = p->free_list;
    p->free_list = node;
    LeaveSpinLock(&p->nodeLock);

    InterlockedIncrement64(&p->num_nodes_free);

}//end: mempool_node_put()
예제 #4
0
파일: reader.c 프로젝트: hoffoo/itch
void read_message(itch_map* m, long len, long offset) {

    // done reading
    if (offset >= len) {
        free(data);
        return;
    }

    if (data[offset] == 0x00) {
        offset++;
        read_message(m, len, offset);
    }

    int msg_len = data[offset];
    if (msg_len < 1)  {
           printf("got bad message len, %i\n", data[offset]);
    }
    char* msg = malloc(msg_len);
    for (int i = 0; i < msg_len; i++) {
        msg[i] = data[offset+i];
    }

    itch_emit(m, msg);
    free(msg);

    offset += msg_len + 1;;

    read_message(m, len, offset);
}
예제 #5
0
void netbuffer_final() {
    sysint i;

    if(l_nPools > 0) {
        /// .. finalize mempools
        for(i = 0; i < l_nPools; i++) {
            mempool_stats stats = mempool_get_stats(l_pool[i]);

            ShowInfo(read_message("Source.net_buffer_final"), l_poolElemSize[i], stats.peak_nodes_used, stats.num_realloc_events);

            mempool_destroy(l_pool[i]);
        }

        if(l_nEmergencyAllocations > 0) {
            ShowWarning(read_message("Source.net_buffer-final2"), l_nEmergencyAllocations);
            l_nEmergencyAllocations = 0;
        }

        aFree(l_poolElemSize);
        l_poolElemSize = NULL;
        aFree(l_pool);
        l_pool = NULL;
        l_nPools = 0;
    }


}//end: netbuffer_final()
예제 #6
0
/* [Dekamaster/Nightroad] */
void mapif_parse_accinfo(int fd)
{
	int u_fd = RFIFOL(fd,2), aid = RFIFOL(fd,6), castergroup = RFIFOL(fd,10);
	char query[NAME_LENGTH], query_esq[NAME_LENGTH*2+1];
	int account_id;
	char *data;

	safestrncpy(query, (char *) RFIFOP(fd,14), NAME_LENGTH);

	Sql_EscapeString(sql_handle, query_esq, query);

	account_id = atoi(query);

	if(account_id < START_ACCOUNT_NUM) {    // is string
		if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `account_id`,`name`,`class`,`base_level`,`job_level`,`online` FROM `%s` WHERE `name` LIKE '%s' LIMIT 10", char_db, query_esq)
			|| Sql_NumRows(sql_handle) == 0) {
			if(Sql_NumRows(sql_handle) == 0) {
				inter_msg_to_fd(fd, u_fd, aid, read_message("Source.char.inter_parse_accinfo_s1"), query);
			} else {
				Sql_ShowDebug(sql_handle);
				inter_msg_to_fd(fd, u_fd, aid, read_message("Source.char.inter_parse_accinfo_s2"));
			}
			Sql_FreeResult(sql_handle);
			return;
		} else {
			if(Sql_NumRows(sql_handle) == 1) {  //we found a perfect match
				Sql_NextRow(sql_handle);
				Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data);
				Sql_FreeResult(sql_handle);
			} else {// more than one, listing... [Dekamaster/Nightroad]
				inter_msg_to_fd(fd, u_fd, aid, read_message("Source.char.inter_parse_accinfo_s3"), (int)Sql_NumRows(sql_handle));
				while (SQL_SUCCESS == Sql_NextRow(sql_handle)) {
					int class_;
					short base_level, job_level, online;
					char name[NAME_LENGTH];

					Sql_GetData(sql_handle, 0, &data, NULL); account_id = atoi(data);
					Sql_GetData(sql_handle, 1, &data, NULL); safestrncpy(name, data, sizeof(name));
					Sql_GetData(sql_handle, 2, &data, NULL); class_ = atoi(data);
					Sql_GetData(sql_handle, 3, &data, NULL); base_level = atoi(data);
					Sql_GetData(sql_handle, 4, &data, NULL); job_level = atoi(data);
					Sql_GetData(sql_handle, 5, &data, NULL); online = atoi(data);

					inter_msg_to_fd(fd, u_fd, aid, read_message("Source.char.inter_parse_accinfo_s4"), account_id, name, job_name(class_), base_level, job_level, online?"Online":"Offline");
				}
				Sql_FreeResult(sql_handle);
				return;
			}
		}
	}

	/* it will only get here if we have a single match */
	/* and we will send packet with account id to login server asking for account info */
	if(account_id) {
		mapif_on_parse_accinfo(account_id, u_fd, aid, castergroup, fd);
	}

	return;
}
int findMessageEdge(int min, int max, int key, int direction, int edge)
{
   if (max < min)
   {
      return -1;
   }

   int middle;
   int userMid;
   int userBelow;
   middle = (min + max)/2;
   message_t *message = malloc(sizeof(message_t));

   /* read in current middle to compare to matchstring */
   FILE *ifp = NULL;
   char filename [1024];
   sprintf(filename, "../../Data/Messages/message_%07d.dat", middle);
   ifp = fopen(filename, "rb");
   message = read_message(ifp);
   fclose(ifp);
   userMid = message->userID;
   free(message);

   /* catch end-case of mid being first element */
   if (middle == edge)
   {
      if (key == userMid)
      {
         return middle;
      }
      else
      {
         return -1;
      }
   }

   /* Reallocate memory for temporary location*/
   message = malloc(sizeof(message_t));
   sprintf(filename, "../../Data/Messages/message_%07d.dat", middle + direction);
   ifp = fopen(filename, "rb");
   message = read_message(ifp);
   fclose(ifp);
   userBelow = message->userID;
   free(message);

   if(key < userMid  || (direction == -1 && key == userBelow))
   {
      return findMessageEdge(min, middle - 1, key, direction, edge);
   }
   else if (key > userMid || (direction == 1 && key == userBelow))
   {
      return findMessageEdge(middle + 1, max, key, direction, edge);
   }
   else
   {
      return middle;
   }
}
예제 #8
0
/** Sends a user message to remote node via associated kernel connection. */
int send_user_message(int target_slot_type, int target_slot_index, int data_length, char* data) {
	struct nl_msg* msg = NULL;
	struct nl_msg *ans_msg = NULL;
	struct nlmsghdr *nl_hdr;
	struct genlmsghdr* genl_hdr;
	struct nlattr *nla;

	int ret_val = 0;

	if ( (ret_val=prepare_request_message(state.handle, DIRECTOR_SEND_GENERIC_USER_MESSAGE, state.gnl_fid, &msg) ) != 0 ) {
		goto done;
  	}

  	ret_val = nla_put_u32(msg,
			   DIRECTOR_A_SLOT_TYPE,
			   target_slot_type);
	if (ret_val != 0)
    		goto done;
    	
  	ret_val = nla_put_u32(msg,
			   DIRECTOR_A_SLOT_INDEX,
			   target_slot_index);
	if (ret_val != 0)
    		goto done;

  	ret_val = nla_put_u32(msg,
			   DIRECTOR_A_LENGTH,
			   data_length);
	if (ret_val != 0)
    		goto done;

	ret_val = nla_put(msg, DIRECTOR_A_USER_DATA, data_length, data);
	if (ret_val != 0)
    		goto done;

  	if ( (ret_val = send_request_message(state.handle, msg, 1) ) != 0 )
    		goto done;

	if ( (ret_val = read_message(state.handle, &ans_msg) ) != 0 ) {
	      goto done;
	}

	// TODO: We are not checking, the ack is for this request. Check it!
	while ( !is_ack_message(ans_msg) ) {
	    // We can get different than ack messega here.. in this case we have to process it
	    handle_incoming_message(ans_msg);
	    
	    if ( (ret_val = read_message(state.handle, &ans_msg) ) != 0 ) {
		  goto done;
	    }	  
	}

done:
	nlmsg_free(ans_msg);
	return ret_val;
}
예제 #9
0
void geoip_readdb(void)
{
	struct stat bufa;
	FILE *db=fopen("./db/GeoIP.dat","rb");
	fstat(fileno(db), &bufa);
	geoip_cache = (unsigned char *) malloc(sizeof(unsigned char) * bufa.st_size);
	if(fread(geoip_cache, sizeof(unsigned char), bufa.st_size, db) != bufa.st_size) {
		ShowError(read_message("Source.char.inter_geoip_readdb_s1"));
	}
	fclose(db);
	ShowStatus(read_message("Source.char.inter_geoip_readdb_s2"), CL_GREEN, CL_RESET);
}
예제 #10
0
파일: socket.c 프로젝트: Chocolate31/eamod
int make_connection(uint32 ip, uint16 port, bool silent)
{
	struct sockaddr_in remote_address;
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if(fd == -1) {
		ShowError(read_message("Source.common.make_connection"), error_msg());
		return -1;
	}
	if(fd == 0) {
		// reserved
		ShowError(read_message("Source.common.make_connection2"));
		sClose(fd);
		return -1;
	}
	if(fd >= FD_SETSIZE) {
		// socket number too big
		ShowError("make_connection: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd);

	remote_address.sin_family      = AF_INET;
	remote_address.sin_addr.s_addr = htonl(ip);
	remote_address.sin_port        = htons(port);

	if(!silent)
		ShowStatus(read_message("Source.common.make_connect"), CONVIP(ip), port);

	result = sConnect(fd, (struct sockaddr *)(&remote_address), sizeof(struct sockaddr_in));
	if(result == SOCKET_ERROR) {
		if(!silent)
			ShowError(read_message("Source.common.make_sConnect"), fd, error_msg());
		do_close(fd);
		return -1;
	}
	//Now the socket can be made non-blocking. [Skotlex]
	set_nonblocking(fd, 1);

	if(fd_max <= fd) fd_max = fd + 1;
	sFD_SET(fd,&readfds);

	create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse);
	session[fd]->client_addr = ntohl(remote_address.sin_addr.s_addr);

	return fd;
}
예제 #11
0
파일: socket.c 프로젝트: Chocolate31/eamod
int make_listen_bind(uint32 ip, uint16 port)
{
	struct sockaddr_in server_address;
	int fd;
	int result;

	fd = sSocket(AF_INET, SOCK_STREAM, 0);

	if(fd == -1) {
		ShowError(read_message("Source.common.make_listen_bind"), error_msg());
		exit(EXIT_FAILURE);
	}
	if(fd == 0) {
		// reserved
		ShowError(read_message("Source.common.make_listen_bind2"));
		sClose(fd);
		return -1;
	}
	if(fd >= FD_SETSIZE) {
		// socket number too big
		ShowError(read_message("Source.common.make_listen_bind3"), fd, FD_SETSIZE);
		sClose(fd);
		return -1;
	}

	setsocketopts(fd);
	set_nonblocking(fd, 1);

	server_address.sin_family      = AF_INET;
	server_address.sin_addr.s_addr = htonl(ip);
	server_address.sin_port        = htons(port);

	result = sBind(fd, (struct sockaddr *)&server_address, sizeof(server_address));
	if(result == SOCKET_ERROR) {
		ShowError(read_message("Source.common.make_listen_bind4"), fd, error_msg());
		exit(EXIT_FAILURE);
	}
	result = sListen(fd,5);
	if(result == SOCKET_ERROR) {
		ShowError(read_message("Source.common.make_listen_bind5"), fd, error_msg());
		exit(EXIT_FAILURE);
	}

	if(fd_max <= fd) fd_max = fd + 1;
	sFD_SET(fd, &readfds);

	create_session(fd, connect_client, null_send, null_parse);
	session[fd]->client_addr = 0; // just listens
	session[fd]->rdata_tick = 0; // disable timeouts on this socket

	return fd;
}
예제 #12
0
void network_do()
{
	struct EVDP_EVENT l_events[EVENTS_PER_CYCLE];
	register struct EVDP_EVENT *ev;
	register int n, nfds;
	register SESSION *s;

	nfds = evdp_wait(l_events,  EVENTS_PER_CYCLE, 1000);  // @TODO: timer_getnext()

	for(n = 0; n < nfds; n++) {
		ev = &l_events[n];
		s = &g_Session[ ev->fd ];

		if(ev->events & EVDP_EVENT_HUP) {
			network_disconnect(ev->fd);
			continue; // no further event processing.
		}// endif vent is HUP (disconnect)


		if(ev->events & EVDP_EVENT_IN) {

			if(s->onRecv != NULL) {
				if(false == s->onRecv(ev->fd)) {
					network_disconnect(ev->fd);
					continue; // ..
				}
			} else {
				ShowError(read_message("Source.common.network_do"), ev->fd);
				network_disconnect(ev->fd);
				continue;
			}

		}// endif event is IN (recv)


		if(ev->events & EVDP_EVENT_OUT) {
			if(s->onSend != NULL) {
				if(false == s->onSend(ev->fd)) {
					network_disconnect(ev->fd);
					continue;
				}
			} else {
				ShowError(read_message("Source.common.network_do2"), ev->fd);
				network_disconnect(ev->fd);
				continue;
			}
		}// endif event is OUT (send)

	}//endfor

}//end: network_do()
예제 #13
0
static void gear_up(void) {
	printf("SHIFT UP\n");
	IGNITION_CUT();
	gear(UP);

	uint32_t timer = get_tick() + 500;

	while(1) {
		if (get_tick() > timer) {
			gear(STOP);
			IGNITION_UNCUT();
			gear(DOWN);
			_delay_ms(100);
			gear(STOP);
			printf("DIDN'T REACH END\n");
			return;
		}

		if (can_has_data()) {
			struct can_message message;
			read_message(&message);
			if ((message.id == GEAR_STOP_BUTTON) && (message.data[0] == 2)) {
				gear(STOP);
				IGNITION_UNCUT();
				_delay_ms(50);
				gear(DOWN);

				uint32_t timer2 = get_tick() + 200;
				while(1) {
					if (get_tick() > timer2) {
						gear(STOP);
						printf("FAILED TO RELEASE AFTER SHIFT\n");
						return;
					}

					if (can_has_data()) {
						struct can_message message;
						read_message(&message);
						if ((message.id == GEAR_STOP_BUTTON) && (message.data[0] == 0)) {
							_delay_ms(100);
							gear(STOP);
							printf("PERFECT GEARSHIFT\n");
							return;
						}
					}
				}
			}
		}
	}
}
static char read_debug_message(BANG_peer *self) {
    unsigned int *length = (unsigned int*) read_message(self,LENGTH_OF_LENGTHS);
    if (length == NULL) {
        return 0;
    }
    char *message = (char*) read_message(self,*length);
    if (message == NULL) {
        return 0;
    }
    fprintf(stderr,"%s",message);
    free(message);
    return 1;

}
uint8_t read_file(uint32_t file_number)  //read the file and returns the pointer to file
{
	message m;
	uint8_t i;	
	
	if(CHECK_FILE_FLAG(file_number))	//
	{	
		for(i=0;i<messages_per_file;i++)
		{
			if(read_message(file_number,i));	
			{
				m=*ptr;
				tempf.sms[i]=m;	//storing the message
			}
			sd_delay(15);
		}		
	tempf.flag=0x11; //file exists
	ptrf=&tempf;
	return 0x00; // read file correctly
	}
	else
	{
		return 0x11;// file doesnot exists
	}	
}
예제 #16
0
/**
   Load or save all variables
*/
static bool load_or_save_variables_at_path(bool save, const std::string &path)
{
    bool result = false;

    debug(4, L"Open file for %s: '%s'",
          save?"saving":"loading",
          path.c_str());

    /* OK to not use CLO_EXEC here because fishd is single threaded */
    int fd = open(path.c_str(), save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600);
    if (fd >= 0)
    {
        /* Success */
        result = true;
        connection_t c(fd);

        if (save)
        {
            /* Save to the file */
            write_loop(c.fd, SAVE_MSG, strlen(SAVE_MSG));
            enqueue_all(&c);
        }
        else
        {
            /* Read from the file */
            read_message(&c);
        }

        connection_destroy(&c);
    }
    return result;
}
예제 #17
0
/** Registeres pid as a user-space director into the kernel */
static int register_pid(pid_t pid) {
	struct nl_msg* msg = NULL;
	struct nl_msg *ans_msg = NULL;
	struct nlmsghdr *nl_hdr;
	struct genlmsghdr* genl_hdr;
	struct nlattr *nla;

	int ret_val = 0;

	printf("Registering pid\n");	

	if ( (ret_val=prepare_request_message(state.handle, DIRECTOR_REGISTER_PID, state.gnl_fid, &msg) ) != 0 ) {
		goto done;
  	}
    	
  	ret_val = nla_put_u32(msg,
			   DIRECTOR_A_PID,
			   pid);
  	
	if (ret_val != 0)
    		goto done;

  	if ( (ret_val = send_request_message(state.handle, msg, 1) ) != 0 )
    		goto done;

	  if ( (ret_val = read_message(state.handle, &ans_msg) ) != 0 )
    		goto done;

done:
	nlmsg_free(ans_msg);
	return ret_val;
}
예제 #18
0
파일: show_help.c 프로젝트: aosm/openmpi
int opal_show_help(const char *filename, const char *topic, 
                   bool want_error_header, ...)
{
    int ret;
    va_list arglist;
    char **array = NULL;

    if (OPAL_SUCCESS != (ret = open_file(filename, topic))) {
        return ret;
    }
    if (OPAL_SUCCESS != (ret = find_topic(filename, topic))) {
        fclose(opal_show_help_yyin);
        return ret;
    }

    ret = read_message(&array);
    opal_show_help_finish_parsing();
    fclose(opal_show_help_yyin);
    if (OPAL_SUCCESS != ret) {
        destroy_message(array);
        return ret;
    }

    va_start(arglist, want_error_header);
    output(want_error_header, array, filename, topic, arglist);
    va_end(arglist);

    destroy_message(array);
    return ret;
}
/**
 * Add msg to the bunch of aggregated messages.
 */
static int aggregate_message(FILE *fp, struct message ***del_msg,
			     int *num_del_msg, struct file_header *f_hdr)
{
	struct message tmp_msg;
	long cur_pos = ftell(fp);
	struct message **tmp = *del_msg;
	int i;

	/* read message and rewind */
	if (read_message(fp, &tmp_msg, f_hdr->version, f_hdr->msgid_blkiomon))
		return -1;
	fseek(fp, cur_pos, SEEK_SET);

	/* append the message that we read to the array */
	if (tmp_msg.type != ZIOMON_DACC_GARBAGE_MSG) {
		*del_msg = malloc((*num_del_msg + 1)*sizeof(struct message*));
		for (i = 0; i < *num_del_msg; ++i)
			(*del_msg)[i] = tmp[i];
		if (*num_del_msg > 0)
			free(tmp);
		// add new msg at end
		(*del_msg)[*num_del_msg] = malloc(sizeof(struct message));
		*(*del_msg)[*num_del_msg] = tmp_msg;
		(*num_del_msg)++;
	}

	return 0;
}
예제 #20
0
int mapif_parse_SaveGuildStorage(int fd)
{
	int guild_id;
	int len;

	RFIFOHEAD(fd);
	guild_id = RFIFOL(fd,8);
	len = RFIFOW(fd,2);

	if(sizeof(struct guild_storage) != len - 12) {
		ShowError(read_message("Source.char.storage_saveguildstorage"), sizeof(struct guild_storage), len - 12);
	} else {
		if(SQL_ERROR == Sql_Query(sql_handle, "SELECT `guild_id` FROM `%s` WHERE `guild_id`='%d'", guild_db, guild_id))
			Sql_ShowDebug(sql_handle);
		else if(Sql_NumRows(sql_handle) > 0) {
			// guild exists
			Sql_FreeResult(sql_handle);
			guild_storage_tosql(guild_id, (struct guild_storage *)RFIFOP(fd,12));
			mapif_save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 0);
			return 0;
		}
		Sql_FreeResult(sql_handle);
	}
	mapif_save_guild_storage_ack(fd, RFIFOL(fd,4), guild_id, 1);
	return 0;
}
예제 #21
0
파일: socket.c 프로젝트: Chocolate31/eamod
const char *error_msg(void)
{
	static char buf[512];
	int code = sErrno;
	snprintf(buf, sizeof(buf), (read_message("Source.common.error_msg")), code, sErr(code));
	return buf;
}
uint8_t read_message_next(uint32_t file_number)//reads next message in queue
{
	uint8_t next;
	next=mat[file_number]->next;//getting valid sms no to read	
	
	return read_message(file_number,next); // Very easy na!
}
예제 #23
0
파일: socket.c 프로젝트: Chocolate31/eamod
/*======================================
 *  CORE : Socket options
 *--------------------------------------*/
void set_nonblocking(int fd, unsigned long yes)
{
	// FIONBIO Use with a nonzero argp parameter to enable the nonblocking mode of socket s.
	// The argp parameter is zero if nonblocking is to be disabled.
	if(sIoctl(fd, FIONBIO, &yes) != 0)
		ShowError(read_message("Source.common.set_nonblocking"), fd, error_msg());
}
예제 #24
0
파일: socket.c 프로젝트: Chocolate31/eamod
void setsocketopts(int fd)
{
	int yes = 1; // reuse fix
#if !defined(WIN32)
	// set SO_REAUSEADDR to true, unix only. on windows this option causes
	// the previous owner of the socket to give up, which is not desirable
	// in most cases, neither compatible with unix.
	sSetsockopt(fd,SOL_SOCKET,SO_REUSEADDR,(char *)&yes,sizeof(yes));
#ifdef SO_REUSEPORT
	sSetsockopt(fd,SOL_SOCKET,SO_REUSEPORT,(char *)&yes,sizeof(yes));
#endif
#endif

	// Set the socket into no-delay mode; otherwise packets get delayed for up to 200ms, likely creating server-side lag.
	// The RO protocol is mainly single-packet request/response, plus the FIFO model already does packet grouping anyway.
	sSetsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&yes, sizeof(yes));

	// force the socket into no-wait, graceful-close mode (should be the default, but better make sure)
	//(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winsock/winsock/closesocket_2.asp)
	{
		struct linger opt;
		opt.l_onoff = 0; // SO_DONTLINGER
		opt.l_linger = 0; // Do not care
		if(sSetsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&opt, sizeof(opt)))
			ShowWarning(read_message("Source.common.setsocketopts"), fd);
	}
}
예제 #25
0
bool buyingstore_setup(struct map_session_data *sd, unsigned char slots)
{
	if(!battle_config.feature_buying_store || sd->state.vending || sd->state.buyingstore || sd->state.trading || slots == 0) {
		return false;
	}

	if(sd->sc.data[SC_NOCHAT] && (sd->sc.data[SC_NOCHAT]->val1&MANNER_NOROOM)) {
		// custom: mute limitation
		return false;
	}

	if(map->list[sd->bl.m].flag.novending) {
		// custom: no vending maps
		clif_displaymessage(sd->fd, msg_txt(276)); // "You can't open a shop on this map"
		return false;
	}

	if(map->getcell(sd->bl.m, sd->bl.x, sd->bl.y, CELL_CHKNOVENDING)) {
		// custom: no vending cells
		clif_displaymessage(sd->fd, msg_txt(204)); // "You can't open a shop on this cell."
		return false;
	}

	if(slots > MAX_BUYINGSTORE_SLOTS) {
		ShowWarning(read_message("Source.map.map_buyingstore_s1"), (int)slots, MAX_BUYINGSTORE_SLOTS);
		slots = MAX_BUYINGSTORE_SLOTS;
	}

	sd->buyingstore.slots = slots;
	clif_buyingstore_open(sd);

	return true;
}
예제 #26
0
파일: main.c 프로젝트: dansgithubuser/bsod1
int main(int argc, char *argv[]) {
    char uart_port[8];
    unsigned i;

    bglib_output = output;

    for (i=0; i<100; ++i){
        sprintf(uart_port, "COM%d", i);
        if (!uart_open(uart_port)) break;
    }

    // Reset dongle to get it into known state
    ble_cmd_system_reset(0);
    uart_close();
    do {
        Sleep(500); // 0.5s
    } while (uart_open(uart_port));

    // Execute action
    ble_cmd_gap_discover(gap_discover_observation);

    // Message loop
    while (state != state_finish) {
        if (read_message(UART_TIMEOUT) > 0) break;
    }

    uart_close();

    return 0;
}
예제 #27
0
// initialize
int inter_init_sql(const char *file)
{
	//int i;

	inter_config_read(file);

	//DB connection initialized
	sql_handle = Sql_Malloc();
	ShowInfo(read_message("Source.char.inter_init_sql"));
	if(SQL_ERROR == Sql_Connect(sql_handle, char_server_id, char_server_pw, char_server_ip, (uint16)char_server_port, char_server_db)) {
		Sql_ShowDebug(sql_handle);
		Sql_Free(sql_handle);
		exit(EXIT_FAILURE);
	}

	if(*default_codepage) {
		if(SQL_ERROR == Sql_SetEncoding(sql_handle, default_codepage))
			Sql_ShowDebug(sql_handle);
	}

	wis_db = idb_alloc(DB_OPT_RELEASE_DATA);
	inter_guild_sql_init();
	inter_storage_sql_init();
	inter_party_sql_init();
	inter_pet_sql_init();
	inter_homunculus_sql_init();
	inter_mercenary_sql_init();
	inter_elemental_sql_init();
	inter_mail_sql_init();
	inter_auction_sql_init();

	geoip_readdb();
	msg_config_read("conf/messages.conf", false);
	return 0;
}
예제 #28
0
/*==========================================
 * read config file
 *------------------------------------------*/
static int inter_config_read(const char *cfgName)
{
	int i;
	char line[1024], w1[1024], w2[1024];
	FILE *fp;

	fp = fopen(cfgName, "r");
	if(fp == NULL) {
		ShowError(read_message("Source.reuse.reuse_file_not_found"), cfgName);
		return 1;
	}

	while(fgets(line, sizeof(line), fp)) {
		i = sscanf(line, "%[^:]: %[^\r\n]", w1, w2);
		if(i != 2)
			continue;

		if(!strcmpi(w1,"char_server_ip")) {
			strcpy(char_server_ip,w2);
		} else if(!strcmpi(w1,"char_server_port")) {
			char_server_port = atoi(w2);
		} else if(!strcmpi(w1,"char_server_id")) {
			strcpy(char_server_id,w2);
		} else if(!strcmpi(w1,"char_server_pw")) {
			strcpy(char_server_pw,w2);
		} else if(!strcmpi(w1,"char_server_db")) {
			strcpy(char_server_db,w2);
		} else if(!strcmpi(w1,"default_codepage")) {
			strcpy(default_codepage,w2);
		} else if(!strcmpi(w1,"party_share_level"))
			party_share_level = atoi(w2);
		else if(!strcmpi(w1,"party_family_share_level"))
			party_family_share_level = atoi(w2);
		else if(!strcmpi(w1,"log_inter"))
			log_inter = atoi(w2);
		else if(!strcmpi(w1,"db_name"))
			safestrncpy(tmp_db_name, w2, sizeof(tmp_db_name));
		else if(!strcmpi(w1,"import"))
			inter_config_read(w2);
	}
	fclose(fp);

	ShowConf(read_message("Source.reuse.reuse_loadfile_ok"), cfgName);

	return 0;
}
int get_complete_msg(FILE *fp, struct message_preview *msg_prev,
		     struct message *msg)
{
	long pos = ftell(fp);
	int rc;

	fseek(fp, msg_prev->pos, SEEK_SET);
	if (msg_prev->is_blkiomon_v2)
		// make sure message is converted
		rc = read_message(fp, msg, DATA_MGR_V2, msg_prev->type);
	else
		// use an arbitrary version != V2
		rc = read_message(fp, msg, DATA_MGR_V3, msg_prev->type);
	fseek(fp, pos, SEEK_SET);

	return rc;
}
static char read_hello(BANG_peer *self) {
    unsigned char *version = (unsigned char*) read_message(self,LENGTH_OF_VERSION);
    /* TODO: Make this more elegant =P */
    if (BANG_version_cmp(version,BANG_LIBRARY_VERSION) == 0) {
        free(version);
        return 0;
    }
    free(version);

    unsigned int *length = (unsigned int*) read_message(self,LENGTH_OF_LENGTHS);
    if (length == NULL) {
        return 0;
    }
    self->peername = (char*) read_message(self,*length);
    free(length);
    return 1;
}