1 #ifndef LSL_HEADERGUARD_BATTLE_H
2 #define LSL_HEADERGUARD_BATTLE_H
3 
4 #include <set>
5 
6 #include <lslutils/type_forwards.h>
7 #include "ibattle.h"
8 #include "enum.h"
9 
10 namespace LSL {
11 
12 class Server;
13 class User;
14 struct UnitsyncMap;
15 struct UnitsyncMod;
16 
17 namespace Battle {
18 
19 /** \brief model of a multiplayer battle
20 * \todo DOCME */
21 class Battle : public IBattle
22 {
23 public:
24     Battle(IServerPtr serv, int id );
25     ~Battle();
key()26     int key() const { return m_id; }
27 
GetServer()28     const IServerPtr GetServer() { return m_serv; }
GetServer()29     const ConstIServerPtr GetServer() const { return m_serv; }
30 
31 		void SendHostInfo( Enum::HostInfo update );
32     void SendHostInfo( const std::string& Tag );
33     void Update( const std::string& Tag );
34 
35     void Join( const std::string& password = "" );
36     void Leave();
37 
38     void KickPlayer( const CommonUserPtr user );
39 
40     void RingNotReadyPlayers();
41     void RingNotSyncedPlayers();
42     void RingNotSyncedAndNotReadyPlayers();
43     void RingPlayer( const ConstUserPtr u );
44 
45     void Say( const std::string& msg );
46     void DoAction( const std::string& msg );
47 
48     void SetLocalMap( const UnitsyncMap& map );
49 
50     void OnRequestBattleStatus();
51     void SendMyBattleStatus();
52 
53     bool ExecuteSayCommand( const std::string& cmd );
54 
55     void AddBot( const std::string& nick, UserBattleStatus status );
56 
57     void ForceSide( const CommonUserPtr user, int side );
58     void ForceTeam( const CommonUserPtr user, int team );
59     void ForceAlly( const CommonUserPtr user, int ally );
60     void ForceColor( const CommonUserPtr user, const lslColor& col );
61     void ForceSpectator( const CommonUserPtr user, bool spectator );
62     void BattleKickPlayer( const CommonUserPtr user );
63     void SetHandicap( const CommonUserPtr user, int handicap);
64 
65     void OnUserAdded( const CommonUserPtr user );
66     void OnUserBattleStatusUpdated( const CommonUserPtr user, UserBattleStatus status );
67     void OnUserRemoved( const CommonUserPtr user );
68 
69     void ForceUnsyncedToSpectate();
70     void ForceUnReadyToSpectate();
71     void ForceUnsyncedAndUnreadyToSpectate();
72 
73     void SetAutoLockOnStart( bool value );
74     bool GetAutoLockOnStart();
75 
76     void SetLockExternalBalanceChanges( bool value );
77     bool GetLockExternalBalanceChanges();
78 
79     void FixColors();
80     void Autobalance( Enum::BalanceType balance_type = Enum::balance_divide, bool clans = true, bool strong_clans = true, int allyteamsize = 0 );
81     void FixTeamIDs( Enum::BalanceType balance_type = Enum::balance_divide, bool clans = true, bool strong_clans = true, int controlteamsize = 0 );
82 
83     void SendScriptToClients();
84 
85     ///< quick hotfix for bans
86     bool IsBanned(const CommonUserPtr user );
87     ///>
88 
89     void SetImReady( bool ready );
90 
91     const CommonUserPtr GetMe();
92     const ConstCommonUserPtr GetMe() const;
93 
94     void UserPositionChanged( const CommonUserPtr user );
95 
96     void SaveMapDefaults();
97     void LoadMapDefaults( const std::string& mapname );
98 
99     void StartHostedBattle();
100     void StartSpring();
101 
102     void SetInGame( bool ingame );
103 
104     void OnUnitsyncReloaded(  );
105 
106     void SetAutoUnspec(bool value);
GetAutoUnspec()107     bool GetAutoUnspec() { return m_auto_unspec; }
108 
109     void ShouldAutoUnspec();
110     void SetChannel( const ChannelPtr channel );
111     const ChannelPtr GetChannel();
112 private:
113     void OnTimer( const boost::system::error_code& error );
114     // Battle variables
115 
116     ///< quick hotfix for bans
117     std::set<std::string> m_banned_users;
118     std::set<std::string> m_banned_ips;
119     ///>
120 
121     IServerPtr m_serv;
122     bool m_autolock_on_start;
123     bool m_auto_unspec;
124     const int m_id;
125     ChannelPtr m_channel;
126 };
127 
128 } // namespace Battle {
129 } // namespace LSL {
130 
131 /**
132  * \file battle.h
133  * \section LICENSE
134 Copyright 2012 by The libSpringLobby team. All rights reserved.
135 
136 Redistribution and use in source and binary forms, with or without modification, are
137 permitted provided that the following conditions are met:
138 
139    1. Redistributions of source code must retain the above copyright notice, this list of
140       conditions and the following disclaimer.
141 
142    2. Redistributions in binary form must reproduce the above copyright notice, this list
143       of conditions and the following disclaimer in the documentation and/or other materials
144       provided with the distribution.
145 
146 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
147 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
148 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
149 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
150 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
151 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
152 USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
153 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
154 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
155 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
156 **/
157 
158 #endif // LSL_HEADERGUARD_BATTLE_H
159