00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028
00029 #include "utils.h"
00030 #include "objserial.h"
00031 #include "servemsg.h"
00032 #include <iostream>
00033
00034 using std::cout;
00035 using std::endl;
00036
00037
00038
00039
00040 Serial_out& Serial_out::operator<<
00041 (
00042 std::string& s
00043 )
00044 {
00045 const char *str = s.c_str();
00046 int len = std::strlen(str);
00047 *this << len;
00048 std::memcpy(buf, str, len);
00049 buf += len;
00050 return *this;
00051 }
00052
00053
00054
00055
00056
00057 Serial_in& Serial_in::operator<<
00058 (
00059 std::string& s
00060 )
00061 {
00062 int len;
00063 (*this) << len;
00064 s.assign((char *) buf, len);
00065 buf += len;
00066 return *this;
00067 }
00068
00069
00070
00071
00072
00073
00074
00075 template <class Serial>
00076 void Common_obj_io
00077 (
00078 Serial& io,
00079 unsigned long& addr,
00080 int& tx, int& ty, int& tz,
00081 int& shape, int& frame
00082 )
00083 {
00084 io << addr << tx << ty << tz << shape << frame;
00085 }
00086
00087
00088
00089
00090
00091
00092
00093 template <class Serial>
00094 void Object_io
00095 (
00096 Serial &io,
00097 unsigned long& addr,
00098 int& tx, int& ty, int& tz,
00099 int& shape, int& frame,
00100 int& quality,
00101 std::string& name
00102 )
00103 {
00104 Common_obj_io<Serial>(io, addr, tx, ty, tz, shape, frame);
00105 io << quality << name;
00106 }
00107
00108
00109
00110
00111
00112
00113
00114 template <class Serial>
00115 void Egg_object_io
00116 (
00117 Serial &io,
00118 unsigned long& addr,
00119 int& tx, int& ty, int& tz,
00120 int& shape, int& frame,
00121 int& type,
00122 int& criteria,
00123 int& probability,
00124 int& distance,
00125 bool& nocturnal,
00126 bool& once,
00127 bool& hatched,
00128 bool& auto_reset,
00129 int& data1, int& data2
00130 )
00131 {
00132 Common_obj_io<Serial>(io, addr, tx, ty, tz, shape, frame);
00133 io << type << criteria << probability << distance <<
00134 nocturnal << once << hatched << auto_reset << data1 << data2;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143 template <class Serial>
00144 static void Npc_actor_io
00145 (
00146 Serial &io,
00147 unsigned long& addr,
00148 int& tx, int& ty, int& tz,
00149 int& shape, int& frame, int& face,
00150 std::string& name,
00151 short& npc_num,
00152 short& ident,
00153 int& usecode,
00154 int *properties,
00155 short& attack_mode,
00156 short& alignment,
00157 unsigned long& oflags,
00158 unsigned long& siflags,
00159 unsigned long& type_flags,
00160 short& num_schedules,
00161 Serial_schedule *schedules
00162 )
00163 {
00164 Common_obj_io<Serial>(io, addr, tx, ty, tz, shape, frame);
00165 io << face << name << npc_num << ident << usecode;
00166 int i;
00167 for (i = 0; i < 12; i++)
00168 io << properties[i];
00169 io << attack_mode << alignment << oflags << siflags << type_flags;
00170 io << num_schedules;
00171 for (i = 0; i < num_schedules; i++)
00172 io << schedules[i].time << schedules[i].type <<
00173 schedules[i].tx << schedules[i].ty;
00174 }
00175
00176
00177
00178
00179
00180
00181
00182 int Object_out
00183 (
00184 int fd,
00185 Exult_server::Msg_type id,
00186 unsigned long addr,
00187 int tx, int ty, int tz,
00188 int shape, int frame,
00189 int quality,
00190 std::string name
00191 )
00192 {
00193 static unsigned char buf[Exult_server::maxlength];
00194 unsigned char *ptr = &buf[0];
00195 Serial_out io(ptr);
00196 Object_io(io, addr, tx, ty, tz, shape, frame, quality,
00197 name);
00198 return Exult_server::Send_data(fd, id, buf, ptr - buf);
00199 }
00200
00201
00202
00203
00204
00205
00206
00207 int Object_in
00208 (
00209 unsigned char *data,
00210 int datalen,
00211 unsigned long& addr,
00212 int& tx, int& ty, int& tz,
00213 int& shape, int& frame,
00214 int& quality,
00215 std::string& name
00216 )
00217 {
00218 unsigned char *ptr = data;
00219 Serial_in io(ptr);
00220 Object_io(io, addr, tx, ty, tz, shape, frame, quality,
00221 name);
00222 return (ptr - data) == datalen;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231 int Egg_object_out
00232 (
00233 int fd,
00234 unsigned long addr,
00235 int tx, int ty, int tz,
00236 int shape, int frame,
00237 int type,
00238 int criteria,
00239 int probability,
00240 int distance,
00241 bool nocturnal,
00242 bool once,
00243 bool hatched,
00244 bool auto_reset,
00245 int data1, int data2
00246 )
00247 {
00248 static unsigned char buf[Exult_server::maxlength];
00249 unsigned char *ptr = &buf[0];
00250 Serial_out io(ptr);
00251 Egg_object_io(io, addr, tx, ty, tz, shape, frame,
00252 type, criteria, probability, distance,
00253 nocturnal, once, hatched, auto_reset,
00254 data1, data2);
00255 return Exult_server::Send_data(fd, Exult_server::egg, buf, ptr - buf);
00256 }
00257
00258
00259
00260
00261
00262
00263
00264 int Egg_object_in
00265 (
00266 unsigned char *data,
00267 int datalen,
00268 unsigned long& addr,
00269 int& tx, int& ty, int& tz,
00270 int& shape, int& frame,
00271 int& type,
00272 int& criteria,
00273 int& probability,
00274 int& distance,
00275 bool& nocturnal,
00276 bool& once,
00277 bool& hatched,
00278 bool& auto_reset,
00279 int& data1, int& data2
00280 )
00281 {
00282 unsigned char *ptr = data;
00283 Serial_in io(ptr);
00284 Egg_object_io(io, addr, tx, ty, tz, shape, frame,
00285 type, criteria, probability, distance,
00286 nocturnal, once, hatched, auto_reset, data1, data2);
00287 return (ptr - data) == datalen;
00288 }
00289
00290
00291
00292
00293
00294
00295
00296 int Npc_actor_out
00297 (
00298 int fd,
00299 unsigned long addr,
00300 int tx, int ty, int tz,
00301 int shape, int frame, int face,
00302 std::string name,
00303 short npc_num,
00304 short ident,
00305 int usecode,
00306 int properties[12],
00307 short attack_mode,
00308 short alignment,
00309 unsigned long oflags,
00310 unsigned long siflags,
00311 unsigned long type_flags,
00312 short num_schedules,
00313 Serial_schedule *schedules
00314 )
00315 {
00316 static unsigned char buf[Exult_server::maxlength];
00317 unsigned char *ptr = &buf[0];
00318 Serial_out io(ptr);
00319 Npc_actor_io(io, addr, tx, ty, tz, shape, frame, face,
00320 name, npc_num, ident, usecode,
00321 properties, attack_mode, alignment,
00322 oflags, siflags, type_flags,
00323 num_schedules, schedules);
00324 return Exult_server::Send_data(fd, Exult_server::npc, buf, ptr - buf);
00325 }
00326
00327
00328
00329
00330
00331
00332
00333 int Npc_actor_in
00334 (
00335 unsigned char *data,
00336 int datalen,
00337 unsigned long& addr,
00338 int& tx, int& ty, int& tz,
00339 int& shape, int& frame, int& face,
00340 std::string& name,
00341 short& npc_num,
00342 short& ident,
00343 int& usecode,
00344 int properties[12],
00345 short& attack_mode,
00346 short& alignment,
00347 unsigned long& oflags,
00348 unsigned long& siflags,
00349 unsigned long& type_flags,
00350 short& num_schedules,
00351 Serial_schedule *schedules
00352 )
00353 {
00354 unsigned char *ptr = data;
00355 Serial_in io(ptr);
00356 Npc_actor_io(io, addr, tx, ty, tz, shape, frame, face,
00357 name, npc_num, ident, usecode,
00358 properties, attack_mode, alignment,
00359 oflags, siflags, type_flags,
00360 num_schedules, schedules);
00361 return (ptr - data) == datalen;
00362 }
00363
00364
00365
00366
00367
00368 template <class Serial>
00369 void Game_info_io
00370 (
00371 Serial &io,
00372 int& version,
00373 int& edit_lift,
00374 int& hide_lift,
00375 bool& map_editing,
00376 bool& tile_grid,
00377 bool& map_modified,
00378 int& edit_mode
00379 )
00380 {
00381 io << version << edit_lift << hide_lift <<
00382 map_editing << tile_grid << map_modified << edit_mode;
00383 }
00384
00385
00386
00387
00388
00389
00390
00391 int Game_info_out
00392 (
00393 int fd,
00394 int version,
00395 int edit_lift,
00396 int hide_lift,
00397 bool map_editing,
00398 bool tile_grid,
00399 bool map_modified,
00400 int edit_mode
00401 )
00402 {
00403 static unsigned char buf[Exult_server::maxlength];
00404 unsigned char *ptr = &buf[0];
00405 Serial_out io(ptr);
00406 Game_info_io(io, version, edit_lift, hide_lift,
00407 map_editing, tile_grid, map_modified, edit_mode);
00408 return Exult_server::Send_data(fd, Exult_server::info, buf, ptr - buf);
00409 }
00410
00411
00412
00413
00414
00415
00416
00417 int Game_info_in
00418 (
00419 unsigned char *data,
00420 int datalen,
00421 int& version,
00422 int& edit_lift,
00423 int& hide_lift,
00424 bool& map_editing,
00425 bool& tile_grid,
00426 bool& map_modified,
00427 int& edit_mode
00428 )
00429 {
00430 unsigned char *ptr = data;
00431 Serial_in io(ptr);
00432 Game_info_io(io, version, edit_lift, hide_lift, map_editing,
00433 tile_grid, map_modified, edit_mode);
00434 return (ptr - data) == datalen;
00435 }
00436