Google
Web alhem.net
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

WolfshadeWeb.cpp

Go to the documentation of this file.
00001 /*
00002 Copyright (C) 2003  Anders Hedstrom
00003 
00004 This program is free software; you can redistribute it and/or
00005 modify it under the terms of the GNU General Public License
00006 as published by the Free Software Foundation; either version 2
00007 of the License, or (at your option) any later version.
00008 
00009 This program is distributed in the hope that it will be useful,
00010 but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 GNU General Public License for more details.
00013 
00014 You should have received a copy of the GNU General Public License
00015 along with this program; if not, write to the Free Software
00016 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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 "WolfshadeWeb.h"
00029 
00030 
00031 namespace cgi
00032 {
00033 
00034 
00035 WolfshadeWeb::WolfshadeWeb(const string &domain,const string &path)
00036 :MenuWeb(domain, path)
00037 ,m_db("localhost","web","","wolfshade")
00038 ,m_bSetCookie(false)
00039 ,m_start(0)
00040 ,m_antal(0)
00041 ,m_zone(0)
00042 ,m_race(0)
00043 ,m_class(0)
00044 ,m_objtype(0)
00045 ,m_material(0)
00046 ,m_pic_ext("")
00047 //
00048 ,m_form1( this )
00049 ,m_form2( this )
00050 ,m_form3( this )
00051 ,m_form4( this )
00052 ,m_form5( this )
00053 ,m_form6( this )
00054 ,m_form7( this )
00055 ,m_form8( this )
00056 ,m_form9( this )
00057 ,m_form10(this )
00058 ,m_form11(this )
00059 {
00060         RegWebForm( &m_form1 );
00061         RegWebForm( &m_form2 );
00062         RegWebForm( &m_form3 );
00063         RegWebForm( &m_form4 );
00064         RegWebForm( &m_form5 );
00065         RegWebForm( &m_form6 );
00066         RegWebForm( &m_form7 );
00067         RegWebForm( &m_form8 );
00068         RegWebForm( &m_form9 );
00069         RegWebForm( &m_form10 );
00070         RegWebForm( &m_form11 );
00071 
00072         m_menuZone = AddMenuItem(&m_form3, "Zones").num;
00073         m_menuMob = AddMenuItem(&m_form1, "Mobs").num;
00074         m_menuObj = AddMenuItem(&m_form2, "Items").num;
00075         m_menuRoom = AddMenuItem(&m_form4, "Rooms").num;
00076         m_menuVirtual = AddMenuItem(&m_form5, "Virtual").num;
00077         AddMenuSeparator();
00078         m_menuWeapon = AddMenuItem(&m_form8, "Weapons").num;
00079         m_menuSkill = AddMenuItem(&m_form9, "Skills").num;
00080         m_menuResource = AddMenuItem(&m_form10, "Resources").num;
00081 //      AddMenuSeparator();
00082 //      m_menuRace = AddMenuItem(&m_form7, "Races").num;
00083 
00084 //      AddMenuSeparator();
00085 //      AddMenuItem(&m_form6, "Bugs");
00086 
00087         AddMenuSeparator();
00088         {
00089                 char url[256];
00090                 sprintf(url,"%s?style=%d",GetCgiName().c_str(),MENU_STYLE_TOP);
00091                 AddMenuLink(url,"Top");
00092                 sprintf(url,"%s?style=%d",GetCgiName().c_str(),MENU_STYLE_LEFT);
00093                 AddMenuLink(url,"Left");
00094         }
00095 }
00096 
00097 
00098 WolfshadeWeb::~WolfshadeWeb()
00099 {
00100 }
00101 
00102 
00103 void WolfshadeWeb::ReadCookies()
00104 {
00105         char slask[200];
00106         
00107         MenuWeb::ReadCookies();
00108 
00109         if (GetCookies() -> getvalue("ws",slask,200))
00110         {
00111                 Parse pa(slask,":");
00112                 m_start = pa.getvalue();
00113                 m_antal = pa.getvalue();
00114                 m_zone = pa.getvalue();
00115                 m_race = pa.getvalue();
00116                 m_class = pa.getvalue();
00117                 m_objtype = pa.getvalue();
00118                 m_material = pa.getvalue();
00119         }
00120 }
00121 
00122 
00123 void WolfshadeWeb::FormInput()
00124 {
00125         char slask[200];
00126 
00127         MenuWeb::FormInput();
00128 
00129         if (GetForm() -> getvalue("start",slask,200) && *slask)
00130         {
00131                 SetStart(atol(slask));
00132         }
00133         if (GetForm() -> getvalue("antal",slask,200) && *slask)
00134         {
00135                 SetAntal(atol(slask));
00136         }
00137         if (GetForm() -> getvalue("xzonex",slask,200) && *slask)
00138         {
00139                 SetZone(atol(slask));
00140         }
00141         if (GetForm() -> getvalue("xracex",slask,200) && *slask)
00142         {
00143                 SetRace(atol(slask));
00144         }
00145         if (GetForm() -> getvalue("xclassx",slask,200) && *slask)
00146         {
00147                 SetClass(atol(slask));
00148         }
00149         if (GetForm() -> getvalue("xobjtypex",slask,200) && *slask)
00150         {
00151                 SetObjtype(atol(slask));
00152         }
00153         if (GetForm() -> getvalue("xmaterialx",slask,200) && *slask)
00154         {
00155                 SetMaterial(atol(slask));
00156         }
00157         if (!GetPage())
00158         {
00159                 SetPage(m_menuZone);
00160         }
00161         if (!GetStart())
00162         {
00163                 SetStart(1);
00164         }
00165         if (!GetAntal())
00166         {
00167                 SetAntal(10);
00168         }
00169 }
00170 
00171 
00172 void WolfshadeWeb::CreateHeader()
00173 {
00174         if (m_pic.size())
00175         {
00176                 printf("Content-type: image/%s\n",m_pic_ext.c_str());
00177                 printf("\n");
00178                 return;
00179         }
00180         if (m_bSetCookie)
00181         {
00182                 SetTheCookie();
00183         }
00184         MenuWeb::CreateHeader();
00185 }
00186 
00187 
00188 void WolfshadeWeb::GenerateDocument()
00189 {
00190         SetMenuclass("menu");
00191 
00192         if (m_pic.size())
00193         {
00194                 Base64 bomb;
00195                 bomb.decode_to_stdout(m_pic);
00196                 return;
00197         }
00198         printf("<html>");
00199         printf("<head>");
00200         printf("<link rel=\"STYLESHEET\" href=\"/style/ws.css\" type=\"text/css\">");
00201         printf("</head>");
00202         printf("<body>");
00203 /*
00204         if (!m_start)
00205         {
00206                 m_form1.Display();
00207         }
00208         else
00209 */
00210         {
00211                 MenuWeb::GenerateDocument();
00212         }
00213         printf("</body>");
00214         printf("</html>");
00215 }
00216 
00217 
00218 void WolfshadeWeb::SetTheCookie()
00219 {
00220         char slask[200];
00221 
00222         sprintf(slask,"%ld:%ld:%ld:%ld:%ld:%ld:%ld",
00223                 m_start,m_antal,m_zone,m_race,m_class,m_objtype,m_material);
00224         SetCookie("ws",slask);
00225 }
00226 
00227 
00228 Database *WolfshadeWeb::GetDatabase()
00229 {
00230         return &m_db;
00231 }
00232 
00233 
00234 void WolfshadeWeb::DisplayStartAntalForm()
00235 {
00236         Query q(GetDatabase());
00237         {
00238                 Table tbl("#000000", 5);
00239 
00240 //              printf("<table cellpadding=5>");
00241                 printf("<form action=%s method=POST>",GetCgiName().c_str());
00242                 printf("<tr bgcolor=#ffffff>");
00243                 printf("<td valign=top>First<br><input type=text size=8 name=start value=\"%ld\"></td>",GetStart());
00244                 printf("<td valign=top>Qty<br><input type=text size=8 name=antal value=\"%ld\"></td>",GetAntal());
00245                 if (GetPage() == m_menuMob)
00246                 {
00247                         // race
00248                         printf("<td valign=top>Race<br><select name=xracex><option value=0>");
00249                         q.get_result("select * from race where num>0 order by alias");
00250                         while (q.fetch_row())
00251                         {
00252                                 db::Race x(GetDatabase(),&q);
00253                                 printf("<option value=%ld%s>%s",
00254                                         x.num,
00255                                         (x.num == m_race) ? " SELECTED" : "",
00256                                         x.alias);
00257                         }
00258                         q.free_result();
00259                         printf("</select>");
00260                         printf("</td>");
00261                         // class
00262                         printf("<td valign=top>Class<br><select name=xclassx><option value=0>");
00263                         q.get_result("select * from classes where num>0 order by alias");
00264                         while (q.fetch_row())
00265                         {
00266                                 db::Classes x(GetDatabase(),&q);
00267                                 printf("<option value=%ld%s>%s",
00268                                         x.num,
00269                                         (x.num == m_class) ? " SELECTED" : "",
00270                                         x.alias);
00271                         }
00272                         q.free_result();
00273                         printf("</select>");
00274                         printf("</td>");
00275                 }
00276                 else
00277                 if (GetPage() == m_menuObj)
00278                 {
00279                         printf("<td valign=top>Object Type<br><select name=xobjtypex><option value=0>");
00280                         q.get_result("select * from obj_type where num>0 order by name");
00281                         while (q.fetch_row())
00282                         {
00283                                 db::Obj_type x(GetDatabase(),&q);
00284                                 printf("<option value=%ld%s>%s",
00285                                         x.num,
00286                                         (x.num == m_objtype) ? " SELECTED" : "",
00287                                         x.name);
00288                         }
00289                         q.free_result();
00290                         printf("</select>");
00291                         printf("</td>");
00292                         // material
00293                         printf("<td valign=top>Material<br><select name=xmaterialx><option value=0>");
00294                         q.get_result("select * from obj_material where num>0 order by name");
00295                         while (q.fetch_row())
00296                         {
00297                                 db::Obj_material x(GetDatabase(),&q);
00298                                 printf("<option value=%ld%s>%s",
00299                                         x.num,
00300                                         (x.num == m_material) ? " SELECTED" : "",
00301                                         x.name);
00302                         }
00303                         q.free_result();
00304                         printf("</select>");
00305                         printf("</td>");
00306                 }
00307                 else
00308                 if (GetPage() == m_menuRoom)
00309                 {
00310                         printf("<td valign=top>Zone<br><select name=xzonex><option value=0>");
00311                         q.get_result("select * from zone order by name");
00312                         while (q.fetch_row())
00313                         {
00314                                 db::Zone x(GetDatabase(),&q);
00315                                 printf("<option value=%ld%s>%s",
00316                                         x.num,
00317                                         (x.num == m_zone) ? " SELECTED" : "",
00318                                         m_form1.nocolor(x.name));
00319                         }
00320                         q.free_result();
00321                         printf("</select>");
00322                         printf("</td>");
00323                 } // m_menuRoom
00324                 printf("<td valign=bottom><input type=submit name=submit value=\" Change \"></td>");
00325                 printf("</tr>");
00326                 printf("</form>");
00327 //              printf("</table>");
00328         }
00329         printf("<br>");
00330 }
00331 
00332 
00333 } // namespace cgi
00334 
00335 
00336 

Generated for Wolfshade by doxygen 1.3.6

Page, code, and content Copyright (C) 2004 by Anders Hedström