aesop-client.h

Go to the documentation of this file.
00001 /*
00002  * aesop-client.h
00003  *
00004  * Copyright (C) 2008,2009  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  * Basic client objects for the aesop client/server framework.
00031  */
00032 
00033 #ifndef AESOP_AESOP_CLIENT_H__
00034 #define AESOP_AESOP_CLIENT_H__
00035 
00036 // includes --------------------------------------------------------------------
00037 #include "aesop-map/map.h"
00038 #include "aesop-physics/aesop-physics.h"
00039 #include "conversation/conversation.h"
00040 #include "crypto/crypto.h"
00041 #include "dialog/dialog.h"
00042 #include "netlib/netlib.h"
00043 #include "story/story.h"
00044 #include "threadsafe/threadsafe_map.h"
00045 #include "xdrbuf/xdrbuf.h"
00046 
00047 
00048 // forward declarations
00049 class Datahash;
00050 namespace aesop {
00051         class MapDynamics;
00052 };
00053 
00054 
00055 namespace aesop {
00056 
00085 
00088 
00089 enum eClientState {
00090         eClientState_Searching  = 1, 
00091         eClientState_Connecting = 2, 
00092         eClientState_Connected  = 3, 
00093 
00094         // keep this last!
00095         eClientState_Invalid    = 0
00096 };
00097 
00098 
00099 
00102 class ClientHost {
00103 public:
00104         // aesop::ClientHost class interface methods ---------------------------
00105         virtual void notifyKey(IN smart_ptr<crypto::DESKey>& desKey) = 0;
00106 
00108         virtual void requestDialog(IN const char * guid,
00109                                 IN int playerId,
00110                                 IN const Datahash * dialog,
00111                                 IN dialog::Host * host) = 0;
00112 
00114         virtual void destroyDialog(IN const char * guid,
00115                                 IN int playerId) = 0;
00116 
00119         virtual void notifyPlayerMap(IN int playerId,
00120                                 IN smart_ptr<MapDynamics>& dyn) = 0;
00121 
00123         virtual void appendGameData(IN xdrbuf::Output * outbuf) = 0;
00124 
00126         virtual void updateAnimation(IN smart_ptr<PhysicsObject>& obj,
00127                                 IN const char * animationState) = 0;
00128 
00129 protected:
00130         // virtual destructor --------------------------------------------------
00133         virtual ~ClientHost(void) throw();
00134 };
00135 
00136 
00137 
00139 struct server_info_t {
00140         // constructor, manipulators
00141         server_info_t(void) throw() { this->clear(); }
00142         void clear(void) throw() {
00143                         publicName = "";
00144                         address.clear();
00145                 }
00146         bool isValid(void) const throw() {
00147                         return address.isValid();
00148                 }
00149 
00150         // data fields
00151         std::string             publicName;
00152         netlib::address_t       address;
00153 };
00154 
00155 
00156 
00159 typedef threadsafe_map<std::string, server_info_t> server_map_t;
00160 
00161 
00162 
00164 class Client { 
00165 public:
00166         // virtual destructor --------------------------------------------------
00167         virtual ~Client(void) throw();
00168 
00169         // aesop::Client class interface methods -------------------------------
00170 
00172         virtual story::Story * getStory(void) throw() = 0;
00173 
00175         virtual eClientState getState(void) throw() = 0;
00176 
00179         virtual bool getServer(OUT server_info_t& server) = 0;
00180 
00183         virtual const server_map_t& getDiscoveredServers(void) = 0;
00184 
00194         virtual bool requestConnect(IN const char * serverKey) = 0;
00195 
00198         virtual float tick(void) = 0;
00199 
00203         virtual bool createPlayer(IN int playerId) = 0;
00204 
00207         virtual void startLocalConversation(IN const char * guid,
00208                                 IN int playerId,
00209                                 IN smart_ptr<converse::ConversationHost> host) = 0;
00210 
00212         virtual bool isConversationUnderway(IN const char * guid) = 0;
00213 
00216         virtual void newGame(IN int playerId) = 0;
00217 
00219         virtual void requestMove(IN int playerId,
00220                                 IN const point3d_t& delta,
00221                                 IN const point3d_t& euler, 
00222                                 OUT point3d_t& newPosition) = 0;
00223 
00225         virtual bool getPlacement(IN int playerId,
00226                                 OUT placement_t& placement) = 0;
00227 
00229         virtual smart_ptr<PhysicsObject> getPlayerObject(IN int playerId) = 0;
00230 
00231         // public static methods (factories) -----------------------------------
00232         static smart_ptr<Client> create(IN ClientHost * host,
00233                                 IN smart_ptr<story::Story>& story,
00234                                 IN smart_ptr<Datahash>& op_params);
00235 };
00236 
00237 
00238 
00239 };      // aesop namespace
00240 
00241 #endif  // AESOP_AESOP_CLIENT_H__
00242