예제 #1
0
void MapCreater::NewArea(STRARR& cmd)
{
	if (cmd.size()>1)
	{
		if(!CheckDirExist(cmd[0]))
			NewMap(STRARR(cmd.begin(), cmd.begin()+1));
			
		string mappath = _working_dir + "/" + cmd[0];
		ConfigFile mapdata(mappath + MAPDATA);
		mapdata.Add(string("area_") + cmd[1], cmd[1]);
		
		string areapath = mappath + "/" + cmd[1];
		CheckFileExist(areapath + AREADATA);
		
		cout<<"Area ["<<cmd[1]<<"] created in ["<<cmd[0]<<"]\n";
	}
	else
		cout<<"newarea (mapname) (areaname)\n";
}
예제 #2
0
void Session::ProcessPacket(SmartPacket* packet, Player* pSource)
{
    switch(packet->GetOpcode())
    {
        case CMSG_INITIATE_SESSION:
        {
            SmartPacket response(SMSG_INITIATE_SESSION_RESPONSE);
            response << uint32(sGlobalStorage->GetLock());
            SendPacket(pSource, &response);
            break;
        }
        case CMSG_VALIDATE_VERSION:
        {
            SmartPacket response(SMSG_VALIDATE_VERSION_RESPONSE);
            response << VERSION_STR;
            response << uint32(1);   // I pres to hratelny - jen doporuci update pri rozdilu verzi
            SendPacket(pSource, &response);

            break;
        }
        case CMSG_REQUEST_INSTANCE_LIST:
        {
            const char* inststr = sInstanceManager->GetInstanceString();
            SmartPacket response(SMSG_INSTANCE_LIST);
            response << inststr;
            SendPacket(pSource, &response);

            break;
        }
        case CMSG_ENTER_GAME:
        {
            uint32 instanceId;
            std::string nickname;

            *packet >> instanceId;
            nickname = packet->readstr();

            if (sSession->GetPlayerByName(nickname.c_str()))
            {
                SmartPacket response(SMSG_ENTER_GAME_RESULT);
                response << uint8(1); //error - nick uz ma nekdo jiny
                SendPacket(pSource, &response);
            }

            pSource->m_nickName = nickname;

            sInstanceManager->RegisterPlayer(pSource, instanceId);
            if (sInstanceManager->GetPlayerInstanceId(pSource) != instanceId)
            {
                SmartPacket response(SMSG_ENTER_GAME_RESULT);
                response << uint8(2); //error - nelze pridat do instance
                SendPacket(pSource, &response);
                return;
            }

            // TODO: nacteni start. pozic ze souboru
            pSource->m_positionX = 1.0f;
            pSource->m_positionY = 1.0f;

            SmartPacket response(SMSG_ENTER_GAME_RESULT);
            response << uint8(0); //vsechno ok
            response << float(pSource->m_positionX); // startovni pozice X
            response << float(pSource->m_positionY); // startovni pozice Y (klientsky Z)
            response << uint32(pSource->m_socket);   // jako ID pouzijeme socket ID
            response << instanceId;
            SendPacket(pSource, &response);

            SmartPacket mapdata(SMSG_MAP_INITIAL_DATA);

            Instance* pInstance = sInstanceManager->GetPlayerInstance(pSource);
            if (pInstance)
            {
                for (int i = 0; i < MAX_PLAYERS_PER_INSTANCE; i++)
                {
                    if (pInstance->pPlayers[i])
                    {
                        mapdata << uint32(pInstance->pPlayers[i]->m_socket);
                        mapdata << pInstance->pPlayers[i]->m_positionX;
                        mapdata << pInstance->pPlayers[i]->m_positionY;
                        mapdata << uint8(pInstance->pPlayers[i]->m_modelIdOffset);
                        mapdata << pInstance->pPlayers[i]->m_nickName.c_str();
                    }
                    else
                    {
                        mapdata << uint32(0);
                        mapdata << float(0);
                        mapdata << float(0);
                        mapdata << uint8(0);
                        mapdata << "UNKNOWN";
                    }
                }

                mapdata << uint32(pInstance->m_dynRecords.size());
                for (std::list<Instance::DynamicRecord>::const_iterator itr = pInstance->m_dynRecords.begin(); itr != pInstance->m_dynRecords.end(); ++itr)
                    mapdata << uint32((*itr).x) << uint32((*itr).y) << uint8((*itr).type);
                SendPacket(pSource, &mapdata);
            }
            SmartPacket inotify(SMSG_NEW_PLAYER);
            inotify << uint32(pSource->m_socket);       // ID
            inotify << pSource->m_positionX;            // pozice X
            inotify << pSource->m_positionY;            // pozice Y
            inotify << uint8(pSource->m_modelIdOffset); // offset modelu, klient si s tim poradi
            inotify << nickname.c_str();                // nick
            sInstanceManager->SendInstancePacket(&inotify, instanceId);
            break;
        }
        case MSG_NONE:
        default:
            sLog->ErrorOut("Received unknown/invalid opcode: %u",packet->GetOpcode());
            break;
    }
}
예제 #3
0
파일: saver.cpp 프로젝트: CJFocke/vsxu
bool CalSaver::saveXmlCoreMaterial(const std::string& strFilename, CalCoreMaterial *pCoreMaterial)
{
  std::stringstream str;

  vsxTiXmlDocument doc(strFilename);

  vsxTiXmlElement material("MATERIAL");
  //material.SetAttribute("MAGIC",Cal::MATERIAL_XMLFILE_MAGIC);
  material.SetAttribute("VERSION",Cal::LIBRARY_VERSION);

  material.SetAttribute("NUMMAPS",pCoreMaterial->getVectorMap().size());
  
  vsxTiXmlElement ambient("AMBIENT");

  CalCoreMaterial::Color ambientColor;
  ambientColor = pCoreMaterial->getAmbientColor();


  str.str("");
  str << (int)ambientColor.red << " " 
	  << (int)ambientColor.green << " "
	  << (int)ambientColor.blue << " "
	  << (int)ambientColor.alpha;
  
  vsxTiXmlText ambientdata(str.str());
  

  ambient.InsertEndChild(ambientdata);
  material.InsertEndChild(ambient);

  vsxTiXmlElement diffuse("DIFFUSE");

  CalCoreMaterial::Color diffuseColor;
  diffuseColor = pCoreMaterial->getDiffuseColor();
  
  str.str("");
  str << (int)diffuseColor.red << " " 
	  << (int)diffuseColor.green << " "
	  << (int)diffuseColor.blue << " "
	  << (int)diffuseColor.alpha;
  
  vsxTiXmlText diffusedata(str.str());

  
  diffuse.InsertEndChild(diffusedata);
  material.InsertEndChild(diffuse);

  vsxTiXmlElement specular("SPECULAR");

  CalCoreMaterial::Color specularColor;
  specularColor = pCoreMaterial->getSpecularColor();

  str.str("");
  str << (int)specularColor.red << " " 
	  << (int)specularColor.green << " "
	  << (int)specularColor.blue << " "
	  << (int)specularColor.alpha;
  
  vsxTiXmlText speculardata(str.str());

  specular.InsertEndChild(speculardata);
  material.InsertEndChild(specular);

  vsxTiXmlElement shininess("SHININESS");

  str.str("");
  str << pCoreMaterial->getShininess();    

  vsxTiXmlText shininessdata(str.str());

  shininess.InsertEndChild(shininessdata);
  material.InsertEndChild(shininess);  

  std::vector<CalCoreMaterial::Map>& vectorMap = pCoreMaterial->getVectorMap();
  
  int mapId;
  for(mapId = 0; mapId < (int)vectorMap.size(); ++mapId)
  {
	  vsxTiXmlElement map("MAP");
	  vsxTiXmlText mapdata(vectorMap[mapId].strFilename);
	  map.InsertEndChild(mapdata);
      material.InsertEndChild(map);
  }

  doc.InsertEndChild(material);

  if(!doc.SaveFile())
  {
	CalError::setLastError(CalError::FILE_WRITING_FAILED, __FILE__, __LINE__, strFilename);
    return false;
  }

  return true;

}