Planeshift

advicemanager.h

Go to the documentation of this file.
00001 /*
00002  * Advicemanager.h
00003  *
00004  * Copyright (C) 2003 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  *
00018  */
00019 
00020 
00021 #ifndef __ADVICEMANAGER_H__
00022 #define __ADVICEMANAGER_H__
00023 
00024 //=============================================================================
00025 // Crystal Space Includes
00026 //=============================================================================
00027 
00028 //=============================================================================
00029 // Project Includes
00030 //=============================================================================
00031 
00032 //=============================================================================
00033 // Local Includes
00034 //=============================================================================
00035 #include "msgmanager.h"         // parent class
00036 #include "gem.h"
00037 
00038 class psAdviceRequestTimeoutGameEvent;
00039 class psAdviceSessionTimeoutGameEvent;
00040 class Client;
00041 class psDatabase;
00042 class AdviceManager;
00043 class AdviceSession;
00044 
00045 #define ADVICE_QUESTION_TIMEOUT    120000
00046 #define ADVICE_QUESTION_RETRIES         5
00047 #define ADVICE_SESSION_TIMEOUT     300000
00048 
00049 #define SESSION_STATUS_UNKNOWN 0
00050 #define SESSION_STATUS_CLAIMED 1
00051 #define SESSION_STATUS_OWNED   2
00052 
00060 struct AdvisorStruct
00061 {
00062     uint32_t id;
00063     csString request;
00064     bool ready;
00065     bool GM;
00066 };
00067 
00068 
00069 
00077 class AdviceManager : public MessageManager<AdviceManager>
00078 {
00079 public:
00080 
00081     AdviceManager(psDatabase* db);
00082     virtual ~AdviceManager();
00083 
00084     void HandleAdviceMessage(MsgEntry* pMsg,Client* client);
00085 
00091     void AddAdvisor(Client* client);
00092 
00099     void RemoveAdvisor(uint32_t id, int connectionId);
00100 
00106     void AdviceRequestTimeout(AdviceSession* adviceSession);
00107 
00115     void CancelAdvisorSession(gemActor* who, AdviceSession* adviceSession, const char* msg);
00116 
00117     void RemoveSession(AdviceSession* adviceSession);
00118 
00125     bool GetAdvisorMode(int id, int connectionId);
00126 
00127 protected:
00128 
00129     void HandleAdviceRequest(Client* advisee, csString message);
00130     void HandleAdviceResponse(Client* advisee, csString sAdvisee, csString message);
00131     void HandleAdviceList(Client* advisor);
00132     void HandleAdviseeList(Client* advisor);
00133     void HandleListAdvisors(Client* advisor);
00134 
00135     bool FloodControl(csString &newmessage, Client* client);
00136 
00137     csHash<AdviceSession*> AdviseeList;
00138     csArray<AdvisorStruct>    advisors;
00139     size_t advisorPos;
00140     psDatabase*              database;
00141 };
00142 
00143 class psAdviceSessionTimeoutGameEvent : public psGEMEvent
00144 {
00145 protected:
00146     AdviceManager* advicemanager;
00147     gemActor* adviseeActor;
00148     gemActor* advisorActor;
00149 
00150 public:
00151     AdviceSession* adviceSession;
00152 
00153     psAdviceSessionTimeoutGameEvent(AdviceManager* mgr,
00154                                     int delayticks,
00155                                     gemActor* advisee,
00156                                     AdviceSession* adviceRequest);
00157 
00158     virtual ~psAdviceSessionTimeoutGameEvent();
00159 
00160     virtual void DeleteObjectCallback(iDeleteNotificationObject* object);
00161 
00162     virtual void Trigger();
00163 };
00164 
00165 class psAdviceRequestTimeoutGameEvent : public psGEMEvent
00166 {
00167 protected:
00168     AdviceManager* advicemanager;
00169     gemActor* adviseeActor;
00170     gemActor* advisorActor;
00171 
00172 public:
00173     AdviceSession* adviceSession;
00174 
00175     psAdviceRequestTimeoutGameEvent(AdviceManager* mgr,
00176                                     int delayticks,
00177                                     gemActor* advisee,
00178                                     AdviceSession* adviceRequest);
00179 
00180     virtual ~psAdviceRequestTimeoutGameEvent();
00181 
00182     virtual void DeleteObjectCallback(iDeleteNotificationObject* object);
00183 
00184     virtual void Trigger();
00185 };
00186 
00187 #endif
00188 
00189 
00190