示例#1
0
void Gate::OnRecvDistributeAck(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs & args) {
	s64 agentId = args.GetDataInt64(0);
	s64 actorId = args.GetDataInt64(1);
	s32 logic = args.GetDataInt32(2);

	if (_players.find(agentId) != _players.end()) {
		if (logic > 0) {
			Player& player = _players[agentId];
			OASSERT(player.state == ST_DISTRIBUTE, "wtf");

			player.selectActorId = actorId;
			player.logic = logic;
			player.state = ST_BINDING;

			_actors[actorId] = agentId;
			_logicPlayers[logic].insert(agentId);

			IArgs<2, 32> args;
			args << actorId << player.accountId;
			args.Fix();

			_harbor->Send(user_node_type::LOGIC, logic, framework_proto::BIND_PLAYER, args.Out());
		}
		else {
			Reset(kernel, agentId, ST_ROLELOADED, node_type::USER);

			olib::Buffer<128> buf;
			buf << _errorDistributeLogicFailed;
			SendToClient(kernel, agentId, _selectRoleAckId, buf.Out());
		}
	}
}
示例#2
0
void Gate::OnBindLogicAck(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs & args) {
	s64 actorId = args.GetDataInt64(0);
	s64 accountId = args.GetDataInt64(1);
	s32 errorCode = args.GetDataInt32(2);

	if (_actors.find(actorId) != _actors.end()) {
		OASSERT(_players.find(_actors[actorId]) != _players.end(), "wtf");
		Player& player = _players[_actors[actorId]];
		OASSERT(player.state == ST_BINDING && actorId == player.selectActorId, "wtf");

		if (errorCode) {
			player.state = ST_ONLINE;
			player.lastActorId = actorId;

			ICacheDBContext * writer = _cacheDB->PrepareWrite("account", player.accountId);
			writer->WriteInt64("id", player.accountId);
			writer->WriteInt64("lastActor", actorId);
			writer->Update();

			const s32 tokenCount = args.GetDataInt32(3);
		}
		else {
			Reset(kernel, _actors[actorId], ST_ROLELOADED, node_type::USER);

			olib::Buffer<128> buf;
			buf << _errorBindLogicFailed;
			SendToClient(kernel, _actors[actorId], _selectRoleAckId, buf.Out());
		}
	}
}
示例#3
0
void Slave::OpenNewNode(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs & args) {
	s32 newNodeType = args.GetDataInt32(0);
	s32 newNodeId = args.GetDataInt32(1);

	OASSERT(_executes.find(newNodeType) != _executes.end(), "unknown nodeType %d", newNodeType);

	s64 node = (((s64)newNodeType) << 32) | newNodeId;
	auto itr = _cmds.find(node);
	if (itr != _cmds.end())
		StartNode(kernel, itr->second.cmd);
	else
		StartNewNode(kernel, _executes[newNodeType].name, _executes[newNodeType].cmd, newNodeType, newNodeId);
}
示例#4
0
void Harbor::Brocast(s32 nodeType, const s32 messageId, const OArgs& args) {
	for (auto itr = _nodes[nodeType].begin(); itr != _nodes[nodeType].end(); ++itr) {
		if (!itr->second->PrepareSendNodeMessage(args.GetSize() + sizeof(s32))) {
			OASSERT(false, "send failed");
		}

		if (!itr->second->SendNodeMessage(&messageId, sizeof(s32))) {
			OASSERT(false, "send failed");
			return;
		}

		if (!itr->second->SendNodeMessage(args.GetContext(), args.GetSize())) {
			OASSERT(false, "send failed");
		}
	}
}
示例#5
0
void Gate::OnRecvBindAccountAck(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs & args) {
	s64 agentId = args.GetDataInt64(0);
	s64 accountId = args.GetDataInt64(1);
	s32 errorCode = args.GetDataInt32(2);
	s32 tokenCount = args.GetDataInt32(3);

	if (_players.find(agentId) != _players.end()) {
		Player& player = _players[agentId];
		OASSERT(player.state == ST_AUTHENING && player.accountId == accountId, "wtf");
		if (player.accountId != accountId)
			return;

		if (errorCode == 0) {
			bool ret = _roleMgr->GetRoleList(accountId, [&player](IKernel * kernel, s64 actorId, IRole * role) {
				player.roles.push_back({ actorId, role });
			});

			if (ret) {
				TokenData data = { player.accountId, 0, (s32)(tools::GetTimeMillisecond() / 1000), tokenCount };
				char token[MAX_TOKEN_SIZE + 1];
				BuildToken(token, sizeof(token) - 1, data);

				olib::Buffer<4096> buf;
				buf << _noError << token << (s32)player.roles.size();
				for (const auto& role : player.roles) {
					buf << role.actorId;
					role.role->Pack(buf);
				}

				SendToClient(kernel, player.agentId, _loginAckId, buf.Out());
			}
			else {
				Reset(kernel, agentId, ST_NONE, node_type::USER);

				olib::Buffer<128> buf;
				buf << _errorLoadRoleListFailed;
				SendToClient(kernel, player.agentId, _loginAckId, buf.Out());
			}
		}
		else {
			olib::Buffer<128> buf;
			buf << errorCode;
			SendToClient(kernel, player.agentId, _loginAckId, buf.Out());
		}
	}
}
示例#6
0
void Redis::Append(CommandBuff& buf, const OArgs& args) {
	for (s32 i = 0; i < args.Count(); i++) {
		switch (args.GetType(i)) {
		case ArgType::TYPE_STRING: Append(buf, args.GetDataString(i)); break;
		//case ArgType::TYPE_STUCT: Append(buf, args.GetDataStruct(i)); break;
		case ArgType::TYPE_FLOAT: Append(buf, args.GetDataFloat(i)); break;
		case ArgType::TYPE_INT64: Append(buf, args.GetDataInt64(i)); break;
		case ArgType::TYPE_INT32: Append(buf, args.GetDataInt32(i)); break;
		case ArgType::TYPE_INT16: Append(buf, args.GetDataInt16(i)); break;
		case ArgType::TYPE_INT8: Append(buf, args.GetDataInt8(i)); break;
		case ArgType::TYPE_BOOL: Append(buf, args.GetDataBool(i) ? 1 : 0); break;
		}
	}
}
示例#7
0
void Gate::OnRecvKickFromAccount(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs & args) {
	s64 agentId = args.GetDataInt64(0);
	if (_players.find(agentId) != _players.end()) {
		Player& player = _players[agentId];
		OASSERT(player.state >= ST_ROLELOADED, "wtf");

		Reset(kernel, agentId, ST_NONE, user_node_type::ACCOUNT);
	}
}
示例#8
0
void Gate::OnRecvKickFromLogic(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs & args) {
	s64 actorId = args.GetDataInt64(0);
	if (_actors.find(actorId) != _actors.end()) {
		OASSERT(_players.find(_actors[actorId]) != _players.end(), "wtf");
		Player& player = _players[_actors[actorId]];
		OASSERT(player.state == ST_ONLINE && player.logic == nodeId, "wtf");

		Reset(kernel, _actors[actorId], ST_NONE, user_node_type::LOGIC);
	}
}
示例#9
0
void Harbor::Send(s32 nodeType, s32 nodeId, const s32 messageId, const OArgs& args) {
	auto itr = _nodes[nodeType].find(nodeId);
	if (itr != _nodes[nodeType].end()) {
		if (!itr->second->PrepareSendNodeMessage(args.GetSize() + sizeof(s32))) {
			OASSERT(false, "send failed");
			return;
		}

		if (!itr->second->SendNodeMessage(&messageId, sizeof(s32))) {
			OASSERT(false, "send failed");
			return;
		}

		if (!itr->second->SendNodeMessage(args.GetContext(), args.GetSize())) {
			OASSERT(false, "send failed");
			return;
		}
	}
}
示例#10
0
void Gate::OnUpdateRole(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs & args) {
	s64 actorId = args.GetDataInt64(0);
	if (_actors.find(actorId) != _actors.end()) {
		OASSERT(_players.find(_actors[actorId]) != _players.end(), "wtf");
		Player& player = _players[_actors[actorId]];
		OASSERT(player.state == ST_ONLINE && actorId == player.selectActorId && nodeId == player.logic, "wtf");

		auto itr = std::find_if(player.roles.begin(), player.roles.end(), [actorId](const Role& role) {
			return role.actorId == actorId;
		});

		OASSERT(itr != player.roles.end(), "wtf");
		if (itr != player.roles.end())
			itr->role->Update(args);
	}
}
void CapacitySubscriber::ReadLoad(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs& args) {
	s32 overlaod = args.GetDataInt32(0);

	s_servers[nodeType][nodeId] = overlaod;
}
示例#12
0
void Analysis::TestDelayRespone(IKernel * kernel, s32 nodeType, s32 nodeId, const OArgs& args) {
	DBG_INFO("%d-%d:%lld=>%lld,%d", nodeType, nodeId, args.GetDataInt64(0), tools::GetTimeMillisecond() - args.GetDataInt64(0), _capacitySubscriber->GetOverLoad(nodeType, nodeId));
}
示例#13
0
bool Redis::Exec(const s64 id, const char* command, const OArgs& args, const std::function<bool(IKernel *, const IRedisResult *)>& f) {
	if (s_contexts.empty())
		return false;

	Ping(s_kernel, id);

	CommandBuff buf;
	buf.size = 0;

	SafeSprintf(buf.data + buf.size, sizeof(buf.data) - buf.size, "*%d\r\n$%d\r\n%s\r\n", args.Count() + 1, strlen(command), command);
	buf.size += (s32)strlen(buf.data + buf.size);

	Append(buf, args);

	s_contexts[id % s_contexts.size()].ctx->obuf = buf.data;
	redisReply * reply = NULL;
	redisGetReply(s_contexts[id % s_contexts.size()].ctx, (void**)&reply);
	if (NULL == reply) {
		return false;
	}

	if (REDIS_REPLY_ERROR == reply->type || REDIS_REPLY_NIL == reply->type) {
		freeReplyObject(reply);
		return false;
	}

	bool ret = true;
	if (f) {
		RedisCallResult rst(reply);
		ret = f(s_kernel, &rst);
	}

	freeReplyObject(reply);
	return ret;

}
示例#14
0
bool Redis::Call(const s64 id, const char* proc, const s32 keyCount, const OArgs& args, const std::function<bool(IKernel *, const IRedisResult *)>& f) {
	if (s_contexts.empty())
		return false;

	Ping(s_kernel, id);

	if (!LoadScript(s_kernel, id, proc))
		return false;

	CommandBuff buf;
	buf.size = 0;

	const char * scriptId = s_contexts[id % s_contexts.size()].scriptIds[proc].GetString();
	s32 len = (s32)strlen(scriptId);
	SafeSprintf(buf.data + buf.size, sizeof(buf.data) - buf.size, "*%d\r\n$7\r\nEVALSHA\r\n$%d\r\n%s\r\n", args.Count() + 2, len, scriptId);
	buf.size += (s32)strlen(buf.data + buf.size);

	Append(buf, args);

	s_contexts[id % s_contexts.size()].ctx->obuf = buf.data;
	redisReply * reply = NULL;
	redisGetReply(s_contexts[id % s_contexts.size()].ctx, (void**)&reply);
	if (NULL == reply) {
		return false;
	}

	if (REDIS_REPLY_ERROR == reply->type || REDIS_REPLY_NIL == reply->type) {
		freeReplyObject(reply);
		return false;
	}

	bool ret = true;
	if (f) {
		RedisCallResult rst(reply);
		ret = f(s_kernel, &rst);
	}

	freeReplyObject(reply);
	return ret;
}