示例#1
0
void Fountain::healChampions(Map* map, long long diff) {
   healTickTimer += diff;
   if (healTickTimer > 1000000) {
      healTickTimer = 0;

      int team = 0;
      for (auto f : healLocations){
            
         for ( Champion* c : map->getChampionsInRange(f, fountainSize)) {
            if (c->getTeam() == team) {
               float HP = c->getStats().getCurrentHealth(), MaxHP = c->getStats().getMaxHealth();
               if (HP + MaxHP * PERCENT_MAX_HEALTH_HEAL < MaxHP) {
                  c->getStats().setCurrentHealth(HP + MaxHP * PERCENT_MAX_HEALTH_HEAL);
               }
               else if (HP < MaxHP) {
                  c->getStats().setCurrentHealth(MaxHP);
                  CORE_INFO("Fully healed at fountain");
               }
			   
			   float Mana = c->getStats().getCurrentMana(), MaxMana = c->getStats().getMaxMana();
               if (Mana + MaxMana * PERCENT_MAX_MANA_HEAL < MaxMana) {
                  c->getStats().setCurrentMana(Mana + MaxMana * PERCENT_MAX_MANA_HEAL);
               }
               else if (Mana < MaxMana) {
                  c->getStats().setCurrentMana(MaxMana);
                  CORE_INFO("Fully healed mana at fountain");
               }
            }
         }
         
      team++;
      }

   }
}
示例#2
0
文件: Buff.cpp 项目: 0ldm0s/IntWars
Buff::Buff(std::string buffName, float dur, BuffType type, Unit* u, Unit* uu)  : duration(dur),  name(buffName), timeElapsed(0), remove(false), attachedTo(u) , attacker(uu), buffType(type), movementSpeedPercentModifier(0.0f)  {
   //init();
   if(name != ""){ // empty name = no buff icon
   std::string scriptloc = "../../lua/buffs/" + name + ".lua";
	CORE_INFO("Loading %s", scriptloc.c_str());
   try{
   
    buffScript = new LuaScript(true);//fix
    
    buffScript->loadScript(scriptloc);
    buffScript->setLoaded(true);
    
    CORE_INFO("Loaded buff lua script");
    buffScript->lua.set_function("getAttachedUnit", [this]() { 
      return attachedTo;
   });
   
   buffScript->lua.set_function("dealMagicDamage", [this](Unit* target, float amount) { attacker->dealDamageTo(target,amount,DAMAGE_TYPE_MAGICAL,DAMAGE_SOURCE_SPELL); });

    CORE_INFO("added lua buff script functions");
   }catch(sol::error e){//lua error? don't crash the whole server
      buffScript->setLoaded(false);
      CORE_ERROR("Lua buff load error: %s", e.what());
   }
   
   
      attachedTo->getMap()->getGame()->notifyAddBuff(attachedTo, attacker, name);
   }
}
示例#3
0
int32_t CCoreTCPListener::handle_input(BASE_HANDLER handle)
{
	while(true) //EPOLL ET模式是需要将事件全部处理干净,直到状态EAGAIN
	{
		Inet_Addr remote_addr;
		CConnection *conn = CONNECTION_POOL.pop_obj();
		conn->reset();

		if(acceptor_.accept(conn->get_sock_stream(), remote_addr, true) == 0)
		{
			CORE_INFO("accept tcp connection, remote addr = " << remote_addr);
			conn->set_remote_addr(remote_addr);

			if(REACTOR_INSTANCE()->register_handler(conn, MASK_WRITE | MASK_READ) == 0)
			{	
				conn->set_state(CConnection::CONN_CONNECTING);

				CORE_INFO("pop conn = " << conn);
			}
			else 
			{
				conn->reset();
				CONNECTION_POOL.push_obj(conn);
			}
#ifdef WIN32
			return 0;
#endif
		}
		else
		{
			conn->reset();
			CONNECTION_POOL.push_obj(conn);
#ifndef WIN32
			if (errno != EAGAIN && errno != ECONNABORTED && errno != EPROTO && errno != EINTR)
			{
				CORE_DEBUG("push conn = " << this);
				CORE_FATAL("tcp listener accept failed!");
				return -2;
			}
			else 
			{
				return 0;
			}
#else 
			return -2;
#endif
		}
	}

	return 0;
}
void Connection_Manager::add_server(uint32_t server_id, uint8_t server_type, uint16_t net_type,
									const Inet_Addr& tel_addr, const Inet_Addr& cnc_addr)
{
	CORE_INFO("add server, sid = " << server_id << ", server_type = " << GetServerName(server_type));

	Server_Node_Map::iterator it = nodes_.find(server_id);
	if(it == nodes_.end())
	{
		Server_Node_t node;
		node.server_id = server_id;
		node.server_type = server_type;
		node.tel_addr = tel_addr;
		node.net_type = net_type;
		node.cnc_addr = cnc_addr;
		node.daemon_del_ = false;
		
		nodes_[server_id] = node;
	}
	else
	{
		it->second.server_id = server_id;
		it->second.server_type = server_type;
		it->second.net_type = net_type;
		it->second.tel_addr = tel_addr;
		it->second.cnc_addr = cnc_addr;
		it->second.daemon_del_ = false;
	}
}
示例#5
0
int32_t DCTCPListener::handle_input(BASE_HANDLER handle)
{
	while(true)
	{
		Inet_Addr remote_addr;
		ShortConnection *conn = SHORTCONN_POOL.pop_obj();
		conn->reset();

		if(acceptor_.accept(conn->get_sock_stream(), remote_addr, true) == 0)
		{
			CORE_INFO("accept tcp short connection, remote addr = " << remote_addr);
			conn->set_remote_addr(remote_addr);
			conn->set_proc(proc_); //管理消息处理句柄

			REACTOR_INSTANCE()->register_handler(conn, MASK_WRITE);	
			REACTOR_INSTANCE()->register_handler(conn, MASK_READ);

			conn->set_state(ShortConnection::SHORT_CONN_CONNECTING);

			CORE_INFO("pop short conn = " << conn);

#ifdef WIN32
			return 0;
#endif
		}
		else
		{
			SHORTCONN_POOL.push_obj(conn);
#ifndef WIN32
			if (errno != EAGAIN && errno != ECONNABORTED && errno != EPROTO && errno != EINTR)
			{
				CORE_DEBUG("push short conn = " << this);
				CORE_FATAL("short tcp listener accept failed!");
				return -2;
			}
			else 
			{
				return 0;
			}
#else 
			return -2;
#endif
		}
	}

	return 0;
}
示例#6
0
文件: main.cpp 项目: noxx2/IntWars
int main(int argc, char ** argv) 
{
	printf("Yorick %s\n", SERVER_VERSION);

	Logger::instance().setLogFile("../../log.html", false, true);
	CORE_INFO("Loading RAF files in filearchives/.");
   
   std::string basePath = RAFManager::getInstance()->findGameBasePath();

   if(!RAFManager::getInstance()->init(basePath + "filearchives")) {
      CORE_ERROR("Couldn't load RAF files. Make sure you have a 'filearchives' directory in the server's root directory. This directory is to be taken from RADS/projects/lol_game_client/");
      return EXIT_FAILURE;
   }
   
   ItemManager::getInstance()->init();
   
   CORE_INFO("Game started");

	Game g;
	ENetAddress address;
	address.host = SERVER_HOST;
   if (argc > 1) {
      enet_uint16 port = atoi(argv[1]);
      address.port = port;
   } else {
      address.port = SERVER_PORT_DEFAULT;
   }
   if (argc > 2) {
      if (!g.initialize(&address, argv[2])) {
         CORE_ERROR("Couldn't listen on port %d, or invalid key", &address);
         return EXIT_FAILURE;
      }
   } else {
      if (!g.initialize(&address, SERVER_KEY_DEFAULT)) {
         CORE_ERROR("Couldn't listen on port %d, or invalid key", &address);
         return EXIT_FAILURE;
      }
   }

	g.netLoop();
   
   PathNode::DestroyTable(); // Cleanup
	
   return EXIT_SUCCESS;
}
示例#7
0
int32_t CoreUDPHandler::close()
{
    CORE_INFO("close core udp");

    REACTOR_INSTANCE()->delete_handler(this);
    sock_dgram_.close();

    return 0;
}
void Connection_Manager::connecting_by_id(const string& data, uint32_t sid)
{
	Server_Node_Map::iterator it = nodes_.find(sid);
	if(it != nodes_.end())
	{
		CConnection* conn = NULL;
		if(it->second.conn == NULL) //建立一条新的TCP服务器连接 
		{
			conn = CONNECTION_POOL.pop_obj();

			conn->set_index(0);
			conn->set_server_type(it->second.server_type);
			conn->set_server_id(it->second.server_id);			
			
			//选取连接地址,目标地址为电信用电信网卡进行连接,依次类推
			Inet_Addr src_addr, dst_addr;
			get_address_pair(it->second, src_addr, dst_addr);

			src_addr.set_port(0);
			//随机一个端口作为客户机端口
			if(src_addr.get_ip() != INADDR_ANY)
			{
				src_addr.set_port(15000 + rand() % 15000);
			}

			CORE_INFO("connecting " << dst_addr << ", by local addr = " << src_addr << ", dst sid = " << sid);

			if(conn->connect(src_addr, dst_addr) != 0)
			{
				conn->close();
				CONNECTION_POOL.push_obj(conn);
				CORE_DEBUG("push conn = " << this);
				CORE_ERROR("connect " << dst_addr << "failed!!");
				return ;
			}

			it->second.conn = conn;
		}
		else
		{
			conn = it->second.conn;
		}

		if(conn->get_state() != CConnection::CONN_CONNECTED) //处于连接状态,缓冲到LIST中
			it->second.strms.push_back(data);
		else
			conn->send(data);
	}
	else
	{
		CORE_ERROR("sid = " << sid << " error!!");
	}
}
示例#9
0
int32_t CCoreTCPListener::open(const Inet_Addr& local_addr)
{
	if(acceptor_.open(local_addr, true) == 0)
	{
		REACTOR_INSTANCE()->register_handler(this, MASK_READ);

		CORE_INFO("open tcp listener, listener addr = " << local_addr);
		return 0;
	}
	else
	{
		CORE_ERROR("open tcp listener failed, listener addr = " << local_addr << ",error = " << error_no());
		return -1;
	}
}
示例#10
0
void CoreUDPHandler::attach(IReciver* reciver)
{
    if(reciver != NULL)
    {
        for(size_t i = 0; i < recivers_.size(); ++i)
        {
            if(recivers_[i] == reciver)
            {
                return ;
            }
        }

        CORE_INFO("core udp handler, attach reciver = 0x" << bin2asc((uint8_t *)reciver, sizeof(reciver)));
        recivers_.push_back(reciver);
    }
}
bool Connection_Manager::on_add_connection(CConnection* conn)
{
	CORE_INFO("on add connection, sid = " << conn->get_server_id() << ", server type = " << GetServerName(conn->get_server_type()));
	if(conn->get_server_id() == 0)
	{
		return false;
	}

	if(conn->get_server_type() >= eDaemon_Server)
	{
		Server_Node_Map::iterator it = nodes_.find(conn->get_server_id());
		if(it != nodes_.end())
		{
			it->second.conn = conn;
			it->second.index = conn->get_index();
		
			for(StreamList::iterator list_it = it->second.strms.begin(); list_it != it->second.strms.end(); ++list_it)
			{
				if(!list_it->empty())
					conn->send(*list_it);
			}

			it->second.strms.clear();
		}
		else
		{
			Server_Node_t node;
			node.server_id = conn->get_server_id();
			node.server_type = conn->get_server_type();
			node.daemon_del_ = true;

			nodes_[conn->get_server_id()] = node;
			nodes_[conn->get_server_id()].index = conn->get_index();
			nodes_[conn->get_server_id()].conn = conn;
		}

		CORE_WARNING("on add connection, sid = " << conn->get_server_id() << ", stype = " << GetServerName(conn->get_server_type()));
		return true;
	}

	return false;
}
示例#12
0
int32_t CoreUDPHandler::open(const Inet_Addr& local_addr)
{
    CORE_INFO("open core udp socket, bind local addr = " << local_addr);

    int32_t ret = sock_dgram_.open(local_addr, true);
    if(ret == 0)
    {
        //设置缓冲区大小
        int32_t buf_size = 1024 * 1024; //1M
        sock_dgram_.set_option(SOL_SOCKET, SO_RCVBUF, (void *)&buf_size, sizeof(int32_t));
        sock_dgram_.set_option(SOL_SOCKET, SO_SNDBUF, (void *)&buf_size, sizeof(int32_t));

        CORE_DEBUG("CoreUDPHandler, register MASK_READ");
        return REACTOR_INSTANCE()->register_handler(this, MASK_READ);
    }
    else
    {
        CORE_FATAL("open UDP failed");
        return -1;
    }
}
void Connection_Manager::del_server(uint32_t server_id, uint8_t server_type)
{
	CORE_INFO("delete server, sid = " << server_id << ", server_type = " << GetServerName(server_type));
	Server_Node_Map::iterator it = nodes_.find(server_id);
	if(it != nodes_.end()) //只删除连接断开的
	{
		if(it->second.conn == NULL)
		{
			//可以做个上层接口,通知节点真正的死去
			if(notify_ != NULL)
			{
				notify_->on_server_dead(it->second.server_id, it->second.server_type);
			}

			nodes_.erase(it);
		}
		else
		{
			it->second.daemon_del_ = true;
		}
	}
}
示例#14
0
void
printHelp (int, char** argv)
{
  CORE_INFO ("Syntax is: %s gamma (learning parameter) categories (directory list of covariances)\n", argv[0]);
}