]> jfr.im git - irc/gameservirc.git/commitdiff
Wrote a loadScript function to take a script in from a file, and redid the dependencies
authorkainazzzo <redacted>
Mon, 26 Jun 2006 22:09:45 +0000 (22:09 +0000)
committerkainazzzo <redacted>
Mon, 26 Jun 2006 22:09:45 +0000 (22:09 +0000)
git-svn-id: https://svn.code.sf.net/p/gameservirc/code/trunk@453 bc333340-6410-0410-a689-9d09f3c113fa

gameserv/.depend
gameserv/script.cpp
gameserv/script.h

index 7a92b6087c68385d5b82831705cb4436279ac186..ed17a364c9ca8ccfa2a3f5c4af216595c3b58ad0 100644 (file)
@@ -18,6 +18,8 @@ pouch.o: pouch.cpp extern.h player.h level.h config.h options.h item.h \
  pouch.h
 player.o: player.cpp item.h level.h player.h pouch.h extern.h config.h \
  options.h flags.h
+script.o: script.cpp script.h extern.h player.h level.h config.h \
+ options.h item.h
 sockhelp.o: sockhelp.cpp sockhelp.h extern.h player.h level.h config.h \
  options.h item.h
 tcpclient.o: tcpclient.cpp sockhelp.h options.h aClient.h player.h \
index dcfed5525323bbaf5737fb1549b1271482845619..29f17f64c44336fb97339829368cca8eb9f5a5d6 100644 (file)
@@ -1,4 +1,9 @@
 #include "script.h"
+#include "extern.h"
+#include <fstream>
+#include <string>
+
+using namespace std;
 
 script::script()
 {
@@ -34,3 +39,39 @@ bool script::executeScript(Player *p)
 {
   return true;
 }
+
+bool script::loadScript(const char *filename)
+{
+  char *buffer;
+  int length;
+  ifstream infile;
+  bool result;
+
+  infile.open(filename, ios::binary);
+
+  if (infile.fail())
+       {
+         log("Error opening script %s", filename);
+         return false;
+       }
+
+  // get length of file:
+  infile.seekg (0, ios::end);
+  length = infile.tellg();
+  infile.seekg (0, ios::beg);
+
+  if (length > 0)
+       { 
+         buffer = new char[length];
+         infile.read(buffer, length);
+         scriptstr = buffer;
+         delete [] buffer;
+         result = true;
+       }
+  else
+       {
+         result = false;
+       }
+  infile.close();
+  return result;
+}
index 5925bbccdb49080edf280c13868b8fe49a77b2d6..57c87c39f3924178a1dca99f5713b30da7d1f958 100644 (file)
@@ -18,6 +18,7 @@ public:
   void setString(const char *str);
 
   bool executeScript(Player *p); // Run the script against a player
+  bool loadScript(const char *filename); // Load a script from a file - does not parse anything
   
   ~script(); // Destructor
 private: