Example #1
0
bool GMEventManager::AddNewGMEvent (Client* client, csString eventName, csString eventDescription)
{
    int newEventID, zero=0;
    PID gmID = client->GetPID();
    int clientnum = client->GetClientNum();
    GMEvent* gmEvent;

    // if this GM already has an active event, he/she cant start another
    if ((gmEvent = GetGMEventByGM(gmID, RUNNING, zero)) != NULL)
    {
        psserver->SendSystemInfo(clientnum,
                                 "You are already running the \'%s\' event.",
                                 gmEvent->eventName.GetDataSafe());
        return false;
    }

    if (eventName.Length() > MAX_EVENT_NAME_LENGTH)
    {
        eventName.Truncate(MAX_EVENT_NAME_LENGTH);
        psserver->SendSystemInfo(client->GetClientNum(),
                                 "Event name truncated to \'%s\'.",
                                 eventName.GetDataSafe());
    }


    // GM can register his/her event
    newEventID = GetNextEventID();

    // remove undesirable characters from the name & description
    csString escEventName, escEventDescription;
    db->Escape(escEventName, eventName.GetDataSafe());
    db->Escape(escEventDescription, eventDescription.GetDataSafe());

    // first in the database
    db->Command("INSERT INTO gm_events(id, gm_id, name, description, status) VALUES (%i, %i, '%s', '%s', %i)",
        newEventID,
        gmID.Unbox(),
        escEventName.GetDataSafe(),
        escEventDescription.GetDataSafe(),
        RUNNING);

    // and in the local cache.
    gmEvent = new GMEvent;
    gmEvent->id = newEventID;
    gmEvent->gmID = gmID;
    gmEvent->EndTime = 0;
    gmEvent->eventName = eventName;
    gmEvent->eventDescription = eventDescription;
    gmEvent->status = RUNNING;
    gmEvents.Push(gmEvent);

    // keep psCharacter upto date
    client->GetActor()->GetCharacterData()->AssignGMEvent(gmEvent->id,true);

    psserver->SendSystemInfo(client->GetClientNum(),
                             "You have initiated a new event, \'%s\'.",
                             eventName.GetDataSafe());

    return true;
}
unsigned int psEffectManager::RenderEffect(const csString & effectName, iSector * sector, const csVector3 & pos, 
                                           iMeshWrapper * attachTarget, const csVector3 & up, 
                                           const unsigned int uniqueIDOverride, const float* scale)
{
#ifndef DONT_DO_EFFECTS
    // check if it's a single effect
    psEffect * currEffect = FindEffect(effectName);
    if (currEffect != 0)
    {
        currEffect = currEffect->Clone();
        if (scale != NULL)
        {
            if (!currEffect->SetFrameParamScalings(scale))
            {
                Error2("Received scale factor for effect %s that don't use param scaling",effectName.GetDataSafe());
            }
        }
    
        unsigned int uniqueID = currEffect->Render(sector, pos, 0, attachTarget, up.Unit(), uniqueIDOverride);
        actualEffects.Put(uniqueID, currEffect);
        return uniqueID;
    }
    Error2("Failed to find effect with name: %s",effectName.GetDataSafe());
#endif
    return 0;
}
Example #3
0
bool LoadPrerequisiteXML(csRef<psQuestPrereqOp>& prerequisite, psQuest * self, csString script)
{
    csRef<iDocumentSystem> xml = csPtr<iDocumentSystem>(new csTinyDocumentSystem);
    csRef<iDocument> doc = xml->CreateDocument();
    const char* error = doc->Parse( script );
    if ( error )
    {
        Error3("%s\n%s",error, script.GetDataSafe() );
        return false;
    }

    csRef<iDocumentNode> root    = doc->GetRoot();
    if(!root)
    {
        Error1("No XML root in prerequisite script");
        return false;
    }
    csRef<iDocumentNode> topNode = root->GetNode("pre");
    if (topNode)
    {
        return LoadPrerequisiteXML(topNode,self,prerequisite);
    }
    else
    {
        Error3("Could not find <pre> tag in prerequisite script '%s' for quest '%s'!",
               script.GetData(),(self?self->GetName():"(null)"));
        return false;
    }

    return true;
}
Example #4
0
csString Tribe::GetBuffer(const csString &bufferName)
{
    csString value = tribeBuffer.Get(bufferName,"");

    RDebug(this, 5, "Get Buffer(%s) return: '%s'",bufferName.GetDataSafe(),value.GetDataSafe());

    return value;
}
Example #5
0
  void Profiler::WriteLogEntry (const csString& entry, bool flush /* = false */)
  {
    if (logfile)
    {
      logfile->Write (entry.GetDataSafe (), entry.Length ());

      if (flush)
        logfile->Flush ();
    }

    if (nativeLogfile)
    {
      fprintf (nativeLogfile, "%s", entry.GetDataSafe ());

      if (flush)
        fflush (nativeLogfile);
    }
  }
bool LocationManager::RemoveLocationType(iDataConnection* db, const csString &locationName)
{
    int res =db->Command("delete from sc_location_type where name='%s'",
                         locationName.GetDataSafe());
    if(res != 1)
    {
        return false;
    }

    RemoveLocationType(locationName);

    return true;
}
void pawsBuddyWindow::ChangeAlias(const csString & name, const csString &oldAlias, const csString & newAlias)
{
    // Check for duplicates
    if (!IsUniqueAlias(newAlias))
    {
        psSystemMessage err(0, MSG_ERROR,
                            "%s '%s' %s",
                            PawsManager::GetSingleton().Translate("Buddy with the name").GetData(), newAlias.GetDataSafe(),
                            PawsManager::GetSingleton().Translate("already exists.").GetData());
        err.FireEvent();
        return;
    }

    bool found = false;

    // Find the old alias in both lists and replace with the new alias.
    size_t loc = offlineBuddies.Find(oldAlias);
    if (loc != csArrayItemNotFound)
    {
        found = true;
        offlineBuddies.DeleteIndex(loc);
        offlineBuddies.Push(newAlias);
    }
    loc = onlineBuddies.Find(oldAlias);
    if (loc != csArrayItemNotFound)
    {
        found = true;
        onlineBuddies.DeleteIndex(loc);
        onlineBuddies.Push(newAlias);
    }

    if (!found)
    {
        // Old alias not found, perhaps the buddy was removed from the list
        psSystemMessage err(0, MSG_ERROR,
                            "%s '%s' %s",
                            PawsManager::GetSingleton().Translate("Buddy with the name").GetData(),
                            name.GetDataSafe(), 
                            PawsManager::GetSingleton().Translate("cannot be found. Perhaps it was removed.").GetData());
        err.FireEvent();

        return;
    }

    // Add/replace in the aliases table and save it.
    aliases.PutUnique(name, newAlias);
    SaveAliases(psengine->GetMainPlayerName());

    // Update the listbox
    FillBuddyList();
}
Example #8
0
void Tribe::SaveKnowledge(csString knowHow)
{
    const char* fields[] =
    { "tribe_id", "knowledge" };
    psStringArray values;
    values.FormatPush("%d", GetID());
    values.FormatPush("%s", knowHow.GetDataSafe());

    int result = db->GenericInsertWithID("sc_tribe_knowledge",fields,values);
    if(result == 0)
    {
        CPrintf(CON_ERROR, "Failed to save knowledge for tribe. Reason: %s.\n",
                db->GetLastError());
        return;
    }
}
Example #9
0
csRef<iDocument> ParseString(const csString & str, bool notify)
{
    csRef<iDocumentSystem> xml;
    xml.AttachNew(new csTinyDocumentSystem);
    CS_ASSERT(xml != NULL);
    csRef<iDocument> doc  = xml->CreateDocument();
    const char* error = doc->Parse(str);
    if (error)
    {
        if (notify)
        {
            Error3("Error in XML: %s\nString was: %s", error, str.GetDataSafe());
        }
        return NULL;
    }
    return doc;
}
Example #10
0
unsigned int psEffectManager::RenderEffect(const csString & effectName, const csVector3 & offset, 
                                           iMeshWrapper * attachPos, iMeshWrapper * attachTarget, const csVector3 & up, 
                                           const unsigned int uniqueIDOverride, bool rotateWithMesh, const float* scale)
{
#ifndef DONT_DO_EFFECTS
    if (!attachPos)
        return 0;
    
    // check if it's a single effect
    psEffect * currEffect = FindEffect(effectName);
    if (currEffect != 0)
    {
        currEffect = currEffect->Clone();
        if (scale != NULL)
        {
            if (!currEffect->SetFrameParamScalings(scale))
            {
                Error2("Received scale factor for effect %s that don't use param scaling",effectName.GetDataSafe());
            }
        }

        const unsigned int uniqueID = currEffect->Render(attachPos->GetMovable()->GetSectors(), offset, attachPos, 
                                                         attachTarget, up.Unit(), uniqueIDOverride, rotateWithMesh);
        
        actualEffects.Put(uniqueID, currEffect);
        return uniqueID;
    }
#endif
    return 0;
}
Example #11
0
bool GMEventManager::AssumeControlOfGMEvent(Client* client, csString eventName)
{
    int zero=0;
    PID newGMID = client->GetPID();
    int clientnum = client->GetClientNum();
    GMEvent* gmEvent;

    // if this GM already has an active event, he/she cant control another
    if ((gmEvent = GetGMEventByGM(newGMID, RUNNING, zero)))
    {
        psserver->SendSystemInfo(clientnum,
                                 "You are already running the \'%s\' event.",
                                 gmEvent->eventName.GetDataSafe());
        return false;
    }

    // find the requested event
    zero = 0;
    if (!(gmEvent = GetGMEventByName(eventName, RUNNING, zero)))
    {
        psserver->SendSystemInfo(clientnum,
                                 "The \'%s\' event is not recognised or not running.",
                                 eventName.GetDataSafe());
        return false;
    }

    // look for the current GM if there is one
    ClientConnectionSet* clientConnections = psserver->GetConnections();
    Client* target;
    if (gmEvent->gmID != UNDEFINED_GMID)
    {
        if ((target = clientConnections->FindPlayer(gmEvent->gmID)))
        {
            psserver->SendSystemInfo(clientnum,
                                     "The \'%s\' event's GM, %s, is online: you cannot assume control.",
                                     gmEvent->eventName.GetDataSafe(),
                                     target->GetName());
            return false;
        }
    }

    // if the GM is a participant, then remove the reference
    RemovePlayerRefFromGMEvent(gmEvent, client, newGMID);

    // OK, assume control
    gmEvent->gmID = newGMID;
    db->Command("UPDATE gm_events SET gm_id = %d WHERE id = %d", newGMID.Unbox(), gmEvent->id);
    client->GetActor()->GetCharacterData()->AssignGMEvent(gmEvent->id,true);
    psserver->SendSystemInfo(clientnum,
                             "You now control the \'%s\' event.",
                             gmEvent->eventName.GetDataSafe());

    csArray<PlayerData>::Iterator iter = gmEvent->Player.GetIterator();
    while (iter.HasNext())
    {
        if ((target = clientConnections->FindPlayer(iter.Next().PlayerID)))
        {
            psserver->SendSystemInfo(target->GetClientNum(),
                                     "The GM %s is now controlling the \'%s\' event.",
                                     client->GetName(),
                                     gmEvent->eventName.GetDataSafe());
        }
    }

    return true;
}
Example #12
0
bool GMEventManager::RewardPlayersInGMEvent (Client* client,
                                             RangeSpecifier rewardRecipient,
                                             float range,
                                             Client* target,
                                             short stackCount,
                                             csString itemName)
{
    GMEvent* gmEvent;
    int clientnum = client->GetClientNum(), zero = 0;
    WordArray rewardDesc(itemName);
    RewardType rewardType = REWARD_ITEM;
    PID gmID = client->GetPID();

    // make sure GM is running (or assisting) an event
    if ((gmEvent = GetGMEventByGM(gmID, RUNNING, zero)) == NULL)
    {
        zero = 0;
        if ((gmEvent = GetGMEventByPlayer(gmID, RUNNING, zero)) == NULL)
        {
            psserver->SendSystemInfo(clientnum, "You are not running/assisting an event.");
            return false;
        }
    }
    // check range is within max permissable
    if (rewardRecipient == IN_RANGE && (range <= 0.0 || range > MAX_REGISTER_RANGE))
    {
       psserver->SendSystemInfo(clientnum,
                                "Range should be greater than 0m upto %.2fm to reward participants.",
                                MAX_REGISTER_RANGE);
       return false;
    }

    // identify reward type: experience, faction points or an item
    if (rewardDesc[0] == "exp" && rewardDesc.GetCount() == 1)
        rewardType = REWARD_EXPERIENCE;
    else if (rewardDesc[0] == "faction" && rewardDesc.GetCount() > 1)
        rewardType = REWARD_FACTION_POINTS;

    // retrieve base stats item
    psItemStats *basestats;
    if (rewardType == REWARD_ITEM)
    {
        basestats = CacheManager::GetSingleton().GetBasicItemStatsByName(itemName.GetDataSafe());
        if (basestats == NULL)
        {
            psserver->SendSystemInfo(clientnum, "Reward \'%s\' not recognised.", itemName.GetDataSafe());
            Error2("'%s' was not found as a valid base item.", itemName.GetDataSafe());
            return false;
        }

        if (stackCount <= 0)
        {
           psserver->SendSystemInfo(clientnum,
                                "You must reward at least 1 item to participant(s).");
           return false;
        }
        
        if (stackCount >= 65 && !basestats->IsMoney())
        {
           psserver->SendSystemInfo(clientnum,
                                "You can't reward that amount of items to partecipant(s).");
           return false;
        }

        // cant reward personalised or unique items
        if (basestats->GetBuyPersonalise() || basestats->GetUnique())
        {
           psserver->SendSystemInfo(clientnum,
                                "You cannot reward personalised / unique items.");
           return false;
        }
    }
    else
        basestats = NULL;


    if (rewardRecipient == INDIVIDUAL)
    {
        if (!target)
            psserver->SendSystemInfo(clientnum, "Invalid target for reward.");
        else
        {
            zero = 0;
            GMEvent* playersEvent = GetGMEventByPlayer(target->GetPID(), RUNNING, zero);
            if (playersEvent && playersEvent->id == gmEvent->id)
            {
                if (rewardType == REWARD_EXPERIENCE)
                    psserver->GetAdminManager()->AwardExperienceToTarget(clientnum, target, target->GetName(), stackCount);
                else if (rewardType == REWARD_FACTION_POINTS)
                    psserver->GetAdminManager()->AdjustFactionStandingOfTarget(clientnum, target, rewardDesc.GetTail(1), stackCount);
                else
                    RewardPlayer(clientnum, target, stackCount, basestats);
            }
            else
            {
                psserver->SendSystemInfo(clientnum,
                                         "%s is not registered in your \'%s\' event.",
                                         target->GetName(),
                                         gmEvent->eventName.GetDataSafe());
            }
        }
    }
    else
    {
        // reward ALL players (incl. within range)
        ClientConnectionSet* clientConnections = psserver->GetConnections();
        gemActor* clientActor = client->GetActor();
        for (size_t p = 0; p < gmEvent->Player.GetSize(); p++)
        {
            if ((target = clientConnections->FindPlayer(gmEvent->Player[p].PlayerID)))
            {
                if (rewardRecipient == ALL || clientActor->RangeTo(target->GetActor()) <= range)
                {
                    if (rewardType == REWARD_EXPERIENCE)
                        psserver->GetAdminManager()->AwardExperienceToTarget(clientnum, target, target->GetName(), stackCount);
                    else if (rewardType == REWARD_FACTION_POINTS)
                        psserver->GetAdminManager()->AdjustFactionStandingOfTarget(clientnum, target, rewardDesc.GetTail(1), stackCount);
                    else
                        RewardPlayer(clientnum, target, stackCount, basestats);
                }
            }
        }
    }

    return true;
}
Example #13
0
void SpellManager::Cast(gemActor* caster, const csString &spellName, float kFactor, Client* client)
{
    psSpell* spell = NULL;

    if( spellName=="" )
    {
        //this is a request to send the current active magic list
        caster->SendActiveSpells();
        return;
    }

    // Allow developers to cast any spell
    bool canCastAllSpells;
    if(client)
    {
        canCastAllSpells = cacheManager->GetCommandManager()->Validate(client->GetSecurityLevel(), "cast all spells");
    }
    else
    {
        canCastAllSpells = true; // For now grant the NPC client the same priveledge as game masters and developers.
    }

    // Allow developers to cast any spell, even if unknown to the character.
    if(canCastAllSpells)
    {
        spell = cacheManager->GetSpellByName(spellName);
    }
    else
    {
        spell = client->GetCharacterData()->GetSpellByName(spellName);
    }

    //spells with empty glyphlists are not enabled
    if(!spell || spell->GetGlyphList().IsEmpty())
    {
        if(client)
        {
            psserver->SendSystemInfo(client->GetClientNum(), "You don't know a spell called %s.",spellName.GetData());
        }
        else
        {
            Debug3(LOG_SUPERCLIENT,caster->GetEID().Unbox(),"%s don't know a spell called %s.",caster->GetName(),spellName.GetDataSafe());
        }
        return;
    }

    // Clamp kFactor to sane values.
    if(kFactor < 0.0)
    {
        kFactor = 0.0;
    }
    if(kFactor > 100.0)
    {
        kFactor = 100.0;
    }

    csString reason;
    if(!spell->CanCast(caster, kFactor, reason, canCastAllSpells))
    {
        if(client)
        {
            psserver->SendSystemInfo(client->GetClientNum(), reason.GetData());
        }
        else
        {
            Debug3(LOG_SUPERCLIENT,caster->GetEID().Unbox(),"%s: %s.",caster->GetName(),reason.GetDataSafe());
        }

        return;
    }

    spell->Cast(caster, kFactor, client);
}
Example #14
0
void Tribe::RemoteDebugReport(uint32_t clientNum, const csString &debugString)
{
    npcclient->GetNetworkMgr()->QueueSystemInfoCommand(clientNum,"%s (%d)> %s", GetName(), id, debugString.GetDataSafe());
}
Example #15
0
void Tribe::LocalDebugReport(const csString &debugString)
{
    CPrintf(CON_CMDOUTPUT, "%s (%d)> %s\n", GetName(), id, debugString.GetDataSafe());
}
Example #16
0
void Tribe::SetBuffer(const csString &bufferName, const csString &value)
{
    RDebug(this, 5, "Set Buffer(%s,%s)",bufferName.GetDataSafe(),value.GetDataSafe());

    tribeBuffer.PutUnique(bufferName,value);
}