Ejemplo n.º 1
0
int32_t Register::InitProfile(int32_t uid)
{

	int32_t ret = 0;

	PPlayerId init_id;
	init_id.set_uid(uid);
	init_id.set_zone_id(_req.zone_id());

	__BEGIN_PROC__

	PlayerID id;
	id.Init(init_id);
	bool exist;
	_p_profile = PlayerDataMgr::getInstance().Add(id, exist);
	if(NULL == _p_profile)
	{
		LOG_ERROR(_ctx, "alloc profile failed");
		ret = -1;
		break;
	}
	else if(exist)
	{
		LOG_ERROR(_ctx, "profile exist. %s", id.ToString().c_str());
		ret = -1;
		break;
	}

	time_t now = YAC_TimeProvider::getInstance()->getNow();

	//玩家id
	PPlayerId *player_id = _p_profile->mutable_player_id();
	player_id->set_uid(uid);
	player_id->set_zone_id(_req.zone_id());

	//账户充值消费信息
	PAccount *account = _p_profile->mutable_account();
	account->set_history_total(0);
	account->set_balance(0);
	account->set_last_recharge_time(0);
	account->set_last_consume_time(0);

	//游戏内代币
	PTokenMoney *token_money = _p_profile->mutable_token_money();
	token_money->set_gold(0);


	//玩家基础信息
	PBaseInfo *base_info = _p_profile->mutable_base_info();
	base_info->set_name(_req.name());
	base_info->set_register_time(now);
	base_info->set_login_time(now);
	base_info->set_gender(0);

	__END_PROC__

	return ret;

}
void LightweightDatabaseServer::Update(RakPeerInterface *peer)
{
	RakNetTime time=0;
	DatabaseTable *databaseTable;
	DataStructures::Page<unsigned, DataStructures::Table::Row*, _TABLE_BPLUS_TREE_ORDER> *cur;
	unsigned i,j;
	DataStructures::Table::Row* row;
	DataStructures::List<unsigned> removeList;
	PlayerID playerId;

	// periodic ping if removing system that do not respond to pings.
	for (i=0; i < database.Size(); i++)
	{
		databaseTable=database[i];

		if (databaseTable->removeRowOnPingFailure)
		{
			// Reading the time is slow - only do it once if necessary.
			if (time==0)
				 time = RakNet::GetTime();

			if (databaseTable->nextRowPingCheck < time)
			{
				databaseTable->nextRowPingCheck=time+1000+(randomMT()%1000);
				DataStructures::BPlusTree<unsigned, DataStructures::Table::Row*, _TABLE_BPLUS_TREE_ORDER> &rows = databaseTable->table.GetRows();
				cur = rows.GetListHead();
				while (cur)
				{
					// Mark dropped entities
					for (j=0; j < (unsigned)cur->size; j++)
					{
						row = cur->data[j];
						if (time - row->cells[databaseTable->lastPingResponseColumnIndex]->i > DROP_SERVER_INTERVAL)
							removeList.Insert(cur->keys[j]);
					}
					cur=cur->next;
				}

				// Remove dropped entities
				for (j=0; j < removeList.Size(); j++)
					databaseTable->table.RemoveRow(removeList[i]);
				removeList.Clear(true);

				cur = rows.GetListHead();
				// Ping remaining entities if they are not connected.  If they are connected just increase the ping interval.
				while (cur)
				{
					for (j=0; j < (unsigned)cur->size; j++)
					{
						row = cur->data[j];
						if (row->cells[databaseTable->nextPingSendColumnIndex]->i < (int) time)
						{
							row->cells[databaseTable->systemIdColumnIndex]->Get((char*)&playerId, 0);
							if (peer->GetIndexFromPlayerID(playerId)==-1)
							{
								peer->Ping(playerId.ToString(false), playerId.port, false);
							}
							else
							{
								// Consider the fact that they are connected to be a ping response
								row->cells[databaseTable->lastPingResponseColumnIndex]->i=time;
							}
							
							row->cells[databaseTable->nextPingSendColumnIndex]->i=time+SEND_PING_INTERVAL+(randomMT()%1000);
						}
					}
					cur=cur->next;
				}
			}
		}
	}
}