File: LuaHandleSynced.h

package info (click to toggle)
spring 0.81.2.1%2Bdfsg1-6
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 28,496 kB
  • ctags: 37,096
  • sloc: cpp: 238,659; ansic: 13,784; java: 12,175; awk: 3,428; python: 1,159; xml: 738; perl: 405; sh: 297; makefile: 267; pascal: 228; objc: 192
file content (99 lines) | stat: -rw-r--r-- 2,838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifndef LUA_HANDLE_SYNCED
#define LUA_HANDLE_SYNCED
// LuaHandleSynced.h: interface for the CLuaHandleSynced class.
//
//////////////////////////////////////////////////////////////////////

#include <map>
#include <string>
using std::map;
using std::string;


#include "LuaHandle.h"


struct lua_State;


class CLuaHandleSynced : public CLuaHandle
{
	public:
		bool Initialize(const string& syncData);
		string GetSyncData();

		bool GetAllowChanges() const { return allowChanges; }

	public: // call-ins
		bool HasCallIn(const string& name);
		virtual bool SyncedUpdateCallIn(const string& name);
		virtual bool UnsyncedUpdateCallIn(const string& name);

		void GameFrame(int frameNumber);
		bool GotChatMsg(const string& msg, int playerID);
		bool RecvLuaMsg(const string& msg, int playerID);
		void RecvFromSynced(int args); // not an engine call-in

		bool SyncedActionFallback(const string& line, int playerID);

	public: // custom call-in
		bool HasSyncedXCall(const string& funcName);
		bool HasUnsyncedXCall(const string& funcName);
		int XCall(lua_State* srcState, const string& funcName);
		int SyncedXCall(lua_State* srcState, const string& funcName);
		int UnsyncedXCall(lua_State* srcState, const string& funcName);

	protected:
		CLuaHandleSynced(const string& name, int order, const string& msgPrefix);
		virtual ~CLuaHandleSynced();
		void Init(const string& syncedFile,
		          const string& unsyncedFile,
		          const string& modes);
		bool SetupSynced(const string& code, const string& filename);
		bool SetupUnsynced(const string& code, const string& filename);

		// hooks to add code during initialization
		virtual bool AddSyncedCode() = 0;
		virtual bool AddUnsyncedCode() = 0;

		string LoadFile(const string& filename, const string& modes) const;

		bool CopyGlobalToUnsynced(const char* name);
		bool SetupUnsyncedFunction(const char* funcName);
		bool LoadUnsyncedCode(const string& code, const string& debug);
		bool SyncifyRandomFuncs();
		bool CopyRealRandomFuncs();
		bool LightCopyTable(int dstIndex, int srcIndex);

	protected:
		static CLuaHandleSynced* GetActiveHandle() {
			return dynamic_cast<CLuaHandleSynced*>(activeHandle);
		}

	protected:
		const string messagePrefix;
		bool allowChanges;
		bool allowUnsafeChanges;
		bool teamsLocked; // disables CallAsTeam()
		map<string, string> textCommands; // name, help

	private: // call-outs
		static int SyncedRandom(lua_State* L);

		static int LoadStringData(lua_State* L);

		static int SendToUnsynced(lua_State* L);

		static int CallAsTeam(lua_State* L);

		static int AllowUnsafeChanges(lua_State* L);

		static int AddSyncedActionFallback(lua_State* L);
		static int RemoveSyncedActionFallback(lua_State* L);

		static int GetWatchWeapon(lua_State* L);
		static int SetWatchWeapon(lua_State* L);
};


#endif /* LUA_HANDLE_SYNCED */