bool Game::initialize(ENetAddress *address, const char *baseKey){ if (enet_initialize () != 0) return false; atexit(enet_deinitialize); _server = enet_host_create(address, 32, 0, 0); if(_server == NULL) return false; std::string key = base64_decode(baseKey); if(key.length() <= 0) return false; _blowfish = new BlowFish((uint8*)key.c_str(), 16); initHandlers(); map = new SummonersRift(this); //TODO: better lua implementation LuaScript script(false); script.loadScript("../../lua/config.lua"); // sol::state lua; // lua.open_libraries(sol::lib::base, sol::lib::table); // lua.open_file("../../lua/config.lua"); sol::table playerList = script.getTable("players"); for (int i=1;i<12;i++) { try { std::string playerIndex = "player"+toString(i); sol::table playerData = playerList.get<sol::table>(playerIndex); std::string rank = playerData.get<std::string>("rank"); std::string name = playerData.get<std::string>("name"); std::string champion = playerData.get<std::string>("champion"); std::string team = playerData.get<std::string>("team"); int skin = playerData.get<int>("skin"); int ribbon = playerData.get<int>("ribbon"); int icon = playerData.get<int>("icon"); std::string summoner1 = playerData.get<std::string>("summoner1"); std::string summoner2 = playerData.get<std::string>("summoner2"); ClientInfo* player = new ClientInfo(rank, ((team == "BLUE") ? TEAM_BLUE : TEAM_PURPLE), ribbon, icon); player->setName(name); player->setSkinNo(skin); static int id = 1; player->userId = id; // same as StartClient.bat id++; player->setSummoners(strToId(summoner1), strToId(summoner2)); Champion* c = ChampionFactory::getChampionFromType(champion, map, GetNewNetID(), player->userId); float respawnX, respawnY; std::tie(respawnX, respawnY) = c->getRespawnPosition(); c->setPosition(respawnX, respawnY); c->setSide((team == "BLUE") ? 0 : 1); c->levelUp(); map->addObject(c); player->setChampion(c); players.push_back(player); } catch(sol::error e) { //printf("Error loading champion: \n%s", e.what()); break; } } // Uncomment the following to get 2-players /*ClientInfo* player2 = new ClientInfo("GOLD", TEAM_PURPLE); player2->setName("tseT"); Champion* c2 = ChampionFactory::getChampionFromType("Ezreal", map, GetNewNetID()); c2->setPosition(100.f, 273.55f); c2->setSide(1); map->addObject(c2); player2->setChampion(c2); player2->setSkinNo(4); player2->userId = 2; // same as StartClient.bat player2->setSummoners(SPL_Ignite, SPL_Flash); players.push_back(player2);*/ return _isAlive = true; }
bool Game::handleChatBoxMessage(HANDLE_ARGS) { ChatMessage *message = reinterpret_cast<ChatMessage *>(packet->data); //Lets do commands if(message->msg == '.') { const char *cmd[] = { ".set", ".gold", ".speed", ".health", ".xp", ".ap", ".ad", ".mana", ".model", ".help", ".spawn", ".size", ".junglespawn", ".skillpoints", ".level", ".tp", ".coords", ".ch"}; std::ostringstream debugMsg; // help command if (strncmp(message->getMessage(), cmd[9], strlen(cmd[9])) == 0) { return true; } // set if(strncmp(message->getMessage(), cmd[0], strlen(cmd[0])) == 0) { uint32 blockNo, fieldNo; float value; sscanf(&message->getMessage()[strlen(cmd[0])+1], "%u %u %f", &blockNo, &fieldNo, &value); blockNo = 1 << (blockNo - 1); uint32 mask = 1 << (fieldNo - 1); peerInfo(peer)->getChampion()->getStats().setStat(blockNo, mask, value); return true; } // gold if(strncmp(message->getMessage(), cmd[1], strlen(cmd[1])) == 0) { float gold = (float)atoi(&message->getMessage()[strlen(cmd[1]) + 1]); peerInfo(peer)->getChampion()->getStats().setGold(gold); return true; } // speed if(strncmp(message->getMessage(), cmd[2], strlen(cmd[2])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[2])+1]); printf("Setting speed to %f\n", data); peerInfo(peer)->getChampion()->getStats().setMovementSpeed(data); return true; } //health if(strncmp(message->getMessage(), cmd[3], strlen(cmd[3])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[3])+1]); peerInfo(peer)->getChampion()->getStats().setCurrentHealth(data); peerInfo(peer)->getChampion()->getStats().setMaxHealth(data); notifySetHealth(peerInfo(peer)->getChampion()); return true; } // xp if(strncmp(message->getMessage(), cmd[4], strlen(cmd[4])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting experience to %f\n", data); peerInfo(peer)->getChampion()->getStats().setExp(data); return true; } // ap if(strncmp(message->getMessage(), cmd[5], strlen(cmd[5])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting AP to %f\n", data); peerInfo(peer)->getChampion()->getStats().setBonusApFlat(data); return true; } // ad if(strncmp(message->getMessage(), cmd[6], strlen(cmd[6])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[5])+1]); printf("Setting AD to %f\n", data); peerInfo(peer)->getChampion()->getStats().setBonusAdFlat(data); return true; } // Mana if(strncmp(message->getMessage(), cmd[7], strlen(cmd[7])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[7])+1]); printf("Setting Mana to %f\n", data); peerInfo(peer)->getChampion()->getStats().setCurrentMana(data); peerInfo(peer)->getChampion()->getStats().setMaxMana(data); return true; } // Model if(strncmp(message->getMessage(), cmd[8], strlen(cmd[8])) == 0) { std::string sModel = (char *)&message->getMessage()[strlen(cmd[8]) + 1]; peerInfo(peer)->getChampion()->setModel(sModel); return true; } // Size if(strncmp(message->getMessage(), cmd[11], strlen(cmd[11])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[11])+1]); printf("Setting size to %f\n", data); peerInfo(peer)->getChampion()->getStats().setSize(data); return true; } // Mob Spawning-Creating, updated if(strncmp(message->getMessage(), cmd[12], strlen(cmd[12])) == 0) { const char *cmd[] = { "c baron" , "c wolves", "c red", "c blue", "c dragon", "c wraiths", "c golems"}; return true; } // Skillpoints if(strncmp(message->getMessage(), cmd[13], strlen(cmd[13])) == 0) { peerInfo(peer)->getChampion()->setSkillPoints(17); SkillUpResponse skillUpResponse(peerInfo(peer)->getChampion()->getNetId(), 0, 0, 17); sendPacket(peer, skillUpResponse, CHL_GAMEPLAY); return true; } // Level if(strncmp(message->getMessage(), cmd[14], strlen(cmd[14])) == 0) { float data = (float)atoi(&message->getMessage()[strlen(cmd[14])+1]); peerInfo(peer)->getChampion()->getStats().setLevel(data); return true; } // tp if(strncmp(message->getMessage(), cmd[15], strlen(cmd[15])) == 0) { float x, y; sscanf(&message->getMessage()[strlen(cmd[15])+1], "%f %f", &x, &y); notifyTeleport(peerInfo(peer)->getChampion(), x, y); return true; } // coords if(strncmp(message->getMessage(), cmd[16], strlen(cmd[16])) == 0) { printf("At %f;%f\n", peerInfo(peer)->getChampion()->getX(), peerInfo(peer)->getChampion()->getY()); debugMsg << "At Coords - X:" << peerInfo(peer)->getChampion()->getX() << " Y:" << peerInfo(peer)->getChampion()->getY() << " Z:" << peerInfo(peer)->getChampion()->getZ(); notifyDebugMessage(debugMsg.str()); return true; } // Ch(ampion) if(strncmp(message->getMessage(), cmd[17], strlen(cmd[17])) == 0) { std::string champ = (char *)&message->getMessage()[strlen(cmd[17]) + 1]; Champion* c = new Champion(champ, map, peerInfo(peer)->getChampion()->getNetId(), peerInfo(peer)->userId); c->setPosition(peerInfo(peer)->getChampion()->getX(), peerInfo(peer)->getChampion()->getY()); c->setModel(champ); // trigger the "modelUpdate" proc map->removeObject(peerInfo(peer)->getChampion()); delete peerInfo(peer)->getChampion(); map->addObject(c); peerInfo(peer)->setChampion(c); return true; } } switch(message->type) { case CMT_ALL: return broadcastPacket(packet->data, packet->dataLength, CHL_COMMUNICATION); case CMT_TEAM: return broadcastPacketTeam(peerInfo(peer)->getTeam(), packet->data, packet->dataLength, CHL_COMMUNICATION); default: //Logging->errorLine("Unknown ChatMessageType\n"); return sendPacket(peer, packet->data, packet->dataLength, CHL_COMMUNICATION); } return false; }