00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdio.h>
00020 #include <stdlib.h>
00021 #include <mysql/mysql.h>
00022 #include <libsql++.h>
00023 #include <string>
00024 using std::string;
00025 #include <libcgi++.h>
00026 #include <libwolfshade.h>
00027
00028 #include "BaseForm.h"
00029 #include "WolfshadeWeb.h"
00030
00031
00032 #include "RoomForm.h"
00033
00034
00035 namespace cgi
00036 {
00037
00038
00039 RoomForm::RoomForm(Web *web)
00040 :BaseForm(web, "roomform")
00041 ,m_edit(0)
00042 ,m_error(false)
00043 {
00044 Query q(GetDatabase());
00045
00046 q.get_result("select * from zone");
00047 while (q.fetch_row())
00048 {
00049 db::Zone *tmp = new db::Zone(GetDatabase(),&q);
00050 m_zone[tmp -> num] = tmp;
00051 }
00052 q.free_result();
00053
00054 q.get_result("select * from room_type");
00055 while (q.fetch_row())
00056 {
00057 db::Room_type *tmp = new db::Room_type(GetDatabase(),&q);
00058 m_type[tmp -> num] = tmp;
00059 }
00060 q.free_result();
00061
00062 q.get_result("select * from room_size");
00063 while (q.fetch_row())
00064 {
00065 db::Room_size *tmp = new db::Room_size(GetDatabase(),&q);
00066 m_size[tmp -> num] = tmp;
00067 }
00068 q.free_result();
00069 }
00070
00071
00072 RoomForm::~RoomForm()
00073 {
00074 for (zones_t::iterator it = m_zone.begin(); it != m_zone.end(); it++)
00075 {
00076 delete (*it).second;
00077 }
00078 for (types_t::iterator it = m_type.begin(); it != m_type.end(); it++)
00079 {
00080 delete (*it).second;
00081 }
00082 for (sizes_t::iterator it = m_size.begin(); it != m_size.end(); it++)
00083 {
00084 delete (*it).second;
00085 }
00086 }
00087
00088
00089 void RoomForm::Process()
00090 {
00091 char action[200];
00092
00093 if (GetForm() -> getvalue("roomform",action,200))
00094 {
00095 if (!strcmp(action,"edit"))
00096 {
00097 char slask[100];
00098 GetForm() -> getvalue("edit",slask,100);
00099 m_edit = atol(slask);
00100 }
00101 else
00102 if (!strcmp(action," Save "))
00103 {
00104 char slask[100];
00105 GetForm() -> getvalue("num",slask,100);
00106 long num = atol(slask);
00107 GetForm() -> getvalue("onum",slask,100);
00108 long onum = atol(slask);
00109 db::Room room(GetDatabase(),num);
00110
00111 if (num != onum && room.num)
00112 {
00113 m_error = true;
00114 }
00115 else
00116 {
00117 long affects = 0;
00118 char value[256];
00119 GetForm() -> getfirst(slask,100,value,256);
00120 while (*slask)
00121 {
00122 if (!strcmp(slask,"affects"))
00123 affects |= atol(value);
00124 GetForm() -> getnext(slask,100,value,256);
00125 }
00126
00127 GetForm() -> EnableRaw( true );
00128 room.num = num;
00129 GetForm() -> getvalue("name",room.name,255);
00130 int l = GetForm() -> getlength("descr");
00131 if (room.description)
00132 delete room.description;
00133 room.description = new char[l * 2 + 100];
00134 GetForm() -> getvalue("descr",room.description,255);
00135 GetForm() -> getvalue("zone",slask,100);
00136 room.zone = atol(slask);
00137 sprintf(room.affects,"%ld",affects);
00138 GetForm() -> getvalue("type",slask,100);
00139 room.type = atol(slask);
00140 GetForm() -> getvalue("size",slask,100);
00141 room.size = atol(slask);
00142 GetForm() -> getvalue("virtual_room",slask,100);
00143 room.virtual_room = atoi(slask);
00144 GetForm() -> getvalue("virtual_char",room.virtual_char,255);
00145 GetForm() -> getvalue("design_char",slask,100);
00146 sprintf(room.design_char,"%c",*slask);
00147 GetForm() -> getvalue("resource",slask,100);
00148 room.resource = atoi(slask);
00149 GetForm() -> getvalue("resource_speed",slask,100);
00150 room.resource_speed = atoi(slask);
00151
00152 room.save();
00153 m_edit = num;
00154 }
00155 }
00156 else
00157 if (!strcmp(action," Save Extra ") ||
00158 !strcmp(action," Add Extra ") )
00159 {
00160 char slask[100];
00161 GetForm() -> getvalue("num",slask,100);
00162 long num = atol(slask);
00163 db::Room_extra x(GetDatabase(),num);
00164 GetForm() -> getvalue("roomnum",slask,100);
00165 long roomnum = atol(slask);
00166
00167 GetForm() -> EnableRaw(true);
00168 x.room = roomnum;
00169 GetForm() -> getvalue("keyword",x.keyword,255);
00170 GetForm() -> getvalue("descr",x.description,255);
00171 x.save();
00172
00173 m_edit = roomnum;
00174 }
00175 else
00176 if (!strcmp(action," Save Door ") ||
00177 !strcmp(action," Add Door ") )
00178 {
00179 char slask[100];
00180 GetForm() -> getvalue("num",slask,100);
00181 long num = atol(slask);
00182 db::Room_door door(GetDatabase(),num);
00183 GetForm() -> getvalue("roomnum",slask,100);
00184 long roomnum = atol(slask);
00185
00186 GetForm() -> EnableRaw(true);
00187 door.room = roomnum;
00188 GetForm() -> getvalue("dir",slask,100);
00189 door.direction = atol(slask);
00190 GetForm() -> getvalue("keyword",door.keyword,255);
00191 GetForm() -> getvalue("type",door.type,100);
00192 GetForm() -> getvalue("key",slask,100);
00193 door.vnumkey = atol(slask);
00194 GetForm() -> getvalue("toroom",slask,100);
00195 door.toroom = atol(slask);
00196 door.save();
00197
00198 m_edit = roomnum;
00199 }
00200 else
00201 if (!strcmp(action,"orientation"))
00202 {
00203
00204 char slask[100];
00205 GetForm() -> getvalue("room",slask,100);
00206 long roomnum = atol(slask);
00207 GetForm() -> getvalue("direction",slask,100);
00208 long dir = atol(slask);
00209 GetForm() -> getvalue("toroom",slask,100);
00210 long toroom = atol(slask);
00211 char sql[200];
00212 sprintf(sql,"select * from room_door where room=%ld and direction=%ld",
00213 roomnum,dir);
00214 db::Room_door door(GetDatabase(),sql);
00215 if (!toroom)
00216 {
00217 door.erase();
00218
00219 m_edit = door.toroom;
00220 }
00221 else
00222 {
00223 if (!door.num)
00224 {
00225 door.vnumkey = -1;
00226 strcpy(door.type, "1");
00227 }
00228 door.room = roomnum;
00229 door.direction = dir;
00230 door.toroom = toroom;
00231 door.save();
00232
00233 m_edit = roomnum;
00234 }
00235 }
00236 }
00237 }
00238
00239
00240 void RoomForm::Select(const string &)
00241 {
00242 }
00243
00244
00245 void RoomForm::List()
00246 {
00247 }
00248
00249
00250 void RoomForm::Display(long)
00251 {
00252 WolfshadeWeb *web = static_cast<WolfshadeWeb *>(GetWeb());
00253 Database *db = GetDatabase();
00254 Query q(db);
00255 Query q2(db);
00256 long zonesize = 0;
00257 char sql[200];
00258
00259 zonesize = EditingZone();
00260
00261 if (!m_edit)
00262 web -> DisplayStartAntalForm();
00263
00264 if (m_error)
00265 {
00266 printf("<h3>New Room# is already taken</h3>");
00267 }
00268
00269
00270 {
00271 if (m_edit)
00272 sprintf(sql,"select * from room where num=%ld",m_edit);
00273 else
00274 {
00275 if (GetZone())
00276 {
00277 sprintf(sql,"select * from room where zone=%ld or (num>=%ld and num<%ld) order by num",
00278 GetZone(),GetZone() * 100,GetZone() * 100 + zonesize);
00279 }
00280 else
00281 {
00282 sprintf(sql,"select * from room where num>=%ld order by num limit %ld",GetStart(),GetAntal());
00283 }
00284 }
00285 q.get_result(sql);
00286 char header[100];
00287
00288 if (m_edit)
00289 sprintf(header," Editing Room#%ld",m_edit);
00290 else
00291 sprintf(header," Rooms (%ld rooms displayed)",q.num_rows());
00292 Table tbl("#000000", 3, header);
00293 printf("<tr bgcolor=#ffffff>");
00294 printf("<th align=left> Room | Vnum</th>");
00295 if (!GetZone())
00296 printf("<th align=left> Zone</th>");
00297 printf("<th align=left> Type</th>");
00298 printf("<th align=left> Size</th>");
00299 printf("</tr>");
00300
00301 while (q.fetch_row())
00302 {
00303 db::Room room(db,&q);
00304
00305 printf("<tr bgcolor=#c0c0c0>");
00306 printf("<td bgcolor=#808080>");
00307 ShowRoom(room,true);
00308 printf("</td>");
00309 if (!GetZone())
00310 {
00311 if (m_zone[room.zone])
00312 {
00313 printf("<td bgcolor=#808080>");
00314 ShowZone(*m_zone[room.zone],true);
00315 printf("</td>");
00316 }
00317 else
00318 printf("<td bgcolor=#808080> %s </td>",m_zone[room.zone] ? htmlcolor(m_zone[room.zone] -> name) : "<invalid zone>" );
00319 }
00320 printf("<td bgcolor=#c0c0c0> %s </td>",m_type[room.type] ? m_type[room.type] -> name : "<invalid type>");
00321 printf("<td bgcolor=#c0c0c0> %s </td>",m_size[room.size] ? m_size[room.size] -> name : "<invalid size>");
00322 printf("</tr>");
00323 }
00324 q.free_result();
00325 }
00326 printf("<br>");
00327
00328 if (m_edit)
00329 {
00330 db::Room room(db,m_edit);
00331
00332 if (!room.virtual_room)
00333 {
00334 {
00335 Table tbl("#000000", 3, " Orientation");
00336
00337
00338
00339
00340
00341
00342 for (int y = 0; y < 5; y++)
00343 {
00344 printf("<tr bgcolor=#ffffc0>");
00345 for (int x = 0; x < 5; x++)
00346 {
00347 int dir = -1;
00348 printf("<td align=middle valign=middle>");
00349 switch (y * 5 + x)
00350 {
00351 case 2:
00352 dir = 0;
00353 break;
00354 case 4:
00355 dir = 4;
00356 break;
00357 case 7:
00358 printf(" <b>North</b> ");
00359 break;
00360 case 8:
00361 printf(" <b>Up</b> ");
00362 break;
00363 case 10:
00364 dir = 3;
00365 break;
00366 case 11:
00367 printf(" <b>West</b> ");
00368 break;
00369 case 12:
00370 dir = 6;
00371 break;
00372 case 13:
00373 printf(" <b>East</b> ");
00374 break;
00375 case 14:
00376 dir = 1;
00377 break;
00378 case 16:
00379 printf(" <b>Down</b> ");
00380 break;
00381 case 17:
00382 printf(" <b>South</b> ");
00383 break;
00384 case 20:
00385 dir = 5;
00386 break;
00387 case 22:
00388 dir = 2;
00389 break;
00390 }
00391 if (dir == 6)
00392 {
00393 printf("<div style=\"background-color: #808080\">");
00394 ShowRoom(room,false,false,true);
00395 printf("</div>");
00396 printf("<b>%ld</b>",room.num);
00397 }
00398 else
00399 if (dir > -1)
00400 {
00401 char sql[200];
00402 sprintf(sql,"select * from room_door where room=%ld and direction=%d",
00403 room.num,dir);
00404 db::Room_door x(db,sql);
00405 if (x.toroom)
00406 {
00407 db::Room room(db,x.toroom);
00408 printf("<div style=\"background-color: #808080\">");
00409 if (room.num)
00410 {
00411 ShowRoom(room,true,false,true);
00412 }
00413 else
00414 {
00415
00416 sprintf(sql,"select * from vzone where vnumstart<=%ld and %ld<vnumstart+sizex*sizey",x.toroom,x.toroom);
00417 db::Vzone vz(db,sql);
00418 if (vz.num)
00419 {
00420 ShowVirtual(vz,true,false,true);
00421 }
00422 }
00423 printf("</div>");
00424 }
00425 printf("<form action=%s method=post>",GetCgiName().c_str());
00426 printf("<input type=hidden name=roomform value=orientation>");
00427 printf("<input type=hidden name=room value=%ld>",room.num);
00428 printf("<input type=hidden name=direction value=%d>",dir);
00429 printf(" <input type=text size=9 name=toroom value=%ld> ",x.toroom);
00430 printf("</form>");
00431 }
00432 printf("</td>");
00433 }
00434 printf("</tr>");
00435 }
00436 }
00437 printf("<br>");
00438 }
00439
00440 {
00441 Table tbl("#000000", 3);
00442 long affects = asciiconvert(room.affects);
00443
00444 printf("<form action=%s method=post>",GetCgiName().c_str());
00445 printf("<input type=hidden name=onum value=%ld>",room.num);
00446
00447 inputnum("Vnum","num",room.num);
00448 inputstr("Name","name",60,room.name,true);
00449 textarea("Description","descr",room.description,true);
00450 inputselect(q,"Zone","zone","select num,name from zone order by name",room.zone,true);
00451
00452 inputbit(q,"Affects","affects","select num,name from room_bit",affects,4);
00453 inputselect(q,"Type","type","select num,name from room_type",room.type);
00454 inputselect(q,"Size","size","select num,name from room_size",room.size);
00455 printf("<tr bgcolor=#ffffc0>");
00456 printf("<td>VirtualRoom</td>");
00457 printf("<td><input type=checkbox name=virtual_room value=1%s>",
00458 room.virtual_room ? " CHECKED" : "");
00459 printf("</td>");
00460 printf("</tr>");
00461 inputstr("VirtualChar","virtual_char",20,room.virtual_char,true);
00462 inputstr("DesignChar","design_char",2,room.design_char);
00463 inputselect(q,"Resource","resource","select num,alias from resource order by alias",room.resource,true);
00464 inputselect(q,"ResourceSpeed","resource_speed","select num,name from resource_speed order by num",room.resource_speed);
00465
00466 inputsubmit(" Save ");
00467
00468 printf("</form>");
00469 }
00470 printf("<br>");
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 if (!room.virtual_room)
00486 {
00487 sprintf(sql,"select * from room_door where room=%ld",room.num);
00488 q.get_result(sql);
00489 while (q.fetch_row())
00490 {
00491 db::Room_door door(db,&q);
00492 {
00493 Table tbl("#000000", 3);
00494 long type = asciiconvert(door.type);
00495
00496 printf("<form action=%s method=post>",GetCgiName().c_str());
00497 printf("<input type=hidden name=num value=%ld>",door.num);
00498 printf("<input type=hidden name=roomnum value=%ld>",room.num);
00499
00500 inputselect(q2,"Direction","dir","select num,name from room_dir order by ordning",door.direction);
00501 inputstr("Keyword","keyword",40,door.keyword);
00502 inputbit(q2,"Type","type","select num,name from door_type",type,3,true);
00503 inputnum("Key","key",door.vnumkey);
00504 inputnum("ToRoom","toroom",door.toroom);
00505 inputsubmit(" Save Door ");
00506
00507 printf("</form>");
00508 }
00509 printf("<br>");
00510 }
00511 q.free_result();
00512
00513
00514 {
00515 Table tbl("#000000", 3);
00516 long type = 1;
00517
00518 SetColor("#c0ffff");
00519 printf("<form action=%s method=post>",GetCgiName().c_str());
00520 printf("<input type=hidden name=num value=%d>",0);
00521 printf("<input type=hidden name=roomnum value=%ld>",room.num);
00522
00523 inputselect(q2,"Direction","dir","select num,name from room_dir order by ordning",0);
00524 inputstr("Keyword","keyword",40,"");
00525 inputbit(q2,"Type","type","select num,name from door_type",type,3,true);
00526 inputnum("Key","key",-1);
00527 inputnum("ToRoom","toroom",-1);
00528 inputsubmit(" Add Door ");
00529
00530 printf("</form>");
00531 }
00532 printf("<br>");
00533 }
00534
00535
00536 sprintf(sql,"select * from room_extra where room=%ld",room.num);
00537 q.get_result(sql);
00538 while (q.fetch_row())
00539 {
00540 db::Room_extra x(db,&q);
00541 {
00542 Table tbl("#000000", 3);
00543
00544 printf("<form action=%s method=post>",GetCgiName().c_str());
00545 printf("<input type=hidden name=num value=%ld>",x.num);
00546 printf("<input type=hidden name=roomnum value=%ld>",room.num);
00547
00548 inputstr("Keyword","keyword",60,x.keyword);
00549 textarea("Description","descr",x.description,true);
00550 inputsubmit(" Save Extra ");
00551
00552 printf("</form>");
00553 }
00554 printf("<br>");
00555 }
00556 q.free_result();
00557
00558
00559 {
00560 Table tbl("#000000", 3);
00561
00562 SetColor("#c0ffff");
00563 printf("<form action=%s method=post>",GetCgiName().c_str());
00564 printf("<input type=hidden name=num value=%d>",0);
00565 printf("<input type=hidden name=roomnum value=%ld>",room.num);
00566
00567 inputstr("Keyword","keyword",60,"");
00568 textarea("Description","descr","");
00569 inputsubmit(" Add Extra ");
00570
00571 printf("</form>");
00572 SetColor("#ffffc0");
00573 }
00574 printf("<br>");
00575 }
00576 }
00577
00578
00579 }
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602