CEVENT(CMDBoard, _ExitPost) { World* world = World::GetPtr(); Editor* ed = ((EditorExitedArgs*)args)->editor; BoardPost* post = (BoardPost*)ed->GetArg(); Player* mobile = (Player*)caller; BoardManager* bmanager = (BoardManager*)world->GetProperty("boards"); Property* prop = NULL; Board* board = NULL; int id = 0; if (!bmanager) { mobile->Message(MSG_ERROR, "Can not access the board system."); return; } prop = mobile->variables.FindProperty("board"); if (!prop) { mobile->Message(MSG_ERROR, "No board set."); return; } id = prop->GetValue().GetInt(); board = bmanager->GetBoardByIndex(id); if (!board) { mobile->Message(MSG_ERROR, "The board you have set does not exist."); return; } board->AddPost(post); }
BOOL CMDABoard::Execute(const std::string &verb, Player* mobile,std::vector<std::string> &args, int subcmd) { World* world = World::GetPtr(); if (!args.size()) { Help(mobile); return true; } if (args[0] == "create" && args.size() > 1) { std::vector<std::string>::iterator it, itEnd; std::vector<std::string> parts; std::string name; BoardManager* bmanager; itEnd = args.end(); for (it = ++(args.begin()); it != itEnd; ++it) { parts.push_back((*it)); } name = Explode(parts, " "); Board* board = new Board(); board->SetName(name); bmanager = (BoardManager*)world->GetProperty("boards"); bmanager->AddBoard(board); mobile->Message(MSG_INFO, "Added "+name+"."); return true; } return false; }
void CMDBoard::Set(Player* mobile, int boardid) { World* world = World::GetPtr(); BoardManager* bmanager = (BoardManager*)world->GetProperty("boards"); Board* board = NULL; Property* prop = NULL; if (!bmanager) { mobile->Message(MSG_ERROR, "Can not access the board system."); return; } board = bmanager->GetBoardByIndex(boardid); if (!board) { mobile->Message(MSG_ERROR, "Invalid board."); return; } prop = mobile->variables.FindProperty("board"); if (!prop) { mobile->variables.AddProperty("board", boardid); } else { prop->SetValue(boardid); } mobile->Message(MSG_INFO, "board set"); }
void CMDBoard::List(Player* mobile) { World* world = World::GetPtr(); BoardManager* bmanager = (BoardManager*)world->GetProperty("boards"); Property* prop = NULL; int id = 0; int i = 0; Board* board = NULL; std::vector<BoardPost*>* posts; std::vector<BoardPost*>::iterator it, itEnd; std::stringstream st; if (!bmanager) { mobile->Message(MSG_ERROR, "Can not access the board system."); return; } prop = mobile->variables.FindProperty("board"); if (!prop) { mobile->Message(MSG_ERROR, "No board set."); mobile->Message(MSG_ERROR, "Use board set to choose a board."); return; } id = prop->GetValue().GetInt(); board = bmanager->GetBoardByIndex(id); if (!board) { mobile->Message(MSG_ERROR, "The board you have set does not exist."); return; } posts = board->GetPosts(); if (!posts->size()) { mobile->Message(MSG_INFO, "No messages."); return; } st << left << "#" << setw(12) << "poster" << right << "subject" << endl; st << Repete("-", 80) << endl; itEnd = posts->end(); i = 1; for (it = posts->begin(); it != itEnd; ++it, ++i) { st << left << "[" << setw(5) << i << "]" << setw(12) << (*it)->GetPoster() << right << (*it)->GetSubject() << endl; } mobile->Message(MSG_LIST, st.str()); }
void CMDBoard::Read(Player* mobile, int id) { World* world = World::GetPtr(); BoardPost*post = NULL; BoardManager* bmanager = (BoardManager*)world->GetProperty("boards"); Board* board = NULL; Property* prop = NULL; int boardid = 0; std::stringstream st; if (!bmanager) { mobile->Message(MSG_ERROR, "Can not access the board system."); return; } prop = mobile->variables.FindProperty("board"); if (!prop) { mobile->Message(MSG_ERROR, "No board set."); mobile->Message(MSG_ERROR, "Use board set to choose a board."); return; } boardid = prop->GetValue().GetInt(); board = bmanager->GetBoardByIndex(boardid); if (!board) { mobile->Message(MSG_ERROR, "The board you have set does not exist."); return; } post = board->GetPostByIndex(id); if (!post) { mobile->Message(MSG_ERROR, "That post does not exist."); return; } st << left << setw(15) << "From: " << right << post->GetPoster() << endl; st << left << setw(15) << "Subject: " << right << post->GetSubject() << endl; st << post->GetMessage() << endl; mobile->Message(MSG_INFO, st.str()); }
void CMDBoard::Show(Player* mobile) { World* world = World::GetPtr(); BoardManager* bmanager = (BoardManager*)world->GetProperty("boards"); std::vector<Board*> boards; std::vector<Board*>::iterator it, itEnd; int i = 1; std::stringstream st; bmanager->GetBoards(&boards); if (!boards.size()) { mobile->Message(MSG_INFO, "There are no boards to show."); return; } itEnd = boards.end(); for (it = boards.begin(); it!= itEnd; ++it, ++i) { st << left << "[" << setw(3) << i << "]" << right << (*it)->GetName() << endl; } mobile->Message(MSG_LIST, st.str()); }
AttributeTable* GetAttributeTable() { World* world = World::GetPtr(); return (AttributeTable*)world->GetProperty("attributes"); }