]> jfr.im git - irc/gameservirc.git/commitdiff
Fixed a bunch of compilation warnings about deprecated const char *
authorkainazzzo <redacted>
Thu, 14 Aug 2008 17:42:56 +0000 (17:42 +0000)
committerkainazzzo <redacted>
Thu, 14 Aug 2008 17:42:56 +0000 (17:42 +0000)
    conversions - Kain

git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@505 bc333340-6410-0410-a689-9d09f3c113fa

12 files changed:
gameserv/Changes
gameserv/aClient.cpp
gameserv/aClient.h
gameserv/config.cpp
gameserv/do_store.cpp
gameserv/extern.h
gameserv/gameserv.cpp
gameserv/messages.cpp
gameserv/sockhelp.cpp
gameserv/sockhelp.h
gameserv/strings.cpp
gameserv/tcpclient.cpp

index 9d78b7dd0d9bce26953d5ed653d551753f6d0727..a8656ff2c0ce35fe704a777c7177acafe5862dfd 100644 (file)
@@ -1,4 +1,8 @@
 Version 1.3.5
+* Fixed a bunch of compilation warnings about deprecated const char *
+    conversions - Kain
+* Fixed a bug in the admin help file that would crash on /msg GameServ 
+    help admin - Kain (thanks for pointing it out, tsukasa)
 * Fixed a bunch of compilation bugs, which should have come up before - Kain
 * Fixed a bug on some redhat systems that would cause the masteritems.dat file
     not to load at all - Kain
index 9de597ff608f475be66fc9920a64a6241680be02..3566309337bfa601a1436d5147269dc4a26ca9bb 100644 (file)
@@ -4,15 +4,15 @@
 #include <stdlib.h>
 #include <stdio.h>
 
-aClient::aClient(char *n)
+aClient::aClient(const string &n)
 {
     #ifdef DEBUGMODE
-       log("aClient created: %s", (n[0] == '\0' ? "NULL" : n));
+       log("aClient created: %s", (n.empty() ? "NULL" : n.c_str()));
     #endif
-    strcpy(nick, n);
+    strcpy(nick, n.c_str());
 
     #ifdef P10
-       strcpy(realnick, n);
+       strcpy(realnick, n.c_str());
     #endif
 
     stats = NULL;
index 95b7b97163a939955283a2bafb7d55025f54dd0a..4a595805e8a4f28813431e1631c8bc92067dd3ad 100644 (file)
@@ -13,7 +13,7 @@ class aClient
   friend ostream &operator<<( ostream &output, const aClient &c);
   
 public:
-  aClient(char *);             // Constructor takes a char for the nick
+  aClient(const string &);             // Constructor takes a char for the nick
   
 #ifdef P10
   aClient(char *, char *);     // Constructor takes a char for the nick and realnick
index 306abbe31390ead6af8df8d5411b3fa1f5a330a5..24681ffbce619e6b722ba63ae689193e87f59618 100644 (file)
@@ -126,7 +126,7 @@ int load_config_file(char *config)
   
   struct DIRECTIVE {
        bool done;
-       char *desc;
+       string desc;
   };
   
   DIRECTIVE directives[numdirectives];
index 8a7eeda05402669513d4d65249db6f4c96cb00dc..d24202c2a9767db5f63e5b93b2487df816ef86c5 100644 (file)
@@ -12,7 +12,6 @@ void do_store(char *u)
   item *tempItem;
   char *cmd = strtok(NULL, " ");
   char *num = strtok(NULL, " ");
-  char *space;
   int id;
   aClient *user;
   Player *p;
@@ -64,7 +63,6 @@ void do_store(char *u)
             {
                          if ((*item_iterator)->getType() == WEAPON)
                                {
-                                 space = spaces(strlen((*item_iterator)->getName().c_str()), ".");
                                  notice(s_GameServ, u, "%s%ld. %20s..........%ld", 
               ((*item_iterator)->getID() < 10 ? " " : ""), 
               (*item_iterator)->getID(), (*item_iterator)->getName().c_str(), (*item_iterator)->price());
index 9b55dbf2aecbb78ad186473b2cc7530ff9aef31e..f871285ce18939d0d6c8323a0203cb121845c944 100644 (file)
@@ -89,8 +89,8 @@ E char *dragondata;
 E char *masterdata;
 E char *logfile;
 E char *adminpass;
-E char *VERSION;
-E char *PACKAGE;
+E const string VERSION;
+E const string PACKAGE;
 E char *welcomemsg;
 E char *ignoreserverslist;
 
@@ -131,7 +131,7 @@ E tavernItem *findTavernItemByID(int id);
 /* find.cpp end   */
 
 /* messages.cpp begin */
-E void display_help(char *u, char *file);
+E void display_help(const string &u, const string &file);
 E void display_monster(char *u);
 E void display_players(char *u);
 E void display_players(aClient *user);
@@ -240,7 +240,7 @@ E bool alphaNumeric(const char *str);
 E char *strtok(char *str, const char *delim);
 #endif
 
-E char *spaces(int len, char *seperator);
+E string spaces(int len, const string &seperator);
 
 E int stricmp(const char *s1, const char *s2);
 E int strnicmp(const char *s1, const char *s2, size_t len);
index 7a08220c92cd8f9d17a648a7fe598f90e4a7267e..642867722c2e12ccc9cd54b6aded692fe65b5b60 100644 (file)
@@ -72,7 +72,7 @@ void gameserv(char *source, char *buf)
     }
   else if (stricmp(cmd, "\1VERSION\1") == 0)
        {
-         notice(s_GameServ, source, "\1VERSION %s %s\1", PACKAGE, VERSION);
+         notice(s_GameServ, source, "\1VERSION %s %s\1", PACKAGE.c_str(), VERSION.c_str());
     }
   else if (stricmp(cmd, "SEARCH") == 0)
        {
index 1148e12c4d81cc862b0a90253a987ecef9921688..8a2cb34b467c65227861b761f5427faa086d8138 100644 (file)
@@ -132,7 +132,7 @@ void showstats(const char *u, const char *nick)
        Player *p;
     char *buf;
     buf = new char[50];
-    char *space;
+    string space;
 
 
     if (!(p = findplayer(nick)))
@@ -145,14 +145,14 @@ void showstats(const char *u, const char *nick)
                
         sprintf(buf, "Experience: %ld", p->getExp());
         space = spaces(strlen(buf), " ");
-        notice(s_GameServ, sender->getNick(), "%s%sLevel: %d",  buf, space,
+        notice(s_GameServ, sender->getNick(), "%s%sLevel: %d",  buf, space.c_str(),
                           p->getLevel());
-        delete [] space;
+        
                
         sprintf(buf, "Gold: %ld", p->getGold());
         space = spaces(strlen(buf), " ");
-        notice(s_GameServ, sender->getNick(), "%s%sGold in Bank: %ld", buf, space, p->getBank());
-        delete [] space;
+        notice(s_GameServ, sender->getNick(), "%s%sGold in Bank: %ld", buf, space.c_str(), p->getBank());
+        
                
         notice(s_GameServ, sender->getNick(), "Hit Points: %d of %d", p->getHP(),
                           p->getMaxHP());
@@ -160,21 +160,21 @@ void showstats(const char *u, const char *nick)
         sprintf(buf, "Strength: %d", p->getStrength());
         space = spaces(strlen(buf), " ");
         notice(s_GameServ, sender->getNick(), "%s%sDefense: %d",
-                          buf, space, p->getDefense());
-        delete [] space;
+                          buf, space.c_str(), p->getDefense());
+        
                
         sprintf(buf, "Armor: %s", (p->getArmor() ? p->getArmor()->getName().c_str() : "Nothing"));
         space = spaces(strlen(buf), " ");
                
-        notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space,
+        notice(s_GameServ, sender->getNick(), "%s%sWeapon: %s", buf, space.c_str(),
                           (p->getWeapon() ? p->getWeapon()->getName().c_str() : "Fists"));
                
-        delete [] space;
+        
                
         sprintf(buf, "Forest Fights: %d", p->getForestFights());
         space = spaces(strlen(buf), " ");
-        notice(s_GameServ, sender->getNick(), "%s%sPlayer Fights: %d", buf, space, p->getPlayerFights());
-        delete [] space;
+        notice(s_GameServ, sender->getNick(), "%s%sPlayer Fights: %d", buf, space.c_str(), p->getPlayerFights());
+        
                if (p->getClient() == sender || isAdmin(sender))
                  {
                        showinventory(p, sender);
@@ -319,18 +319,18 @@ void showBankBalance(const char *u)
   notice(s_GameServ, u, "Account Balance: %ld     Gold On hand: %ld", p->getBank(), p->getGold());
 }
 
-void display_help(char *u, char *file)
+void display_help(const string &u, const string &file)
 {
   ifstream infile;
   char *buf;
   
-  if (!file)
+  if (file.empty())
     {
          infile.open("helpfiles/help");
          if (infile.fail())
                {
                  log("Error opening helpfiles/help");
-                 notice(s_GameServ, u, "Error opening helpfiles/help");
+                 notice(s_GameServ, u.c_str(), "Error opening helpfiles/help");
                  return;
                }
          buf = new char[1024];
@@ -338,30 +338,28 @@ void display_help(char *u, char *file)
                {
                  // Written this way, it will process <S in the helpfiles
                  // Instead of notice(s_GameServ, u, "%s", buf);
-                 notice(s_GameServ, u, buf);
+                 notice(s_GameServ, u.c_str(), buf);
                }
          
          // Minor recursion - as long as admin_commands exists, it won't loop
           // continuously
-         aClient *user = find(u);
+         aClient *user = find(u.c_str());
          if (user && isAdmin(user))
-           display_help(u, "admin_commands");
+           display_help(u.c_str(), "admin_commands");
     }
   else
     {
-         char *filename;
-         filename = new char[strlen(file) + 11];
-         strcpy(filename, "helpfiles/");
-         strcat(filename, file);
+         string filename;
+      filename = "helpfiles/";
+      filename += file;
          
-         for (unsigned int x = 10; x < strlen(filename); x++)
+         for (unsigned int x = 10; x < filename.length(); x++)
            filename[x] = tolower(filename[x]);
          
-         infile.open(filename);
-         delete [] filename;
+         infile.open(filename.c_str());
          if (infile.fail())
                {
-                 notice(s_GameServ, u, "No help for \ 2%s\ 2", file);
+                 notice(s_GameServ, u.c_str(), "No help for \ 2%s\ 2", file.c_str());
                  return;
                }
          buf = new char[1024];
@@ -369,7 +367,7 @@ void display_help(char *u, char *file)
                {
                  // Written this way, it will process <S in the helpfiles
                  // Instead of notice(s_GameServ, u, "%s", buf);
-                 notice(s_GameServ, u, buf);
+                 notice(s_GameServ, u.c_str(), buf);
                }
     }
   infile.close();
index e6e25d270702c5579af3e4b1ecef4f2693e588fb..d1b863c50a01db6383093d466b9be3310efba149 100644 (file)
 the
    service name is not found, it tries it as a decimal number.  The number
    returned is byte ordered for the network. */
-int atoport(char *service, char *proto)
+int atoport(const string &service, const string &proto)
 {
   int port;
   long int lport;
   char *errpos;
 
-    lport = strtol(service,&errpos,0);
+    lport = strtol(service.c_str(),&errpos,0);
     if ( (errpos[0] != 0) || (lport < 1) || (lport > 65535) )
       return -1; /* Invalid port address */
 
index b7ec8a662dc5c5b7d14221acb798df80914762ba..64b89939ecfc27ad7c7e44ee20601451b0c32ee0 100644 (file)
 #include <netdb.h>
 #include <arpa/inet.h>
 
-int atoport( char *service, char *proto);
+#include <string>
+using std::string;
+
+int atoport(const string &service, const string &proto);
 struct in_addr *atoaddr(char *address);
 int get_connection(int socket_type, u_short port, int *listener);
 int make_connection(char *service, int type, char *netaddress);
index 9a4d3a370511bf02d589cd7b0667a62e4b7a35ff..651ee96160faca93a83bee7622076d4d6aaae0da 100755 (executable)
@@ -29,14 +29,15 @@ int stricmp(const char *s1, const char *s2)
 
 
 
-char *spaces(int len, char *seperator)
+string spaces(int len, const string &seperator)
 {
-    char *final;
-    final = new char[30];
+    string final;
     int y;
-    strcpy(final, seperator);
+    final += seperator;
+
     for (y = 0; y < 30 - len; y++)
-        strcat(final, seperator);
+        final += seperator;
+
     return final;
 }
 
index b6d417562d1b24d8a3def8dc7de84d0c59450714..bc0e9107d14fd2777f05732c4a9b150c5471f520 100644 (file)
@@ -34,8 +34,8 @@
 
 using namespace std;
 
-char *PACKAGE = "GameServ";
-char *VERSION = "1.3.4 +devel";
+const string PACKAGE = "GameServ";
+const string VERSION = "1.3.4 +devel";
 
 int sock;
 long lastrefresh;
@@ -109,6 +109,7 @@ int main(int argc, char *argv[])
          perror("Could not turn into a daemon");
          exit(3);
     }
+
   if (load_items() == 0)
     {
       log("Error loading items");
@@ -199,7 +200,7 @@ int main(int argc, char *argv[])
          raw("PASS :%s", remotepass);
          raw("SERVER %s 1 :%s", servername, servername);
          raw("NICK <S 1 %d %s %s %s %d :%s v%s", time(NULL), gsident, gshost, 
-                 servername, time(NULL), PACKAGE, VERSION);
+                 servername, time(NULL), PACKAGE.c_str(), VERSION.c_str());
          raw(":<S JOIN %s", c_Forest);
          raw(":<S MODE %s +tn", c_Forest);
 #elif defined(BAHAMUT)
@@ -390,7 +391,7 @@ int main(int argc, char *argv[])
                          char *server;
                          server = strtok(NULL, " ");
                          server++;
-                         raw(":%s 351 %s %s_%s. %s", servername, source+1, PACKAGE, VERSION, servername);
+                         raw(":%s 351 %s %s_%s. %s", servername, source+1, PACKAGE.c_str(), VERSION.c_str(), servername);
                        }
                  // Code indenting is clean up until here!
 #if !defined(P10)