Example #1
0
bool AssetManager::LoadAsset (const csString& normpath, const csString& file, const csString& mount,
    iCollection* collection)
{
  csRef<iString> path;
  if (!normpath.IsEmpty ())
  {
    csRef<scfStringArray> fullPath = ConstructPath ();
    path = FindAsset (fullPath, normpath, file);
    if (!path)
      return Error ("Cannot find asset '%s' in the asset path!\n", normpath.GetData ());
  }

  csString rmount;
  if (mount.IsEmpty ())
  {
    rmount.Format ("/assets/__mnt_%d__/", mntCounter);
    mntCounter++;
  }
  else
  {
    rmount = mount;
  }

  if (path)
  {
    vfs->Mount (rmount, path->GetData ());
    printf ("Mounting '%s' to '%s'\n", path->GetData (), rmount.GetData ());
    fflush (stdout);
  }

  vfs->PushDir (rmount);
  // If the file doesn't exist we don't try to load it. That's not an error
  // as it might be saved later.
  bool exists = vfs->Exists (file);
  vfs->PopDir ();
  if (exists)
  {
    if (!LoadLibrary (rmount, file, collection))
      return false;
  }
  else
  {
    Warn ("Warning! File '%s/%s' does not exist!\n",
	(!path) ? rmount.GetData () : path->GetData (), file.GetData ());
  }

  //if (!path.IsEmpty ())
    //vfs->Unmount (rmount, path);
  return true;
}
Example #2
0
void pawsExchangeWindow::StartExchange( csString& player, bool withPlayer )
{
    csString text;
    if(!player.IsEmpty())
    {
        text.Format("Trading with %s",player.GetData());
    }

    int width;

    Clear();            
    Show();
            
    pawsTextBox* textBox = dynamic_cast <pawsTextBox*> (FindWidget("other_player"));
    if (textBox != NULL)
        textBox->SetText( text );

    if (withPlayer)
        width = 350;
    else
        width = 175;
    SetRelativeFrameSize(GetActualWidth(width), defaultFrame.Height());

    // Autoshow the inventory
    pawsWidget* widget = PawsManager::GetSingleton().FindWidget("SmallInventoryWindow");
    
    if (widget)
    {
        wasSmallInventoryOpen = widget->IsVisible();
        widget->Show();
    }
}        
Example #3
0
  FeederHeightSourceType ParseFormatString (const csString& format)
  {
    if (format.IsEmpty ())
    {
      return HEIGHT_SOURCE_IMAGE;
    }

    static const char* formatStrings[] = 
    {
      "image", 
      "raw8",
      "raw16le",
      "raw16be",
      "raw32le",
      "raw32be",
      "rawfloatle",
      "rawfloatbe"
    };

    for (size_t i = 0; i < sizeof(formatStrings) / sizeof(char*); ++i)
    {
      if (format == formatStrings[i])
      {
        return (FeederHeightSourceType)i;
      }
    }

    return HEIGHT_SOURCE_IMAGE;
  }
bool ZoneHandler::ForceLoadWindowWidget(bool enable, csString loadWindowName)
{
    if(enable)
    {
        //check first if the window name is valid. shouldn't end up here
        if(loadWindowName.IsEmpty())
        {
            return false;
        }
        else //if it's valid we load it and set it as load window for now
        {
            PawsManager::GetSingleton().LoadWidget(loadWindowName.GetData());

            //request the load window to update the new window
            if(loadWindow)
                loadWindow->PublishMOTD();

            return FindLoadWindow(true, loadWindowName.GetData());
        }
    }
    else //restore the pointers to the normal window and removes the specified window from the memory
    {
        //restore the ties to the default load window
        bool result = FindLoadWindow(true);
        //as we have reloaded the load window we can remove the widget we don't need anymore
        if(loadWindowName.Length())
            PawsManager::GetSingleton().RemoveWidget(loadWindowName.GetData(), false);

        return result;
    }

    return true;
}
Example #5
0
File: win32.cpp Project: garinh/cs
static inline bool AddToPathEnv (csString dir, csString& pathEnv)
{
  // check if installdir is in the path.
  bool gotpath = false;

  size_t dlen = dir.Length();
  // csGetInstallDir() might return "" (current dir)
  if (dlen != 0)
  {
    ToLower (dir);
  
    if (!pathEnv.IsEmpty())
    {
      csString mypath (pathEnv);
      ToLower (mypath);

      const char* ppos = strstr (mypath.GetData(), dir);
      while (!gotpath && ppos)
      {
        const char* npos = strchr (ppos, ';');
        size_t len = npos ? npos - ppos : strlen (ppos);

        if ((len == dlen) || (len == dlen+1))
        {
          if (ppos[len] == '\\') len--;
	  if (!strncmp (ppos, dir, len))
	  {
	    // found it
	    gotpath = true;
	  }
        }
        ppos = npos ? strstr (npos+1, dir) : 0;
      }
    }

    if (!gotpath)
    {
      // put CRYSTAL path into PATH environment.
      csString newpath;
      newpath.Append (dir);
      newpath.Append (";");
      newpath.Append (pathEnv);
      pathEnv = newpath;
      return true;
    }
  }
  return false;
}
void AdviceManager::HandleAdviceResponse( Client *advisor, csString sAdvisee, csString message)
{
    if ( !advisor->GetAdvisor() )
    {
        psserver->SendSystemInfo(advisor->GetClientNum(),"You need to be an advisor to use this command.");
        return;
    }

    csString buf;
    // Source Client Name, Target Client Name, Message
    buf.Format("%s, %s, \"%s\"", advisor->GetName(), sAdvisee.GetData() , message.GetData());
    psserver->GetLogCSV()->Write(CSV_ADVICE, buf);

    // Find Advisee Client by name
    if (sAdvisee.Length())
    {
        sAdvisee = NormalizeCharacterName(sAdvisee);
    }
    Client *advisee = psserver->GetConnections()->Find(sAdvisee);
    if (!advisee)
    {
        // Create a new message to report TELL error and send
        // back to original person.
        csString sMsg("No player named ");
        sMsg += sAdvisee;
        sMsg += " is logged on to the system currently.";
        psserver->SendSystemError(advisor->GetClientNum(), sMsg);
        return;
    }

    // Can't allow you to advise yourself
    if ( advisee == advisor )
    {
        psserver->SendSystemError(advisor->GetClientNum(), "You are not allowed to advise yourself. Please wait for another advisor.");
        return;
    }

    // find existing Advicee in the List
    AdviceSession key;
    key.AdviseeClientNum = advisee->GetClientNum();
    AdviceSession *activeSession = AdviseeList.Get(advisee->GetClientNum(), NULL);

    if (!activeSession || (activeSession  && ( !activeSession->requestEvent ) && ( activeSession->GetAdvisor() == NULL ) ) )
    {
        psserver->SendSystemError(advisor->GetClientNum(), "%s has not requested help.", advisee->GetName());
        return;
    }

    if (activeSession  && ( activeSession->AdviseeClientNum != advisee->GetClientNum() ) )
    {
        Debug2( LOG_ANY, advisee->GetClientNum(), "Grabbed wrong advisor session: %d", activeSession->AdviseeClientNum );
    }

    if ( ( activeSession->GetAdvisor() != NULL ) && ( activeSession->AdvisorClientNum != advisor->GetClientNum() ) )
    {
        psserver->SendSystemError(advisor->GetClientNum(), "%s is being advised already, thank you.",  advisee->GetName());
        return;
    }

    if ( message.Length() == 0  && activeSession->status == SESSION_STATUS_UNKNOWN ) // advisor is claiming a session
    {
        // check to make sure advisor has only one claimed session.
        AdviceSession *loopSession;

        csHash< AdviceSession* >::GlobalIterator loop( AdviseeList.GetIterator() );

        while(loop.HasNext())
        {
        	loopSession = loop.Next();
            if (activeSession->status == SESSION_STATUS_CLAIMED && loopSession->GetAdvisor() == advisor )
            {
                psserver->SendSystemInfo(advisor->GetClientNum(), "You cannot have two messengers waiting for you at the same time, please answer %s's request first." , loopSession->adviseeName.GetData() );
                return;
            }
        }

        activeSession->SetAdvisor( advisor );
        psserver->SendSystemInfo(advisee->GetClientNum(), "An advisor is preparing an answer to your question, please be patient.");
        psserver->SendSystemInfo(advisor->GetClientNum(), "You have claimed the session with %s. Please provide an answer." , advisee->GetName() );

        for (size_t i = 0; i < advisors.GetSize(); i++)
        {
            if ( advisors[i].id != activeSession->AdvisorClientNum )
            {
                psserver->SendSystemInfo(advisors[i].id, "%s has proclaimed they know the answer to %s's question.", advisor->GetName(), advisee->GetName() );
            }
        }
        activeSession->status = SESSION_STATUS_CLAIMED;
    }
    else
    {
        if (message.IsEmpty())
        {
            psserver->SendSystemInfo(advisor->GetClientNum(), "Please enter the advice you wish to give.");
            return;
        }

        psChatMessage msgChat(activeSession->AdviseeClientNum, 0, advisor->GetName(), advisee->GetName(), message ,CHAT_ADVISOR,false);

        if ( activeSession->GetAdvisor() == NULL || activeSession->status != SESSION_STATUS_OWNED )
        {
            // Check to make sure the advice is 'good'
            // if ( message.Length() < 20 )
            // {
                // psserver->SendSystemInfo(advisor->GetClientNum(), "Please be more specific when answering questions. Your advice has been ignored.");
                // return;
            // }

            //activeSession->AdvisorClientNum = me->clientnum;
            activeSession->SetAdvisor( advisor );
            advisor->IncrementAdvisorPoints(activeSession->advisorPoints);
            psserver->CharacterLoader.SaveCharacterData( advisor->GetCharacterData(), advisor->GetActor(), true );

            // Send Confirmation to advisor
            psserver->SendSystemInfo( advisor->GetClientNum(), "You are now advising %s.",advisee->GetName());

            // Send Confirmation to all other advisors so they know they lost this one.
            for (size_t i = 0; i < advisors.GetSize(); i++)
            {
                if ( advisors[i].id != activeSession->AdvisorClientNum )
                {
                    psserver->SendSystemInfo( advisors[i].id, "%s has been assigned to %s.",  advisee->GetName(), advisor->GetName() );
                    if ( advisors[i].GM )
                        continue;
                    msgChat.msg->clientnum = advisors[i].id;
                    msgChat.SendMessage();
                }
            }
            activeSession->status = SESSION_STATUS_OWNED;
        }

        if ( activeSession->requestEvent )
            activeSession->requestEvent->valid = false;  // This keeps the cancellation timeout from firing.

        activeSession->answered = true;

        // Send Message to Advisee
        msgChat.msg->clientnum = activeSession->AdviseeClientNum;
        msgChat.SendMessage();

        // Send Message to advisor
        msgChat.msg->clientnum = activeSession->AdvisorClientNum;
        msgChat.SendMessage();

        // Send message to GM chars as well
        for (size_t i = 0; i < advisors.GetSize(); i++)
        {
            if (!advisors[i].GM || advisors[i].id == activeSession->AdvisorClientNum)
                continue;
            msgChat.msg->clientnum = advisors[i].id;
            msgChat.SendMessage();
        }
    }

    // Add timeout for Advisor-Advisee relationship
    // this will allow later questions by the same client to go to a different advisor
    // spreading the wealth and burden amongst all ;)
    if ( activeSession->timeoutEvent )
    {
        activeSession->timeoutEvent->valid = false;
    }
    psAdviceSessionTimeoutGameEvent *ev = new psAdviceSessionTimeoutGameEvent( this, activeSession->answered?ADVICE_SESSION_TIMEOUT:ADVICE_SESSION_TIMEOUT/2, advisee->GetActor(), activeSession );
    activeSession->timeoutEvent = ev;
    psserver->GetEventManager()->Push(ev);

}
Example #7
0
bool mcMapParser::ReadNextToken (csString& str)
{
  char c, next_c;

  str.Clear();
  m_empty_token = false;

  /* Skip commented and empty lines */
  for(;;)
  {
    if( !SkipWhitespace() ) 
    {
      return false;
    }

    if( !GetChar(c) )
    {
      return false;
    }

    if(c == '\n')
    {
      /* An empty line */
      ++m_current_line;
      continue;
    }

    if( PeekChar(next_c) )
    {
      if( c == '/' && next_c == '/')
      {
        if( !SkipToNextLine() )
        {
          return false;
        }
      }
      else
      {
        break;
      }
    }
    else
    {
      break;
    }
  }

  /* Quoted strings are returned directly */
  if (c == '\"')
  {
    for(;;)
    {
      if ( !GetChar(c) )
      {
        /* If we fail now, the token is not complete! */
        return false; 
      }

      if (c == '\"')
      {
        /* The end of the string has been reached */
	m_empty_token = str.IsEmpty();
        return true;
      }

      str << c;
    }
  }

  /* Check for special single character tokens */
  if ( c == '{'  || c == '}' ||
       c == '('  || c == ')' ||
       c == '\'' || c ==':'  )
  {
    str << c;
    return true;
  }

  /* Parse a regular word */
  for(;;)
  {
    str << c;

    if (!PeekChar(next_c))
    {
      break;
    }

    if ( next_c == '{'  || next_c == '}'  ||
         next_c == '('  || next_c == ')'  ||
         next_c == '\'' || next_c ==':'   ||
         next_c == ' '  || next_c == '\t' || 
         next_c == '\r' || next_c == '\n' )
    {
      break;
    }

    if(!GetChar(c))
    {
      break;
    }
  }

  return true;
}
cssVFSFileDlg::cssVFSFileDlg ( wxWindow *parent,
			       wxWindowID id,
			       const wxString &title,
			       const wxPoint &position,
			       const wxSize& size,
			       long style,
			       iVFS* vfs,
			       const csString& startpath,
			       fileDialogType type) : 
wxDialog( parent, id, title, position, size, style), vfs (vfs)
{
  dialogType = type;
  imageList = CreateImageList();

  // Create Sizers
  wxBoxSizer *boxSizerMain = new wxBoxSizer( wxHORIZONTAL );
  wxBoxSizer *boxSizerRight = new wxBoxSizer( wxVERTICAL );
  wxBoxSizer *boxSizerTopRight = new wxBoxSizer( wxHORIZONTAL );
  wxFlexGridSizer *flexSizerBottomRight = new wxFlexGridSizer( 3, 0, 0 );
  flexSizerBottomRight->AddGrowableCol( 1 );
  flexSizerBottomRight->AddGrowableRow( 0 );
  flexSizerBottomRight->AddGrowableRow( 1 );

  // Create widgets
  switch ( dialogType )
  {
  case VFS_OPEN:
    okbutton = new wxButton(this, BUTTON_OPEN, _("&Open"), wxDefaultPosition, wxDefaultSize, 0 );
    break;
  case VFS_SAVE:
    okbutton =  new wxButton( this, BUTTON_OPEN, _("&Save"), wxDefaultPosition, wxDefaultSize, 0 );
    break;
  }
  okbutton->SetDefault();

  dirtree = new wxTreeCtrl( this, DIRECTORY_TREE, wxDefaultPosition, wxSize(160,160), wxTR_HAS_BUTTONS|wxTR_LINES_AT_ROOT|wxSUNKEN_BORDER );
  fileView = new wxListCtrl( this, DIRECTORY_LIST, wxDefaultPosition, wxSize(340,210), wxLC_LIST|wxSUNKEN_BORDER );
  fileView->SetImageList( imageList, wxIMAGE_LIST_SMALL );
  filter = new wxChoice( this, CHOICE_FILTER, wxDefaultPosition, wxSize(230,-1));
  thepath = new wxTextCtrl( this, TEXT_PATH, wxT(""), wxDefaultPosition, wxSize(230,-1), 0 );
  pathtext = new wxStaticText( this, -1,  _("VFS Path:"), wxDefaultPosition, wxDefaultSize, 0 );
  cancelbut	= new wxButton( this, BUTTON_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
  viewTypes = new wxChoice( this, CHOICE_VIEW_MODE, wxDefaultPosition, wxSize(100,-1));


  newFolderButton = new wxBitmapButton( this,
					BUTTON_NEW_FOLDER,
					wxArtProvider::GetBitmap (wxART_NEW_DIR, wxART_CMN_DIALOG),
					wxDefaultPosition,
					wxSize(25,25) );
  newFolderButton->SetToolTip( _("Create Directory") );

  parentFolderButton = new wxBitmapButton( this,
					   BUTTON_PARENT,
					   wxArtProvider::GetBitmap (wxART_GO_DIR_UP, wxART_CMN_DIALOG),
					   wxDefaultPosition,
					   wxSize(25,25) );
  parentFolderButton->SetToolTip( _("Parent Folder") );
  
  wxStaticText *fileFilterText = new wxStaticText( this, -1, _("File filter:"), wxDefaultPosition, wxDefaultSize, 0 );

  // Set Objects into sizers
  boxSizerMain->Add( dirtree, 0, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxLEFT|wxTOP|wxBOTTOM, 5 );
  boxSizerTopRight->Add( parentFolderButton, 0, wxALIGN_CENTER|wxRIGHT, 5 );
  boxSizerTopRight->Add( newFolderButton, 0, wxALIGN_CENTER|wxRIGHT, 5 );
  boxSizerTopRight->Add( viewTypes, 1, wxALIGN_CENTER|wxLEFT|wxGROW , 5 );
  boxSizerRight->Add( boxSizerTopRight, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 0 );
  boxSizerRight->Add( fileView, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxTOP|wxBOTTOM, 5 );
  flexSizerBottomRight->Add( pathtext, 1, wxALIGN_CENTER|wxALL, 5 );
  flexSizerBottomRight->Add( thepath, 1, wxGROW, 5 );
  flexSizerBottomRight->Add( okbutton, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxLEFT, 15 );
  flexSizerBottomRight->Add( fileFilterText, 0, wxALIGN_CENTER|wxALL|wxGROW, 5 );
  flexSizerBottomRight->Add( filter, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL|wxGROW, 0 );
  flexSizerBottomRight->Add( cancelbut, 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxLEFT, 15 );
  boxSizerRight->Add( flexSizerBottomRight, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxLEFT|wxTOP, 5 );
  boxSizerMain->Add( boxSizerRight, 1, wxGROW|wxALIGN_CENTER_HORIZONTAL|wxALL, 5 );

  this->SetAutoLayout( TRUE );
  this->SetSizer( boxSizerMain );
  boxSizerMain->Fit( this );
  boxSizerMain->SetSizeHints( this );

  dirtree->DeleteAllItems();
  wxTreeItemId rootId = dirtree->AddRoot( wxT("VFS") );
  dirtree->SetItemHasChildren( rootId );
  dirtree->SetImageList( imageList );
  dirtree->SetItemImage( rootId, imageIdList[IMAGE_FOLDER_OPEN] );

  FileDlgTreeItemData* data = new FileDlgTreeItemData(wxT("/"));
  dirtree->SetItemData( rootId, data );
  dirtree->SelectItem(rootId);
  dirtree->Expand (rootId);

  if (startpath.IsEmpty () || startpath == "/")
    curdvpath = GetPathByTreeItem(rootId);
  else
    curdvpath = startpath;
  LoadVFSDirView (curdvpath);
  thepath->SetValue (wxString::FromUTF8 (curdvpath.GetData()));
  InitViewTypeList ();

  // Open the tree until the given path
  if (startpath != "/")
  {
    csString path = startpath;
    if (path.StartsWith ('/'))
      path = path.Slice (1);
    while (!path.IsEmpty ())
    {
      size_t index = path.FindFirst ('/');
      if (index == (size_t) -1) break;
      csString dir = path.Slice (0, index);
      path = path.Slice (index + 1);
      OpenTreeItemChild (wxString::FromUTF8 (dir.GetData()));
    }
  }
}