-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcajeput_int.h
366 lines (269 loc) · 10.2 KB
/
cajeput_int.h
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
/* Copyright (c) 2009-2010 Aidan Thornton, all rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY AIDAN THORNTON ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL AIDAN THORNTON BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* This is an internal header that should not be used by external modules.
(Yes, I know caj_omv_udp.cpp uses it, and that needs fixing.) */
#ifndef CAJEPUT_INT_H
#define CAJEPUT_INT_H
#include <string>
#include <map>
#include <vector>
#include <set>
#include <deque>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include "caj_llsd.h"
#include "cajeput_core.h"
#include "cajeput_world.h"
#include "cajeput_user.h"
#include "cajeput_grid_glue.h"
#include "cajeput_user_glue.h"
#include "caj_logging.h"
#define USER_CONNECTION_TIMEOUT 15
#define USER_CONNECTION_TIMEOUT_PAUSED 90
struct cap_descrip;
typedef std::map<std::string,cap_descrip*> named_caps_map;
typedef std::map<std::string,cap_descrip*>::iterator named_caps_iter;
// ---------------- CALLBACKS CODE ---------------
// FIXME - I think this is generating a bunch of practically identical code
// for each possible function pointer type, which is not good!
template <class T>
struct caj_cb_entry {
T cb;
void *priv;
};
template <class T>
bool operator < (const caj_cb_entry<T> &e1, const caj_cb_entry<T> &e2) {
return e1.cb < e2.cb || (e1.cb == e2.cb && e1.priv < e2.priv);
}
template <class T>
struct caj_callback {
// ideally, we'd typedef the iterator too, but C++ ain't that smart
typedef std::set<caj_cb_entry<T> > cb_set;
std::set<caj_cb_entry<T> > callbacks;
void add_callback(T cb, void *priv) {
caj_cb_entry<T> entry;
entry.cb = cb; entry.priv = priv;
callbacks.insert(entry);
}
void remove_callback(T cb, void *priv) {
caj_cb_entry<T> entry;
entry.cb = cb; entry.priv = priv;
callbacks.erase(entry);
}
};
// -------------------------------------------------------------
struct sl_throttle {
double time; // time last refilled
float level, rate; // current reservoir level and flow rate
};
// note - allocated with calloc, can't use C++ stuff
struct avatar_obj {
struct world_obj ob;
caj_vector4 footfall;
primitive_obj *attachments[NUM_ATTACH_POINTS];
primitive_obj *sitting_on; // not the same as ob.parent
};
struct user_ctx {
struct user_ctx* next;
char *first_name, *last_name, *name, *group_title;
uint32_t circuit_code;
struct user_hooks *userh;
void *user_priv;
// this is core enough we can't do without it!
struct cap_descrip* seed_cap;
named_caps_map named_caps;
std::set<user_ctx**> self_ptrs;
// float main_throttle; // FIXME - is this needed?
struct sl_throttle throttles[SL_NUM_THROTTLES];
uint16_t dirty_terrain[16];
// Event queue stuff. FIXME - seperate this out
struct {
caj_llsd *queued;
caj_llsd *last;
int ctr;
SoupMessage *msg;
double timeout;
} evqueue;
uuid_t session_id;
uuid_t secure_session_id;
uuid_t user_id;
int flags; // AGENT_FLAG_*
float draw_dist;
double last_activity;
struct simulator_ctx* sim;
struct simgroup_ctx* sgrp;
struct avatar_obj* av;
caj_callback<user_generic_cb> delete_hook; // notifies when this user removed
uint32_t wearable_serial;
int pending_wearable_lookups;
struct caj_string texture_entry, visual_params;
struct animation_desc default_anim;
std::vector<animation_desc> anims;
int32_t anim_seq; // FIXME - seems fishy
struct teleport_desc *tp_out;
// FIXME - move this out of struct to save l KB of space per child agent
struct wearable_desc wearables[SL_NUM_WEARABLES];
inventory_contents* sys_folders;
int sys_folders_state; // SYS_FOLDERS_*
caj_callback<user_generic_cb> sys_folders_cbs;
void *grid_priv;
std::map<uint32_t, int> obj_upd; // FIXME - HACK
std::deque<uint32_t> deleted_objs;
int shutdown_ctr; // for slow user removal (AGENT_FLAG_IN_SLOW_REMOVAL)
// Blech. Remove this/move to seperate struct?
caj_vector3 start_pos, start_look_at;
struct obj_chat_listener listen;
user_ctx(simulator_ctx* our_sim) : sim(our_sim), av(NULL) {
}
};
struct world_obj;
// goes in world_obj.chat
struct obj_chat_listeners {
struct world_obj *obj;
// msg and all strings pointed to by it owned by caller
std::set<std::pair<int32_t, obj_chat_listener*> > channels;
};
struct asset_cb_desc {
void(*cb)(struct simgroup_ctx *sgrp, void *priv,
struct simple_asset *asset);
void *cb_priv;
asset_cb_desc( void(*cb_)(struct simgroup_ctx *sgrp, void *priv,
struct simple_asset *asset), void *cb_priv_) :
cb(cb_), cb_priv(cb_priv_) { };
};
#define CAJ_ASSET_PENDING 0
#define CAJ_ASSET_READY 1
#define CAJ_ASSET_MISSING 2
struct asset_desc {
simple_asset asset;
int status; // CAJ_ASSET_*
std::set<asset_cb_desc*> cbs;
};
struct simgroup_ctx {
std::map<obj_uuid_t,inventory_contents*> inv_lib;
struct inventory_folder inv_lib_root;
std::map<obj_uuid_t,texture_desc*> textures;
std::map<obj_uuid_t,asset_desc*> assets;
GTimer *timer;
caj_logger *log;
char *release_notes;
int release_notes_len;
int state_flags;
GKeyFile *config;
SoupServer *soup;
SoupSession *soup_session;
void *grid_priv;
struct cajeput_grid_hooks gridh;
int hold_off_shutdown;
uint16_t http_port;
char *ip_addr;
std::map<std::string,cap_descrip*> caps;
std::map<uint64_t, simulator_ctx*> sims;
caj_callback<sim_generic_cb> sim_added_hook;
};
struct collision_pair {
uint32_t collidee, collider;
collision_pair(uint32_t collidee, uint32_t collider) :
collidee(collidee), collider(collider) { }
};
static inline bool operator<(const collision_pair &lhs,
const collision_pair &rhs) {
return lhs.collidee < rhs.collidee || (lhs.collidee == rhs.collidee &&
lhs.collider < rhs.collider);
}
#define CAJEPUT_SIM_READY 1 // TODO
#define CAJEPUT_SGRP_SHUTTING_DOWN 2
typedef std::set<collision_pair> collision_state;
struct simulator_ctx {
simgroup_ctx *sgrp;
char *cfg_sect, *shortname;
struct user_ctx* ctxts;
char *name;
uint32_t region_x, region_y;
uint64_t region_handle;
float *terrain;
int state_flags;
uint16_t udp_port;
uuid_t region_id, owner;
std::map<obj_uuid_t,world_obj*> uuid_map;
std::map<uint32_t,world_obj*> localid_map;
struct world_octree* world_tree;
gchar *welcome_message;
void *phys_priv;
struct cajeput_physics_hooks physh;
void *script_priv;
struct cajeput_script_hooks scripth;
collision_state *collisions;
//struct obj_bucket[8][8][32];
// bunch of callbacks
caj_callback<sim_generic_cb> shutdown_hook;
};
void caj_send_im_from_script(struct simulator_ctx *sim,
struct primitive_obj *prim,
struct caj_instant_message *im);
// ------ CALLBACKS ----------------
void sim_call_shutdown_hook(struct simulator_ctx *sim);
void sim_int_init_udp(struct simulator_ctx *sim);
void world_obj_add_listen(struct simulator_ctx *sim, struct world_obj *ob,
int32_t channel, struct obj_chat_listener* listen);
// FIXME - rename and export more widely!
void llsd_soup_set_response(SoupMessage *msg, caj_llsd *llsd);
void user_int_free_texture_sends(struct user_ctx *ctx);
void user_int_event_queue_init(user_ctx *ctx);
void user_int_event_queue_check_timeout(user_ctx *ctx, double time_now);
void user_int_event_queue_free(user_ctx *ctx);
void user_int_caps_init(simulator_ctx *sim, user_ctx *ctx,
struct sim_new_user *uinfo);
void user_int_caps_cleanup(user_ctx *ctx);
void user_remove_int(user_ctx **user); // for internal use only.
// FIXME - this really shouldn't be exposed
void user_av_chat_callback(struct simulator_ctx *sim, struct world_obj *obj,
const struct chat_message *msg, void *user_data);
// for strictly internal use ONLY! Really! Use equivalents in cajeput_core.h
void user_send_teleport_failed(struct user_ctx* ctx, const char* reason);
void user_send_teleport_progress(struct user_ctx* ctx, const char* msg, uint32_t flags);
void user_send_teleport_complete(struct user_ctx* ctx, struct teleport_desc *tp);
void user_call_delete_hook(struct user_ctx *ctx);
void world_int_dump_prims(simulator_ctx *sim);
void world_int_load_prims(simulator_ctx *sim);
struct world_octree* world_octree_create();
void world_octree_destroy(struct world_octree* tree);
inventory_item* prim_update_script(struct simulator_ctx *sim, struct primitive_obj *prim,
uuid_t item_id, int script_running,
unsigned char *data, int data_len,
compile_done_cb cb, void *cb_priv);
void world_int_init_obj_updates(user_ctx *ctx); // ick - HACK.
void world_save_script_state(simulator_ctx *sim, inventory_item *inv,
caj_string *out);
// note - takes ownership of the passed-in buffer
void world_load_script_state(inventory_item *inv, caj_string *state);
// --------- HACKY OBJECT UPDATE STUFF ---------------
// --------- CAPS STUFF -----------------------------
// perhaps caps-related functions should be externally available
struct cap_descrip; // opaque
typedef void (*caps_callback) (SoupMessage *msg, user_ctx *ctx, void *user_data);
struct cap_descrip* user_add_named_cap(struct simulator_ctx *ctx,
const char* name, caps_callback callback,
user_ctx* user, void *user_data);
void caj_int_caps_init(simgroup_ctx *sgrp);
#endif