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 \
#include "script.h"
+#include "extern.h"
+#include <fstream>
+#include <string>
+
+using namespace std;
script::script()
{
{
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;
+}
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: