Changed everyting to Unix line endings.
This commit is contained in:
parent
20e7221c7c
commit
53e22b1185
@ -1,8 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
||||
|
@ -1,33 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MCServer</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>MCServer</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
@ -1,4 +1,4 @@
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
|
@ -1,27 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mcserver"
|
||||
android:versionCode="3"
|
||||
android:versionName="r1375" >
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||
|
||||
<uses-sdk android:minSdkVersion="10" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:name=".MCServerActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.mcserver"
|
||||
android:versionCode="3"
|
||||
android:versionName="r1375" >
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||
|
||||
<uses-sdk android:minSdkVersion="10" />
|
||||
|
||||
<application
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name" >
|
||||
<activity
|
||||
android:name=".MCServerActivity"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,2 +1,2 @@
|
||||
Put all pre-packaged plugins in here such as Core.
|
||||
Put all pre-packaged plugins in here such as Core.
|
||||
The user will be able to install each plugin in here separately.
|
@ -1,10 +1,10 @@
|
||||
Put all pre-packaged settings/preferences and license files in here.
|
||||
Such as:
|
||||
|
||||
settings.example.ini
|
||||
groups.example.ini
|
||||
users.example.ini
|
||||
webadmin.example.ini
|
||||
Lua-LICENSE.txt
|
||||
MersenneTwister-LICENSE.txt
|
||||
Put all pre-packaged settings/preferences and license files in here.
|
||||
Such as:
|
||||
|
||||
settings.example.ini
|
||||
groups.example.ini
|
||||
users.example.ini
|
||||
webadmin.example.ini
|
||||
Lua-LICENSE.txt
|
||||
MersenneTwister-LICENSE.txt
|
||||
etc.etc
|
@ -1,39 +1,39 @@
|
||||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*
|
||||
* This class was automatically generated by the
|
||||
* aapt tool from the resource data it found. It
|
||||
* should not be modified by hand.
|
||||
*/
|
||||
|
||||
package com.mcserver;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int ic_launcher=0x7f020000;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int configure_server=0x7f050003;
|
||||
public static final int ip_address=0x7f050005;
|
||||
public static final int listView1=0x7f050006;
|
||||
public static final int server_status_text=0x7f050004;
|
||||
public static final int start_server=0x7f050002;
|
||||
public static final int stop_server=0x7f050001;
|
||||
public static final int textView2=0x7f050000;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int list_item=0x7f030000;
|
||||
public static final int main=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int app_name=0x7f040001;
|
||||
public static final int configure=0x7f040007;
|
||||
public static final int hello=0x7f040000;
|
||||
public static final int mcserver_is_not_running=0x7f040005;
|
||||
public static final int mcserver_is_running=0x7f040004;
|
||||
public static final int start=0x7f040002;
|
||||
public static final int stop=0x7f040003;
|
||||
public static final int your_ip=0x7f040006;
|
||||
}
|
||||
}
|
||||
/* AUTO-GENERATED FILE. DO NOT MODIFY.
|
||||
*
|
||||
* This class was automatically generated by the
|
||||
* aapt tool from the resource data it found. It
|
||||
* should not be modified by hand.
|
||||
*/
|
||||
|
||||
package com.mcserver;
|
||||
|
||||
public final class R {
|
||||
public static final class attr {
|
||||
}
|
||||
public static final class drawable {
|
||||
public static final int ic_launcher=0x7f020000;
|
||||
}
|
||||
public static final class id {
|
||||
public static final int configure_server=0x7f050003;
|
||||
public static final int ip_address=0x7f050005;
|
||||
public static final int listView1=0x7f050006;
|
||||
public static final int server_status_text=0x7f050004;
|
||||
public static final int start_server=0x7f050002;
|
||||
public static final int stop_server=0x7f050001;
|
||||
public static final int textView2=0x7f050000;
|
||||
}
|
||||
public static final class layout {
|
||||
public static final int list_item=0x7f030000;
|
||||
public static final int main=0x7f030001;
|
||||
}
|
||||
public static final class string {
|
||||
public static final int app_name=0x7f040001;
|
||||
public static final int configure=0x7f040007;
|
||||
public static final int hello=0x7f040000;
|
||||
public static final int mcserver_is_not_running=0x7f040005;
|
||||
public static final int mcserver_is_running=0x7f040004;
|
||||
public static final int start=0x7f040002;
|
||||
public static final int stop=0x7f040003;
|
||||
public static final int your_ip=0x7f040006;
|
||||
}
|
||||
}
|
||||
|
@ -1,46 +1,46 @@
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := mcserver
|
||||
|
||||
|
||||
|
||||
LOCAL_SRC_FILES := $(shell find ../CryptoPP ../lua-5.1.4 ../jsoncpp-src-0.5.0 ../zlib-1.2.7 ../source ../squirrel_3_0_1_stable ../tolua++-1.0.93 ../iniFile ../WebServer ../expat '(' -name '*.cpp' -o -name '*.c' ')')
|
||||
LOCAL_SRC_FILES := $(filter-out %SquirrelFunctions.cpp %SquirrelBindings.cpp %cPlugin_Squirrel.cpp %cSquirrelCommandBinder.cpp %minigzip.c %lua.c %tolua.c %toluabind.c %LeakFinder.cpp %StackWalker.cpp %example.c,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES := $(patsubst %.cpp,../%.cpp,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES := $(patsubst %.c,../%.c,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES += app-android.cpp ToJava.cpp
|
||||
|
||||
LOCAL_CFLAGS := -DANDROID_NDK \
|
||||
-O3 \
|
||||
-funroll-loops \
|
||||
-mfloat-abi=softfp -mfpu=neon \
|
||||
-fexceptions \
|
||||
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := cpufeatures
|
||||
|
||||
LOCAL_C_INCLUDES := ../source \
|
||||
../source/md5 \
|
||||
../WebServer \
|
||||
../source/packets \
|
||||
../source/items \
|
||||
../source/blocks \
|
||||
../tolua++-1.0.93/src/lib \
|
||||
../lua-5.1.4/src \
|
||||
../zlib-1.2.7 \
|
||||
../iniFile \
|
||||
../tolua++-1.0.93/include \
|
||||
../jsoncpp-src-0.5.0/include \
|
||||
../jsoncpp-src-0.5.0/src/lib_json \
|
||||
../squirrel_3_0_1_stable/include \
|
||||
../squirrel_3_0_1_stable \
|
||||
../squirrel_3_0_1_stable/sqrat \
|
||||
../expat/ \
|
||||
.. \
|
||||
|
||||
|
||||
LOCAL_LDLIBS := -ldl -llog
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
$(call import-module,cpufeatures)
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := mcserver
|
||||
|
||||
|
||||
|
||||
LOCAL_SRC_FILES := $(shell find ../CryptoPP ../lua-5.1.4 ../jsoncpp-src-0.5.0 ../zlib-1.2.7 ../source ../squirrel_3_0_1_stable ../tolua++-1.0.93 ../iniFile ../WebServer ../expat '(' -name '*.cpp' -o -name '*.c' ')')
|
||||
LOCAL_SRC_FILES := $(filter-out %SquirrelFunctions.cpp %SquirrelBindings.cpp %cPlugin_Squirrel.cpp %cSquirrelCommandBinder.cpp %minigzip.c %lua.c %tolua.c %toluabind.c %LeakFinder.cpp %StackWalker.cpp %example.c,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES := $(patsubst %.cpp,../%.cpp,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES := $(patsubst %.c,../%.c,$(LOCAL_SRC_FILES))
|
||||
LOCAL_SRC_FILES += app-android.cpp ToJava.cpp
|
||||
|
||||
LOCAL_CFLAGS := -DANDROID_NDK \
|
||||
-O3 \
|
||||
-funroll-loops \
|
||||
-mfloat-abi=softfp -mfpu=neon \
|
||||
-fexceptions \
|
||||
|
||||
|
||||
LOCAL_STATIC_LIBRARIES := cpufeatures
|
||||
|
||||
LOCAL_C_INCLUDES := ../source \
|
||||
../source/md5 \
|
||||
../WebServer \
|
||||
../source/packets \
|
||||
../source/items \
|
||||
../source/blocks \
|
||||
../tolua++-1.0.93/src/lib \
|
||||
../lua-5.1.4/src \
|
||||
../zlib-1.2.7 \
|
||||
../iniFile \
|
||||
../tolua++-1.0.93/include \
|
||||
../jsoncpp-src-0.5.0/include \
|
||||
../jsoncpp-src-0.5.0/src/lib_json \
|
||||
../squirrel_3_0_1_stable/include \
|
||||
../squirrel_3_0_1_stable \
|
||||
../squirrel_3_0_1_stable/sqrat \
|
||||
../expat/ \
|
||||
.. \
|
||||
|
||||
|
||||
LOCAL_LDLIBS := -ldl -llog
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
$(call import-module,cpufeatures)
|
||||
|
@ -1,3 +1,3 @@
|
||||
#include "Globals.h"
|
||||
|
||||
#include "Globals.h"
|
||||
|
||||
#include "ToJava.h"
|
@ -1,59 +1,59 @@
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
extern JNIEnv* g_CurrentJNIEnv;
|
||||
extern JavaVM* g_JavaVM;
|
||||
extern jobject g_JavaThread;
|
||||
//extern jobject g_JavaActivity;
|
||||
|
||||
//__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList);
|
||||
|
||||
static void CallJavaFunction_Void_String( jobject a_Object, const std::string & a_FunctionName, const std::string & a_StringParam )
|
||||
{
|
||||
JNIEnv * oldEnv = g_CurrentJNIEnv;
|
||||
int status = g_JavaVM->AttachCurrentThread(&g_CurrentJNIEnv, NULL);
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "STATUS: %i old: %p new: %p", status, oldEnv, g_CurrentJNIEnv );
|
||||
jstring str = g_CurrentJNIEnv->NewStringUTF( a_StringParam.c_str() );
|
||||
|
||||
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "JNIEnv: %i Object: %i", g_CurrentJNIEnv, a_Object );
|
||||
jclass cls = g_CurrentJNIEnv->GetObjectClass( a_Object );
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jclass: %i", cls );
|
||||
jmethodID mid = g_CurrentJNIEnv->GetMethodID( cls, a_FunctionName.c_str(), "(Ljava/lang/String;)V"); // void a_FunctionName( String )
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jmethodID: %i", mid );
|
||||
if (mid != 0)
|
||||
{
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "Going to call right NOW! %s", a_FunctionName.c_str() );
|
||||
g_CurrentJNIEnv->CallVoidMethod( a_Object, mid, str );
|
||||
}
|
||||
else
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "It was 0, derp" );
|
||||
}
|
||||
|
||||
if( oldEnv != g_CurrentJNIEnv )
|
||||
{
|
||||
g_JavaVM->DetachCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void CallJavaFunction_Void_Void( jobject a_Object, const std::string & a_FunctionName )
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "JNIEnv: %i Object: %i", g_CurrentJNIEnv, a_Object );
|
||||
jclass cls = g_CurrentJNIEnv->GetObjectClass( a_Object );
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jclass: %i", cls );
|
||||
jmethodID mid = g_CurrentJNIEnv->GetMethodID( cls, a_FunctionName.c_str(), "()V"); // void a_FunctionName( String )
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jmethodID: %i", mid );
|
||||
if (mid != 0)
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "Going to call right NOW! %s", a_FunctionName.c_str() );
|
||||
g_CurrentJNIEnv->CallVoidMethod( a_Object, mid );
|
||||
}
|
||||
else
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "It was 0, derp" );
|
||||
}
|
||||
#pragma once
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
extern JNIEnv* g_CurrentJNIEnv;
|
||||
extern JavaVM* g_JavaVM;
|
||||
extern jobject g_JavaThread;
|
||||
//extern jobject g_JavaActivity;
|
||||
|
||||
//__android_log_vprint(ANDROID_LOG_ERROR,"MCServer", a_Format, argList);
|
||||
|
||||
static void CallJavaFunction_Void_String( jobject a_Object, const std::string & a_FunctionName, const std::string & a_StringParam )
|
||||
{
|
||||
JNIEnv * oldEnv = g_CurrentJNIEnv;
|
||||
int status = g_JavaVM->AttachCurrentThread(&g_CurrentJNIEnv, NULL);
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "STATUS: %i old: %p new: %p", status, oldEnv, g_CurrentJNIEnv );
|
||||
jstring str = g_CurrentJNIEnv->NewStringUTF( a_StringParam.c_str() );
|
||||
|
||||
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "JNIEnv: %i Object: %i", g_CurrentJNIEnv, a_Object );
|
||||
jclass cls = g_CurrentJNIEnv->GetObjectClass( a_Object );
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jclass: %i", cls );
|
||||
jmethodID mid = g_CurrentJNIEnv->GetMethodID( cls, a_FunctionName.c_str(), "(Ljava/lang/String;)V"); // void a_FunctionName( String )
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jmethodID: %i", mid );
|
||||
if (mid != 0)
|
||||
{
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "Going to call right NOW! %s", a_FunctionName.c_str() );
|
||||
g_CurrentJNIEnv->CallVoidMethod( a_Object, mid, str );
|
||||
}
|
||||
else
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "It was 0, derp" );
|
||||
}
|
||||
|
||||
if( oldEnv != g_CurrentJNIEnv )
|
||||
{
|
||||
g_JavaVM->DetachCurrentThread();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void CallJavaFunction_Void_Void( jobject a_Object, const std::string & a_FunctionName )
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "JNIEnv: %i Object: %i", g_CurrentJNIEnv, a_Object );
|
||||
jclass cls = g_CurrentJNIEnv->GetObjectClass( a_Object );
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jclass: %i", cls );
|
||||
jmethodID mid = g_CurrentJNIEnv->GetMethodID( cls, a_FunctionName.c_str(), "()V"); // void a_FunctionName( String )
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "jmethodID: %i", mid );
|
||||
if (mid != 0)
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "Going to call right NOW! %s", a_FunctionName.c_str() );
|
||||
g_CurrentJNIEnv->CallVoidMethod( a_Object, mid );
|
||||
}
|
||||
else
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "It was 0, derp" );
|
||||
}
|
||||
}
|
@ -1,130 +1,130 @@
|
||||
#include "Globals.h"
|
||||
|
||||
#include <jni.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "OSSupport/CriticalSection.h"
|
||||
#include "OSSupport/MakeDir.h"
|
||||
#include "ToJava.h"
|
||||
|
||||
#include "Root.h"
|
||||
#include "WebAdmin.h"
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#ifdef _WIN32 // For IntelliSense parsing
|
||||
typedef void jobject;
|
||||
typedef int jint;
|
||||
typedef bool jboolean;
|
||||
typedef void JavaVM;
|
||||
typedef void JNIEnv;
|
||||
#endif
|
||||
|
||||
cCriticalSection g_CriticalSection;
|
||||
|
||||
JNIEnv* g_CurrentJNIEnv = 0;
|
||||
jobject g_JavaThread = 0;
|
||||
JavaVM* g_JavaVM = 0;
|
||||
//jobject g_JavaActivity = 0;
|
||||
|
||||
cRoot * pRoot = NULL;
|
||||
|
||||
|
||||
class cMainThread :
|
||||
public cIsThread
|
||||
{
|
||||
public:
|
||||
cMainThread() :
|
||||
cIsThread("cMainThread")
|
||||
{
|
||||
//Start();
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "cMainThread");
|
||||
}
|
||||
|
||||
void Stop(void)
|
||||
{
|
||||
m_ShouldTerminate = true;
|
||||
Wait();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Execute(void) override
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Execute");
|
||||
pRoot = new cRoot();
|
||||
pRoot->Start();
|
||||
delete pRoot;
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
cMainThread * pMainThread = NULL;
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "JNI_OnLoad JNI_OnLoad JNI_OnLoad JNI_OnLoad");
|
||||
g_JavaVM = vm;
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
/* Called when program/activity is created */
|
||||
extern "C" void Java_com_mcserver_MCServerActivity_NativeOnCreate( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
g_JavaThread = thiz;
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Logging from C++!");
|
||||
g_CriticalSection.Unlock();
|
||||
|
||||
mkdir("/sdcard/mcserver", S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
|
||||
pRoot = new cRoot();
|
||||
pRoot->Start();
|
||||
delete pRoot; pRoot = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" void Java_com_mcserver_MCServerActivity_NativeCleanUp( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
g_JavaThread = thiz;
|
||||
g_CriticalSection.Unlock();
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "pRoot: %p", pRoot);
|
||||
if( pRoot != NULL )
|
||||
{
|
||||
pRoot->ExecuteConsoleCommand("stop");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" jboolean Java_com_mcserver_MCServerActivity_NativeIsServerRunning( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
return pRoot != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" jint Java_com_mcserver_MCServerActivity_NativeGetWebAdminPort( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
if( pRoot != NULL && pRoot->GetWebAdmin() != NULL )
|
||||
{
|
||||
return pRoot->GetWebAdmin()->GetPort();
|
||||
}
|
||||
return 0;
|
||||
#include "Globals.h"
|
||||
|
||||
#include <jni.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include <float.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "OSSupport/CriticalSection.h"
|
||||
#include "OSSupport/MakeDir.h"
|
||||
#include "ToJava.h"
|
||||
|
||||
#include "Root.h"
|
||||
#include "WebAdmin.h"
|
||||
|
||||
#include <android/log.h>
|
||||
|
||||
#ifdef _WIN32 // For IntelliSense parsing
|
||||
typedef void jobject;
|
||||
typedef int jint;
|
||||
typedef bool jboolean;
|
||||
typedef void JavaVM;
|
||||
typedef void JNIEnv;
|
||||
#endif
|
||||
|
||||
cCriticalSection g_CriticalSection;
|
||||
|
||||
JNIEnv* g_CurrentJNIEnv = 0;
|
||||
jobject g_JavaThread = 0;
|
||||
JavaVM* g_JavaVM = 0;
|
||||
//jobject g_JavaActivity = 0;
|
||||
|
||||
cRoot * pRoot = NULL;
|
||||
|
||||
|
||||
class cMainThread :
|
||||
public cIsThread
|
||||
{
|
||||
public:
|
||||
cMainThread() :
|
||||
cIsThread("cMainThread")
|
||||
{
|
||||
//Start();
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "cMainThread");
|
||||
}
|
||||
|
||||
void Stop(void)
|
||||
{
|
||||
m_ShouldTerminate = true;
|
||||
Wait();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Execute(void) override
|
||||
{
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Execute");
|
||||
pRoot = new cRoot();
|
||||
pRoot->Start();
|
||||
delete pRoot;
|
||||
}
|
||||
|
||||
} ;
|
||||
|
||||
cMainThread * pMainThread = NULL;
|
||||
|
||||
jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||
{
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "JNI_OnLoad JNI_OnLoad JNI_OnLoad JNI_OnLoad");
|
||||
g_JavaVM = vm;
|
||||
return JNI_VERSION_1_4;
|
||||
}
|
||||
|
||||
/* Called when program/activity is created */
|
||||
extern "C" void Java_com_mcserver_MCServerActivity_NativeOnCreate( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
g_JavaThread = thiz;
|
||||
//__android_log_print(ANDROID_LOG_ERROR,"MCServer", "%s", "Logging from C++!");
|
||||
g_CriticalSection.Unlock();
|
||||
|
||||
mkdir("/sdcard/mcserver", S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
|
||||
pRoot = new cRoot();
|
||||
pRoot->Start();
|
||||
delete pRoot; pRoot = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" void Java_com_mcserver_MCServerActivity_NativeCleanUp( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
g_CriticalSection.Lock();
|
||||
g_CurrentJNIEnv = env;
|
||||
g_JavaThread = thiz;
|
||||
g_CriticalSection.Unlock();
|
||||
|
||||
__android_log_print(ANDROID_LOG_ERROR,"MCServer", "pRoot: %p", pRoot);
|
||||
if( pRoot != NULL )
|
||||
{
|
||||
pRoot->ExecuteConsoleCommand("stop");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" jboolean Java_com_mcserver_MCServerActivity_NativeIsServerRunning( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
return pRoot != NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
extern "C" jint Java_com_mcserver_MCServerActivity_NativeGetWebAdminPort( JNIEnv* env, jobject thiz )
|
||||
{
|
||||
if( pRoot != NULL && pRoot->GetWebAdmin() != NULL )
|
||||
{
|
||||
return pRoot->GetWebAdmin()->GetPort();
|
||||
}
|
||||
return 0;
|
||||
}
|
@ -1,61 +1,61 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical" >
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center_horizontal"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
<Button
|
||||
android:id="@+id/stop_server"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:enabled="true"
|
||||
android:text="@string/stop" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/start_server"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/start" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/stop_server"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:enabled="true"
|
||||
android:text="@string/stop" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/start_server"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/start" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/configure_server"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/configure" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/server_status_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/mcserver_is_not_running"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ip_address"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/your_ip" />
|
||||
<ListView
|
||||
android:id="@+id/listView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
</ListView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/configure_server"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/configure" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/server_status_text"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/mcserver_is_not_running"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/ip_address"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/your_ip" />
|
||||
<ListView
|
||||
android:id="@+id/listView1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
</ListView>
|
||||
|
||||
</LinearLayout>
|
@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="hello">Hello World, MCServerActivity!</string>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="hello">Hello World, MCServerActivity!</string>
|
||||
<string name="app_name">MCServer</string>
|
||||
<string name="start">Start</string>
|
||||
<string name="stop">Stop</string>
|
||||
<string name="mcserver_is_running">MCServer is running</string>
|
||||
<string name="mcserver_is_not_running">MCServer is not running</string>
|
||||
<string name="your_ip">Your IP …</string>
|
||||
<string name="configure">Configure</string>
|
||||
|
||||
<string name="your_ip">Your IP …</string>
|
||||
<string name="configure">Configure</string>
|
||||
|
||||
</resources>
|
@ -1,432 +1,432 @@
|
||||
package com.mcserver;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
public class MCServerInstaller {
|
||||
private MCServerActivity mContext;
|
||||
final private String BaseDirectory = "basedir";
|
||||
final private String PluginDirectory = "Plugins";
|
||||
|
||||
final public String SHARED_PREFS_NAME = "MCSERVER_PREFS";
|
||||
final public String PREF_IS_INSTALLED = "IS_INSTALLED";
|
||||
final public String PREF_LAST_VERSION = "LAST_VERSION";
|
||||
private SharedPreferences mSettings = null;
|
||||
|
||||
int thisVersion;
|
||||
|
||||
MCServerInstaller( MCServerActivity activity )
|
||||
{
|
||||
mContext = activity;
|
||||
|
||||
mSettings = mContext.getSharedPreferences( SHARED_PREFS_NAME, 0);
|
||||
|
||||
try {
|
||||
this.thisVersion = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode;
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.e("MCServer", "Could not read version code from manifest!");
|
||||
e.printStackTrace();
|
||||
this.thisVersion = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean IsInstalled()
|
||||
{
|
||||
return mSettings.getBoolean(PREF_IS_INSTALLED, false);
|
||||
}
|
||||
|
||||
|
||||
public boolean NeedsUpdate()
|
||||
{
|
||||
Log.i("MCServer", "thisVersion: " + this.thisVersion + " pref: " + mSettings.getInt(PREF_LAST_VERSION, 0));
|
||||
return mSettings.getInt(PREF_LAST_VERSION, 0) != this.thisVersion;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<String> FindFoldersInPath(String path)
|
||||
{
|
||||
ArrayList<String> allFolders = new ArrayList<String>();
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] allPlugins = am.list(path);
|
||||
for(String pluginName : allPlugins)
|
||||
{
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(path + "/" + pluginName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
// It seems to be a folder :D
|
||||
allFolders.add(pluginName);
|
||||
continue;
|
||||
}
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return allFolders;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void ExpandAssets( String path )
|
||||
{
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] getAssets = am.list(path);
|
||||
for(String assetName : getAssets)
|
||||
{
|
||||
//Log.e("MCServer", path + "/" + imgName);
|
||||
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(path + "/" + assetName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
//Log.e("MCServer", "Could not open" + path + "/" + imgName );
|
||||
ExpandAssets(path + "/" + assetName);
|
||||
continue;
|
||||
}
|
||||
|
||||
String outPath = Environment.getExternalStorageDirectory().getPath() + "/mcserver/" + path + "/" + assetName;
|
||||
//Log.e("MCServer", "outPath: " + outPath );
|
||||
File f = new File( outPath );
|
||||
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
OutputStream ostr = new FileOutputStream(f);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = istr.read(buffer))>0)
|
||||
{
|
||||
ostr.write(buffer, 0, length);
|
||||
}
|
||||
ostr.flush();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ShowFirstRunDialog()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
//builder.setTitle("blaa");
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setMessage("It seems this is the first time you are running MCServer on your Android device or it has been updated! This app comes with a couple of pre-packaged plugins, please take a moment to select the plugins you would like to install.");
|
||||
builder.setCancelable(false);
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
|
||||
dialog.setOnDismissListener( new DialogInterface.OnDismissListener(){
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
ShowPluginInstallDialog(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void ShowPluginInstallDialog(boolean bCancelable)
|
||||
{
|
||||
final ArrayList<String> allPlugins = FindFoldersInPath( BaseDirectory + "/" + PluginDirectory );
|
||||
final CharSequence[] items = allPlugins.toArray(new CharSequence[allPlugins.size()]);
|
||||
final boolean[] selected = new boolean[items.length];
|
||||
for( int i = 0; i < items.length; ++i )
|
||||
{
|
||||
if( items[i].toString().contains("Core") )
|
||||
{ // Select the core plugin by default
|
||||
selected[i] = true;
|
||||
items[i] = items[i] + " (Recommended)";
|
||||
}
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
builder.setTitle("Plugins to install");
|
||||
builder.setCancelable(bCancelable);
|
||||
builder.setMultiChoiceItems(items, selected, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
selected[which] = isChecked;
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("Install", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ArrayList<String> toInstall = new ArrayList<String>();
|
||||
for( int i = 0; i < selected.length; ++i )
|
||||
{
|
||||
if( selected[i] )
|
||||
{
|
||||
toInstall.add(allPlugins.get(i));
|
||||
}
|
||||
}
|
||||
InstallPlugins(toInstall);
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog dialog2 = builder.create();
|
||||
dialog2.show();
|
||||
}
|
||||
|
||||
|
||||
void InstallPlugins( final ArrayList<String> plugins )
|
||||
{
|
||||
new AsyncTask<Void, Integer, Boolean>()
|
||||
{
|
||||
ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute()
|
||||
{
|
||||
/*
|
||||
* This is executed on UI thread before doInBackground(). It is
|
||||
* the perfect place to show the progress dialog.
|
||||
*/
|
||||
progressDialog = ProgressDialog.show(mContext, "", "Installing...");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params)
|
||||
{
|
||||
if (params == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
/*
|
||||
* This is run on a background thread, so we can sleep here
|
||||
* or do whatever we want without blocking UI thread. A more
|
||||
* advanced use would download chunks of fixed size and call
|
||||
* publishProgress();
|
||||
*/
|
||||
for( int i = 0; i < plugins.size(); ++i )
|
||||
{
|
||||
this.publishProgress((int)(i / (float)plugins.size() * 100), i);
|
||||
InstallSinglePlugin(PluginDirectory + "/" + plugins.get(i));
|
||||
}
|
||||
|
||||
this.publishProgress( 100, -1 );
|
||||
InstallExampleSettings();
|
||||
|
||||
this.publishProgress( 100, -2 );
|
||||
InstallWebAdmin();
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.e("tag", e.getMessage());
|
||||
/*
|
||||
* The task failed
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* The task succeeded
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void onProgressUpdate(Integer... progress)
|
||||
{
|
||||
progressDialog.setProgress(progress[0]);
|
||||
if( progress[1] > -1 )
|
||||
{
|
||||
progressDialog.setMessage("Installing " + plugins.get(progress[1]) + "..." );
|
||||
}
|
||||
else if( progress[1] == -1 )
|
||||
{
|
||||
progressDialog.setMessage("Installing default settings...");
|
||||
}
|
||||
else if( progress[1] == -2 )
|
||||
{
|
||||
progressDialog.setMessage("Installing WebAdmin...");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result)
|
||||
{
|
||||
progressDialog.dismiss();
|
||||
/*
|
||||
* Update here your view objects with content from download. It
|
||||
* is save to dismiss dialogs, update views, etc., since we are
|
||||
* working on UI thread.
|
||||
*/
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(mContext);
|
||||
b.setTitle(android.R.string.dialog_alert_title);
|
||||
if (result)
|
||||
{
|
||||
b.setMessage("Install succeeded");
|
||||
|
||||
SharedPreferences.Editor editor = mSettings.edit();
|
||||
editor.putBoolean(PREF_IS_INSTALLED, true);
|
||||
editor.putInt(PREF_LAST_VERSION, thisVersion);
|
||||
editor.commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
b.setMessage("Install failed");
|
||||
}
|
||||
b.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
b.create().show();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
|
||||
void InstallExampleSettings()
|
||||
{
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] allFiles = am.list(BaseDirectory);
|
||||
for(String fileName : allFiles)
|
||||
{
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(BaseDirectory + "/" + fileName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
// Must be a folder :D
|
||||
continue;
|
||||
}
|
||||
|
||||
String outPath = Environment.getExternalStorageDirectory().getPath() + "/mcserver/" + fileName;
|
||||
Log.i("MCServer", "outPath: " + outPath );
|
||||
File f = new File( outPath );
|
||||
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
OutputStream ostr = new FileOutputStream(f);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = istr.read(buffer))>0)
|
||||
{
|
||||
ostr.write(buffer, 0, length);
|
||||
}
|
||||
ostr.flush();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InstallWebAdmin()
|
||||
{
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] allFiles = am.list(BaseDirectory + "/webadmin");
|
||||
for(String fileName : allFiles)
|
||||
{
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(BaseDirectory + "/webadmin/" + fileName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
// Must be a folder :D
|
||||
continue;
|
||||
}
|
||||
|
||||
String outPath = Environment.getExternalStorageDirectory().getPath() + "/mcserver/webadmin/" + fileName;
|
||||
Log.i("MCServer", "outPath: " + outPath );
|
||||
File f = new File( outPath );
|
||||
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
OutputStream ostr = new FileOutputStream(f);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = istr.read(buffer))>0)
|
||||
{
|
||||
ostr.write(buffer, 0, length);
|
||||
}
|
||||
ostr.flush();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InstallSinglePlugin( String path )
|
||||
{
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] getImages = am.list(BaseDirectory + "/" + path);
|
||||
for(String imgName : getImages)
|
||||
{
|
||||
Log.i("MCServer", path + "/" + imgName);
|
||||
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(BaseDirectory + "/" + path + "/" + imgName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
Log.i("MCServer", "Could not open" + path + "/" + imgName );
|
||||
InstallSinglePlugin(path + "/" + imgName);
|
||||
continue;
|
||||
}
|
||||
|
||||
String outPath = Environment.getExternalStorageDirectory().getPath() + "/mcserver/" + path + "/" + imgName;
|
||||
Log.i("MCServer", "outPath: " + outPath );
|
||||
File f = new File( outPath );
|
||||
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
OutputStream ostr = new FileOutputStream(f);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = istr.read(buffer))>0)
|
||||
{
|
||||
ostr.write(buffer, 0, length);
|
||||
}
|
||||
ostr.flush();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
package com.mcserver;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.AssetManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Environment;
|
||||
import android.util.Log;
|
||||
|
||||
public class MCServerInstaller {
|
||||
private MCServerActivity mContext;
|
||||
final private String BaseDirectory = "basedir";
|
||||
final private String PluginDirectory = "Plugins";
|
||||
|
||||
final public String SHARED_PREFS_NAME = "MCSERVER_PREFS";
|
||||
final public String PREF_IS_INSTALLED = "IS_INSTALLED";
|
||||
final public String PREF_LAST_VERSION = "LAST_VERSION";
|
||||
private SharedPreferences mSettings = null;
|
||||
|
||||
int thisVersion;
|
||||
|
||||
MCServerInstaller( MCServerActivity activity )
|
||||
{
|
||||
mContext = activity;
|
||||
|
||||
mSettings = mContext.getSharedPreferences( SHARED_PREFS_NAME, 0);
|
||||
|
||||
try {
|
||||
this.thisVersion = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0).versionCode;
|
||||
} catch (NameNotFoundException e) {
|
||||
Log.e("MCServer", "Could not read version code from manifest!");
|
||||
e.printStackTrace();
|
||||
this.thisVersion = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public boolean IsInstalled()
|
||||
{
|
||||
return mSettings.getBoolean(PREF_IS_INSTALLED, false);
|
||||
}
|
||||
|
||||
|
||||
public boolean NeedsUpdate()
|
||||
{
|
||||
Log.i("MCServer", "thisVersion: " + this.thisVersion + " pref: " + mSettings.getInt(PREF_LAST_VERSION, 0));
|
||||
return mSettings.getInt(PREF_LAST_VERSION, 0) != this.thisVersion;
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<String> FindFoldersInPath(String path)
|
||||
{
|
||||
ArrayList<String> allFolders = new ArrayList<String>();
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] allPlugins = am.list(path);
|
||||
for(String pluginName : allPlugins)
|
||||
{
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(path + "/" + pluginName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
// It seems to be a folder :D
|
||||
allFolders.add(pluginName);
|
||||
continue;
|
||||
}
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return allFolders;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void ExpandAssets( String path )
|
||||
{
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] getAssets = am.list(path);
|
||||
for(String assetName : getAssets)
|
||||
{
|
||||
//Log.e("MCServer", path + "/" + imgName);
|
||||
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(path + "/" + assetName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
//Log.e("MCServer", "Could not open" + path + "/" + imgName );
|
||||
ExpandAssets(path + "/" + assetName);
|
||||
continue;
|
||||
}
|
||||
|
||||
String outPath = Environment.getExternalStorageDirectory().getPath() + "/mcserver/" + path + "/" + assetName;
|
||||
//Log.e("MCServer", "outPath: " + outPath );
|
||||
File f = new File( outPath );
|
||||
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
OutputStream ostr = new FileOutputStream(f);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = istr.read(buffer))>0)
|
||||
{
|
||||
ostr.write(buffer, 0, length);
|
||||
}
|
||||
ostr.flush();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ShowFirstRunDialog()
|
||||
{
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
//builder.setTitle("blaa");
|
||||
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setMessage("It seems this is the first time you are running MCServer on your Android device or it has been updated! This app comes with a couple of pre-packaged plugins, please take a moment to select the plugins you would like to install.");
|
||||
builder.setCancelable(false);
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
|
||||
dialog.setOnDismissListener( new DialogInterface.OnDismissListener(){
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
ShowPluginInstallDialog(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void ShowPluginInstallDialog(boolean bCancelable)
|
||||
{
|
||||
final ArrayList<String> allPlugins = FindFoldersInPath( BaseDirectory + "/" + PluginDirectory );
|
||||
final CharSequence[] items = allPlugins.toArray(new CharSequence[allPlugins.size()]);
|
||||
final boolean[] selected = new boolean[items.length];
|
||||
for( int i = 0; i < items.length; ++i )
|
||||
{
|
||||
if( items[i].toString().contains("Core") )
|
||||
{ // Select the core plugin by default
|
||||
selected[i] = true;
|
||||
items[i] = items[i] + " (Recommended)";
|
||||
}
|
||||
}
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
|
||||
builder.setTitle("Plugins to install");
|
||||
builder.setCancelable(bCancelable);
|
||||
builder.setMultiChoiceItems(items, selected, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
selected[which] = isChecked;
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("Install", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
ArrayList<String> toInstall = new ArrayList<String>();
|
||||
for( int i = 0; i < selected.length; ++i )
|
||||
{
|
||||
if( selected[i] )
|
||||
{
|
||||
toInstall.add(allPlugins.get(i));
|
||||
}
|
||||
}
|
||||
InstallPlugins(toInstall);
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog dialog2 = builder.create();
|
||||
dialog2.show();
|
||||
}
|
||||
|
||||
|
||||
void InstallPlugins( final ArrayList<String> plugins )
|
||||
{
|
||||
new AsyncTask<Void, Integer, Boolean>()
|
||||
{
|
||||
ProgressDialog progressDialog;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute()
|
||||
{
|
||||
/*
|
||||
* This is executed on UI thread before doInBackground(). It is
|
||||
* the perfect place to show the progress dialog.
|
||||
*/
|
||||
progressDialog = ProgressDialog.show(mContext, "", "Installing...");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params)
|
||||
{
|
||||
if (params == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
/*
|
||||
* This is run on a background thread, so we can sleep here
|
||||
* or do whatever we want without blocking UI thread. A more
|
||||
* advanced use would download chunks of fixed size and call
|
||||
* publishProgress();
|
||||
*/
|
||||
for( int i = 0; i < plugins.size(); ++i )
|
||||
{
|
||||
this.publishProgress((int)(i / (float)plugins.size() * 100), i);
|
||||
InstallSinglePlugin(PluginDirectory + "/" + plugins.get(i));
|
||||
}
|
||||
|
||||
this.publishProgress( 100, -1 );
|
||||
InstallExampleSettings();
|
||||
|
||||
this.publishProgress( 100, -2 );
|
||||
InstallWebAdmin();
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.e("tag", e.getMessage());
|
||||
/*
|
||||
* The task failed
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* The task succeeded
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void onProgressUpdate(Integer... progress)
|
||||
{
|
||||
progressDialog.setProgress(progress[0]);
|
||||
if( progress[1] > -1 )
|
||||
{
|
||||
progressDialog.setMessage("Installing " + plugins.get(progress[1]) + "..." );
|
||||
}
|
||||
else if( progress[1] == -1 )
|
||||
{
|
||||
progressDialog.setMessage("Installing default settings...");
|
||||
}
|
||||
else if( progress[1] == -2 )
|
||||
{
|
||||
progressDialog.setMessage("Installing WebAdmin...");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean result)
|
||||
{
|
||||
progressDialog.dismiss();
|
||||
/*
|
||||
* Update here your view objects with content from download. It
|
||||
* is save to dismiss dialogs, update views, etc., since we are
|
||||
* working on UI thread.
|
||||
*/
|
||||
AlertDialog.Builder b = new AlertDialog.Builder(mContext);
|
||||
b.setTitle(android.R.string.dialog_alert_title);
|
||||
if (result)
|
||||
{
|
||||
b.setMessage("Install succeeded");
|
||||
|
||||
SharedPreferences.Editor editor = mSettings.edit();
|
||||
editor.putBoolean(PREF_IS_INSTALLED, true);
|
||||
editor.putInt(PREF_LAST_VERSION, thisVersion);
|
||||
editor.commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
b.setMessage("Install failed");
|
||||
}
|
||||
b.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
b.create().show();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
|
||||
void InstallExampleSettings()
|
||||
{
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] allFiles = am.list(BaseDirectory);
|
||||
for(String fileName : allFiles)
|
||||
{
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(BaseDirectory + "/" + fileName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
// Must be a folder :D
|
||||
continue;
|
||||
}
|
||||
|
||||
String outPath = Environment.getExternalStorageDirectory().getPath() + "/mcserver/" + fileName;
|
||||
Log.i("MCServer", "outPath: " + outPath );
|
||||
File f = new File( outPath );
|
||||
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
OutputStream ostr = new FileOutputStream(f);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = istr.read(buffer))>0)
|
||||
{
|
||||
ostr.write(buffer, 0, length);
|
||||
}
|
||||
ostr.flush();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InstallWebAdmin()
|
||||
{
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] allFiles = am.list(BaseDirectory + "/webadmin");
|
||||
for(String fileName : allFiles)
|
||||
{
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(BaseDirectory + "/webadmin/" + fileName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
// Must be a folder :D
|
||||
continue;
|
||||
}
|
||||
|
||||
String outPath = Environment.getExternalStorageDirectory().getPath() + "/mcserver/webadmin/" + fileName;
|
||||
Log.i("MCServer", "outPath: " + outPath );
|
||||
File f = new File( outPath );
|
||||
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
OutputStream ostr = new FileOutputStream(f);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = istr.read(buffer))>0)
|
||||
{
|
||||
ostr.write(buffer, 0, length);
|
||||
}
|
||||
ostr.flush();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void InstallSinglePlugin( String path )
|
||||
{
|
||||
AssetManager am = mContext.getAssets();
|
||||
try {
|
||||
String[] getImages = am.list(BaseDirectory + "/" + path);
|
||||
for(String imgName : getImages)
|
||||
{
|
||||
Log.i("MCServer", path + "/" + imgName);
|
||||
|
||||
InputStream istr = null;
|
||||
try
|
||||
{
|
||||
istr = am.open(BaseDirectory + "/" + path + "/" + imgName);
|
||||
} catch( java.io.FileNotFoundException e ) {
|
||||
Log.i("MCServer", "Could not open" + path + "/" + imgName );
|
||||
InstallSinglePlugin(path + "/" + imgName);
|
||||
continue;
|
||||
}
|
||||
|
||||
String outPath = Environment.getExternalStorageDirectory().getPath() + "/mcserver/" + path + "/" + imgName;
|
||||
Log.i("MCServer", "outPath: " + outPath );
|
||||
File f = new File( outPath );
|
||||
|
||||
f.getParentFile().mkdirs();
|
||||
f.createNewFile();
|
||||
OutputStream ostr = new FileOutputStream(f);
|
||||
|
||||
byte[] buffer = new byte[1024];
|
||||
int length;
|
||||
while ((length = istr.read(buffer))>0)
|
||||
{
|
||||
ostr.write(buffer, 0, length);
|
||||
}
|
||||
ostr.flush();
|
||||
ostr.close();
|
||||
istr.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,180 +1,180 @@
|
||||
// authenc.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#ifndef CRYPTOPP_IMPORTS
|
||||
|
||||
#include "authenc.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::AuthenticateData(const byte *input, size_t len)
|
||||
{
|
||||
unsigned int blockSize = AuthenticationBlockSize();
|
||||
unsigned int &num = m_bufferedDataLength;
|
||||
byte* data = m_buffer.begin();
|
||||
|
||||
if (num != 0) // process left over data
|
||||
{
|
||||
if (num+len >= blockSize)
|
||||
{
|
||||
memcpy(data+num, input, blockSize-num);
|
||||
AuthenticateBlocks(data, blockSize);
|
||||
input += (blockSize-num);
|
||||
len -= (blockSize-num);
|
||||
num = 0;
|
||||
// drop through and do the rest
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(data+num, input, len);
|
||||
num += (unsigned int)len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// now process the input data in blocks of blockSize bytes and save the leftovers to m_data
|
||||
if (len >= blockSize)
|
||||
{
|
||||
size_t leftOver = AuthenticateBlocks(input, len);
|
||||
input += (len - leftOver);
|
||||
len = leftOver;
|
||||
}
|
||||
|
||||
memcpy(data, input, len);
|
||||
num = (unsigned int)len;
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
|
||||
{
|
||||
m_bufferedDataLength = 0;
|
||||
m_state = State_Start;
|
||||
|
||||
SetKeyWithoutResync(userKey, keylength, params);
|
||||
m_state = State_KeySet;
|
||||
|
||||
size_t length;
|
||||
const byte *iv = GetIVAndThrowIfInvalid(params, length);
|
||||
if (iv)
|
||||
Resynchronize(iv, (int)length);
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::Resynchronize(const byte *iv, int length)
|
||||
{
|
||||
if (m_state < State_KeySet)
|
||||
throw BadState(AlgorithmName(), "Resynchronize", "key is set");
|
||||
|
||||
m_bufferedDataLength = 0;
|
||||
m_totalHeaderLength = m_totalMessageLength = m_totalFooterLength = 0;
|
||||
m_state = State_KeySet;
|
||||
|
||||
Resync(iv, this->ThrowIfInvalidIVLength(length));
|
||||
m_state = State_IVSet;
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::Update(const byte *input, size_t length)
|
||||
{
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
case State_Start:
|
||||
case State_KeySet:
|
||||
throw BadState(AlgorithmName(), "Update", "setting key and IV");
|
||||
case State_IVSet:
|
||||
AuthenticateData(input, length);
|
||||
m_totalHeaderLength += length;
|
||||
break;
|
||||
case State_AuthUntransformed:
|
||||
case State_AuthTransformed:
|
||||
AuthenticateLastConfidentialBlock();
|
||||
m_bufferedDataLength = 0;
|
||||
m_state = State_AuthFooter;
|
||||
// fall through
|
||||
case State_AuthFooter:
|
||||
AuthenticateData(input, length);
|
||||
m_totalFooterLength += length;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::ProcessData(byte *outString, const byte *inString, size_t length)
|
||||
{
|
||||
m_totalMessageLength += length;
|
||||
if (m_state >= State_IVSet && m_totalMessageLength > MaxMessageLength())
|
||||
throw InvalidArgument(AlgorithmName() + ": message length exceeds maximum");
|
||||
|
||||
reswitch:
|
||||
switch (m_state)
|
||||
{
|
||||
case State_Start:
|
||||
case State_KeySet:
|
||||
throw BadState(AlgorithmName(), "ProcessData", "setting key and IV");
|
||||
case State_AuthFooter:
|
||||
throw BadState(AlgorithmName(), "ProcessData was called after footer input has started");
|
||||
case State_IVSet:
|
||||
AuthenticateLastHeaderBlock();
|
||||
m_bufferedDataLength = 0;
|
||||
m_state = AuthenticationIsOnPlaintext()==IsForwardTransformation() ? State_AuthUntransformed : State_AuthTransformed;
|
||||
goto reswitch;
|
||||
case State_AuthUntransformed:
|
||||
AuthenticateData(inString, length);
|
||||
AccessSymmetricCipher().ProcessData(outString, inString, length);
|
||||
break;
|
||||
case State_AuthTransformed:
|
||||
AccessSymmetricCipher().ProcessData(outString, inString, length);
|
||||
AuthenticateData(outString, length);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::TruncatedFinal(byte *mac, size_t macSize)
|
||||
{
|
||||
if (m_totalHeaderLength > MaxHeaderLength())
|
||||
throw InvalidArgument(AlgorithmName() + ": header length of " + IntToString(m_totalHeaderLength) + " exceeds the maximum of " + IntToString(MaxHeaderLength()));
|
||||
|
||||
if (m_totalFooterLength > MaxFooterLength())
|
||||
{
|
||||
if (MaxFooterLength() == 0)
|
||||
throw InvalidArgument(AlgorithmName() + ": additional authenticated data (AAD) cannot be input after data to be encrypted or decrypted");
|
||||
else
|
||||
throw InvalidArgument(AlgorithmName() + ": footer length of " + IntToString(m_totalFooterLength) + " exceeds the maximum of " + IntToString(MaxFooterLength()));
|
||||
}
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
case State_Start:
|
||||
case State_KeySet:
|
||||
throw BadState(AlgorithmName(), "TruncatedFinal", "setting key and IV");
|
||||
|
||||
case State_IVSet:
|
||||
AuthenticateLastHeaderBlock();
|
||||
m_bufferedDataLength = 0;
|
||||
// fall through
|
||||
|
||||
case State_AuthUntransformed:
|
||||
case State_AuthTransformed:
|
||||
AuthenticateLastConfidentialBlock();
|
||||
m_bufferedDataLength = 0;
|
||||
// fall through
|
||||
|
||||
case State_AuthFooter:
|
||||
AuthenticateLastFooterBlock(mac, macSize);
|
||||
m_bufferedDataLength = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
m_state = State_KeySet;
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
// authenc.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#ifndef CRYPTOPP_IMPORTS
|
||||
|
||||
#include "authenc.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::AuthenticateData(const byte *input, size_t len)
|
||||
{
|
||||
unsigned int blockSize = AuthenticationBlockSize();
|
||||
unsigned int &num = m_bufferedDataLength;
|
||||
byte* data = m_buffer.begin();
|
||||
|
||||
if (num != 0) // process left over data
|
||||
{
|
||||
if (num+len >= blockSize)
|
||||
{
|
||||
memcpy(data+num, input, blockSize-num);
|
||||
AuthenticateBlocks(data, blockSize);
|
||||
input += (blockSize-num);
|
||||
len -= (blockSize-num);
|
||||
num = 0;
|
||||
// drop through and do the rest
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(data+num, input, len);
|
||||
num += (unsigned int)len;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// now process the input data in blocks of blockSize bytes and save the leftovers to m_data
|
||||
if (len >= blockSize)
|
||||
{
|
||||
size_t leftOver = AuthenticateBlocks(input, len);
|
||||
input += (len - leftOver);
|
||||
len = leftOver;
|
||||
}
|
||||
|
||||
memcpy(data, input, len);
|
||||
num = (unsigned int)len;
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
|
||||
{
|
||||
m_bufferedDataLength = 0;
|
||||
m_state = State_Start;
|
||||
|
||||
SetKeyWithoutResync(userKey, keylength, params);
|
||||
m_state = State_KeySet;
|
||||
|
||||
size_t length;
|
||||
const byte *iv = GetIVAndThrowIfInvalid(params, length);
|
||||
if (iv)
|
||||
Resynchronize(iv, (int)length);
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::Resynchronize(const byte *iv, int length)
|
||||
{
|
||||
if (m_state < State_KeySet)
|
||||
throw BadState(AlgorithmName(), "Resynchronize", "key is set");
|
||||
|
||||
m_bufferedDataLength = 0;
|
||||
m_totalHeaderLength = m_totalMessageLength = m_totalFooterLength = 0;
|
||||
m_state = State_KeySet;
|
||||
|
||||
Resync(iv, this->ThrowIfInvalidIVLength(length));
|
||||
m_state = State_IVSet;
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::Update(const byte *input, size_t length)
|
||||
{
|
||||
if (length == 0)
|
||||
return;
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
case State_Start:
|
||||
case State_KeySet:
|
||||
throw BadState(AlgorithmName(), "Update", "setting key and IV");
|
||||
case State_IVSet:
|
||||
AuthenticateData(input, length);
|
||||
m_totalHeaderLength += length;
|
||||
break;
|
||||
case State_AuthUntransformed:
|
||||
case State_AuthTransformed:
|
||||
AuthenticateLastConfidentialBlock();
|
||||
m_bufferedDataLength = 0;
|
||||
m_state = State_AuthFooter;
|
||||
// fall through
|
||||
case State_AuthFooter:
|
||||
AuthenticateData(input, length);
|
||||
m_totalFooterLength += length;
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::ProcessData(byte *outString, const byte *inString, size_t length)
|
||||
{
|
||||
m_totalMessageLength += length;
|
||||
if (m_state >= State_IVSet && m_totalMessageLength > MaxMessageLength())
|
||||
throw InvalidArgument(AlgorithmName() + ": message length exceeds maximum");
|
||||
|
||||
reswitch:
|
||||
switch (m_state)
|
||||
{
|
||||
case State_Start:
|
||||
case State_KeySet:
|
||||
throw BadState(AlgorithmName(), "ProcessData", "setting key and IV");
|
||||
case State_AuthFooter:
|
||||
throw BadState(AlgorithmName(), "ProcessData was called after footer input has started");
|
||||
case State_IVSet:
|
||||
AuthenticateLastHeaderBlock();
|
||||
m_bufferedDataLength = 0;
|
||||
m_state = AuthenticationIsOnPlaintext()==IsForwardTransformation() ? State_AuthUntransformed : State_AuthTransformed;
|
||||
goto reswitch;
|
||||
case State_AuthUntransformed:
|
||||
AuthenticateData(inString, length);
|
||||
AccessSymmetricCipher().ProcessData(outString, inString, length);
|
||||
break;
|
||||
case State_AuthTransformed:
|
||||
AccessSymmetricCipher().ProcessData(outString, inString, length);
|
||||
AuthenticateData(outString, length);
|
||||
break;
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
void AuthenticatedSymmetricCipherBase::TruncatedFinal(byte *mac, size_t macSize)
|
||||
{
|
||||
if (m_totalHeaderLength > MaxHeaderLength())
|
||||
throw InvalidArgument(AlgorithmName() + ": header length of " + IntToString(m_totalHeaderLength) + " exceeds the maximum of " + IntToString(MaxHeaderLength()));
|
||||
|
||||
if (m_totalFooterLength > MaxFooterLength())
|
||||
{
|
||||
if (MaxFooterLength() == 0)
|
||||
throw InvalidArgument(AlgorithmName() + ": additional authenticated data (AAD) cannot be input after data to be encrypted or decrypted");
|
||||
else
|
||||
throw InvalidArgument(AlgorithmName() + ": footer length of " + IntToString(m_totalFooterLength) + " exceeds the maximum of " + IntToString(MaxFooterLength()));
|
||||
}
|
||||
|
||||
switch (m_state)
|
||||
{
|
||||
case State_Start:
|
||||
case State_KeySet:
|
||||
throw BadState(AlgorithmName(), "TruncatedFinal", "setting key and IV");
|
||||
|
||||
case State_IVSet:
|
||||
AuthenticateLastHeaderBlock();
|
||||
m_bufferedDataLength = 0;
|
||||
// fall through
|
||||
|
||||
case State_AuthUntransformed:
|
||||
case State_AuthTransformed:
|
||||
AuthenticateLastConfidentialBlock();
|
||||
m_bufferedDataLength = 0;
|
||||
// fall through
|
||||
|
||||
case State_AuthFooter:
|
||||
AuthenticateLastFooterBlock(mac, macSize);
|
||||
m_bufferedDataLength = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
m_state = State_KeySet;
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
@ -1,49 +1,49 @@
|
||||
#ifndef CRYPTOPP_AUTHENC_H
|
||||
#define CRYPTOPP_AUTHENC_H
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include "secblock.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! .
|
||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher
|
||||
{
|
||||
public:
|
||||
AuthenticatedSymmetricCipherBase() : m_state(State_Start) {}
|
||||
|
||||
bool IsRandomAccess() const {return false;}
|
||||
bool IsSelfInverting() const {return true;}
|
||||
void UncheckedSetKey(const byte *,unsigned int,const CryptoPP::NameValuePairs &) {assert(false);}
|
||||
|
||||
void SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
|
||||
void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}
|
||||
void Resynchronize(const byte *iv, int length=-1);
|
||||
void Update(const byte *input, size_t length);
|
||||
void ProcessData(byte *outString, const byte *inString, size_t length);
|
||||
void TruncatedFinal(byte *mac, size_t macSize);
|
||||
|
||||
protected:
|
||||
void AuthenticateData(const byte *data, size_t len);
|
||||
const SymmetricCipher & GetSymmetricCipher() const {return const_cast<AuthenticatedSymmetricCipherBase *>(this)->AccessSymmetricCipher();};
|
||||
|
||||
virtual SymmetricCipher & AccessSymmetricCipher() =0;
|
||||
virtual bool AuthenticationIsOnPlaintext() const =0;
|
||||
virtual unsigned int AuthenticationBlockSize() const =0;
|
||||
virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) =0;
|
||||
virtual void Resync(const byte *iv, size_t len) =0;
|
||||
virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
|
||||
virtual void AuthenticateLastHeaderBlock() =0;
|
||||
virtual void AuthenticateLastConfidentialBlock() {}
|
||||
virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
|
||||
|
||||
enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
|
||||
State m_state;
|
||||
unsigned int m_bufferedDataLength;
|
||||
lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
|
||||
AlignedSecByteBlock m_buffer;
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
#ifndef CRYPTOPP_AUTHENC_H
|
||||
#define CRYPTOPP_AUTHENC_H
|
||||
|
||||
#include "cryptlib.h"
|
||||
#include "secblock.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! .
|
||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE AuthenticatedSymmetricCipherBase : public AuthenticatedSymmetricCipher
|
||||
{
|
||||
public:
|
||||
AuthenticatedSymmetricCipherBase() : m_state(State_Start) {}
|
||||
|
||||
bool IsRandomAccess() const {return false;}
|
||||
bool IsSelfInverting() const {return true;}
|
||||
void UncheckedSetKey(const byte *,unsigned int,const CryptoPP::NameValuePairs &) {assert(false);}
|
||||
|
||||
void SetKey(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
|
||||
void Restart() {if (m_state > State_KeySet) m_state = State_KeySet;}
|
||||
void Resynchronize(const byte *iv, int length=-1);
|
||||
void Update(const byte *input, size_t length);
|
||||
void ProcessData(byte *outString, const byte *inString, size_t length);
|
||||
void TruncatedFinal(byte *mac, size_t macSize);
|
||||
|
||||
protected:
|
||||
void AuthenticateData(const byte *data, size_t len);
|
||||
const SymmetricCipher & GetSymmetricCipher() const {return const_cast<AuthenticatedSymmetricCipherBase *>(this)->AccessSymmetricCipher();};
|
||||
|
||||
virtual SymmetricCipher & AccessSymmetricCipher() =0;
|
||||
virtual bool AuthenticationIsOnPlaintext() const =0;
|
||||
virtual unsigned int AuthenticationBlockSize() const =0;
|
||||
virtual void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms) =0;
|
||||
virtual void Resync(const byte *iv, size_t len) =0;
|
||||
virtual size_t AuthenticateBlocks(const byte *data, size_t len) =0;
|
||||
virtual void AuthenticateLastHeaderBlock() =0;
|
||||
virtual void AuthenticateLastConfidentialBlock() {}
|
||||
virtual void AuthenticateLastFooterBlock(byte *mac, size_t macSize) =0;
|
||||
|
||||
enum State {State_Start, State_KeySet, State_IVSet, State_AuthUntransformed, State_AuthTransformed, State_AuthFooter};
|
||||
State m_state;
|
||||
unsigned int m_bufferedDataLength;
|
||||
lword m_totalHeaderLength, m_totalMessageLength, m_totalFooterLength;
|
||||
AlignedSecByteBlock m_buffer;
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
280
CryptoPP/ccm.cpp
280
CryptoPP/ccm.cpp
@ -1,140 +1,140 @@
|
||||
// ccm.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#ifndef CRYPTOPP_IMPORTS
|
||||
|
||||
#include "ccm.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
void CCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
|
||||
{
|
||||
BlockCipher &blockCipher = AccessBlockCipher();
|
||||
|
||||
blockCipher.SetKey(userKey, keylength, params);
|
||||
|
||||
if (blockCipher.BlockSize() != REQUIRED_BLOCKSIZE)
|
||||
throw InvalidArgument(AlgorithmName() + ": block size of underlying block cipher is not 16");
|
||||
|
||||
m_digestSize = params.GetIntValueWithDefault(Name::DigestSize(), DefaultDigestSize());
|
||||
if (m_digestSize % 2 > 0 || m_digestSize < 4 || m_digestSize > 16)
|
||||
throw InvalidArgument(AlgorithmName() + ": DigestSize must be 4, 6, 8, 10, 12, 14, or 16");
|
||||
|
||||
m_buffer.Grow(2*REQUIRED_BLOCKSIZE);
|
||||
m_L = 8;
|
||||
}
|
||||
|
||||
void CCM_Base::Resync(const byte *iv, size_t len)
|
||||
{
|
||||
BlockCipher &cipher = AccessBlockCipher();
|
||||
|
||||
m_L = REQUIRED_BLOCKSIZE-1-(int)len;
|
||||
assert(m_L >= 2);
|
||||
if (m_L > 8)
|
||||
m_L = 8;
|
||||
|
||||
m_buffer[0] = byte(m_L-1); // flag
|
||||
memcpy(m_buffer+1, iv, len);
|
||||
memset(m_buffer+1+len, 0, REQUIRED_BLOCKSIZE-1-len);
|
||||
|
||||
if (m_state >= State_IVSet)
|
||||
m_ctr.Resynchronize(m_buffer, REQUIRED_BLOCKSIZE);
|
||||
else
|
||||
m_ctr.SetCipherWithIV(cipher, m_buffer);
|
||||
|
||||
m_ctr.Seek(REQUIRED_BLOCKSIZE);
|
||||
m_aadLength = 0;
|
||||
m_messageLength = 0;
|
||||
}
|
||||
|
||||
void CCM_Base::UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
|
||||
{
|
||||
if (m_state != State_IVSet)
|
||||
throw BadState(AlgorithmName(), "SpecifyDataLengths", "or after State_IVSet");
|
||||
|
||||
m_aadLength = headerLength;
|
||||
m_messageLength = messageLength;
|
||||
|
||||
byte *cbcBuffer = CBC_Buffer();
|
||||
const BlockCipher &cipher = GetBlockCipher();
|
||||
|
||||
cbcBuffer[0] = byte(64*(headerLength>0) + 8*((m_digestSize-2)/2) + (m_L-1)); // flag
|
||||
PutWord<word64>(true, BIG_ENDIAN_ORDER, cbcBuffer+REQUIRED_BLOCKSIZE-8, m_messageLength);
|
||||
memcpy(cbcBuffer+1, m_buffer+1, REQUIRED_BLOCKSIZE-1-m_L);
|
||||
cipher.ProcessBlock(cbcBuffer);
|
||||
|
||||
if (headerLength>0)
|
||||
{
|
||||
assert(m_bufferedDataLength == 0);
|
||||
|
||||
if (headerLength < ((1<<16) - (1<<8)))
|
||||
{
|
||||
PutWord<word16>(true, BIG_ENDIAN_ORDER, m_buffer, (word16)headerLength);
|
||||
m_bufferedDataLength = 2;
|
||||
}
|
||||
else if (headerLength < (W64LIT(1)<<32))
|
||||
{
|
||||
m_buffer[0] = 0xff;
|
||||
m_buffer[1] = 0xfe;
|
||||
PutWord<word32>(false, BIG_ENDIAN_ORDER, m_buffer+2, (word32)headerLength);
|
||||
m_bufferedDataLength = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buffer[0] = 0xff;
|
||||
m_buffer[1] = 0xff;
|
||||
PutWord<word64>(false, BIG_ENDIAN_ORDER, m_buffer+2, headerLength);
|
||||
m_bufferedDataLength = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t CCM_Base::AuthenticateBlocks(const byte *data, size_t len)
|
||||
{
|
||||
byte *cbcBuffer = CBC_Buffer();
|
||||
const BlockCipher &cipher = GetBlockCipher();
|
||||
return cipher.AdvancedProcessBlocks(cbcBuffer, data, cbcBuffer, len, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
|
||||
}
|
||||
|
||||
void CCM_Base::AuthenticateLastHeaderBlock()
|
||||
{
|
||||
byte *cbcBuffer = CBC_Buffer();
|
||||
const BlockCipher &cipher = GetBlockCipher();
|
||||
|
||||
if (m_aadLength != m_totalHeaderLength)
|
||||
throw InvalidArgument(AlgorithmName() + ": header length doesn't match that given in SpecifyDataLengths");
|
||||
|
||||
if (m_bufferedDataLength > 0)
|
||||
{
|
||||
xorbuf(cbcBuffer, m_buffer, m_bufferedDataLength);
|
||||
cipher.ProcessBlock(cbcBuffer);
|
||||
m_bufferedDataLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CCM_Base::AuthenticateLastConfidentialBlock()
|
||||
{
|
||||
byte *cbcBuffer = CBC_Buffer();
|
||||
const BlockCipher &cipher = GetBlockCipher();
|
||||
|
||||
if (m_messageLength != m_totalMessageLength)
|
||||
throw InvalidArgument(AlgorithmName() + ": message length doesn't match that given in SpecifyDataLengths");
|
||||
|
||||
if (m_bufferedDataLength > 0)
|
||||
{
|
||||
xorbuf(cbcBuffer, m_buffer, m_bufferedDataLength);
|
||||
cipher.ProcessBlock(cbcBuffer);
|
||||
m_bufferedDataLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CCM_Base::AuthenticateLastFooterBlock(byte *mac, size_t macSize)
|
||||
{
|
||||
m_ctr.Seek(0);
|
||||
m_ctr.ProcessData(mac, CBC_Buffer(), macSize);
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
// ccm.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#ifndef CRYPTOPP_IMPORTS
|
||||
|
||||
#include "ccm.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
void CCM_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
|
||||
{
|
||||
BlockCipher &blockCipher = AccessBlockCipher();
|
||||
|
||||
blockCipher.SetKey(userKey, keylength, params);
|
||||
|
||||
if (blockCipher.BlockSize() != REQUIRED_BLOCKSIZE)
|
||||
throw InvalidArgument(AlgorithmName() + ": block size of underlying block cipher is not 16");
|
||||
|
||||
m_digestSize = params.GetIntValueWithDefault(Name::DigestSize(), DefaultDigestSize());
|
||||
if (m_digestSize % 2 > 0 || m_digestSize < 4 || m_digestSize > 16)
|
||||
throw InvalidArgument(AlgorithmName() + ": DigestSize must be 4, 6, 8, 10, 12, 14, or 16");
|
||||
|
||||
m_buffer.Grow(2*REQUIRED_BLOCKSIZE);
|
||||
m_L = 8;
|
||||
}
|
||||
|
||||
void CCM_Base::Resync(const byte *iv, size_t len)
|
||||
{
|
||||
BlockCipher &cipher = AccessBlockCipher();
|
||||
|
||||
m_L = REQUIRED_BLOCKSIZE-1-(int)len;
|
||||
assert(m_L >= 2);
|
||||
if (m_L > 8)
|
||||
m_L = 8;
|
||||
|
||||
m_buffer[0] = byte(m_L-1); // flag
|
||||
memcpy(m_buffer+1, iv, len);
|
||||
memset(m_buffer+1+len, 0, REQUIRED_BLOCKSIZE-1-len);
|
||||
|
||||
if (m_state >= State_IVSet)
|
||||
m_ctr.Resynchronize(m_buffer, REQUIRED_BLOCKSIZE);
|
||||
else
|
||||
m_ctr.SetCipherWithIV(cipher, m_buffer);
|
||||
|
||||
m_ctr.Seek(REQUIRED_BLOCKSIZE);
|
||||
m_aadLength = 0;
|
||||
m_messageLength = 0;
|
||||
}
|
||||
|
||||
void CCM_Base::UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength)
|
||||
{
|
||||
if (m_state != State_IVSet)
|
||||
throw BadState(AlgorithmName(), "SpecifyDataLengths", "or after State_IVSet");
|
||||
|
||||
m_aadLength = headerLength;
|
||||
m_messageLength = messageLength;
|
||||
|
||||
byte *cbcBuffer = CBC_Buffer();
|
||||
const BlockCipher &cipher = GetBlockCipher();
|
||||
|
||||
cbcBuffer[0] = byte(64*(headerLength>0) + 8*((m_digestSize-2)/2) + (m_L-1)); // flag
|
||||
PutWord<word64>(true, BIG_ENDIAN_ORDER, cbcBuffer+REQUIRED_BLOCKSIZE-8, m_messageLength);
|
||||
memcpy(cbcBuffer+1, m_buffer+1, REQUIRED_BLOCKSIZE-1-m_L);
|
||||
cipher.ProcessBlock(cbcBuffer);
|
||||
|
||||
if (headerLength>0)
|
||||
{
|
||||
assert(m_bufferedDataLength == 0);
|
||||
|
||||
if (headerLength < ((1<<16) - (1<<8)))
|
||||
{
|
||||
PutWord<word16>(true, BIG_ENDIAN_ORDER, m_buffer, (word16)headerLength);
|
||||
m_bufferedDataLength = 2;
|
||||
}
|
||||
else if (headerLength < (W64LIT(1)<<32))
|
||||
{
|
||||
m_buffer[0] = 0xff;
|
||||
m_buffer[1] = 0xfe;
|
||||
PutWord<word32>(false, BIG_ENDIAN_ORDER, m_buffer+2, (word32)headerLength);
|
||||
m_bufferedDataLength = 6;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_buffer[0] = 0xff;
|
||||
m_buffer[1] = 0xff;
|
||||
PutWord<word64>(false, BIG_ENDIAN_ORDER, m_buffer+2, headerLength);
|
||||
m_bufferedDataLength = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t CCM_Base::AuthenticateBlocks(const byte *data, size_t len)
|
||||
{
|
||||
byte *cbcBuffer = CBC_Buffer();
|
||||
const BlockCipher &cipher = GetBlockCipher();
|
||||
return cipher.AdvancedProcessBlocks(cbcBuffer, data, cbcBuffer, len, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
|
||||
}
|
||||
|
||||
void CCM_Base::AuthenticateLastHeaderBlock()
|
||||
{
|
||||
byte *cbcBuffer = CBC_Buffer();
|
||||
const BlockCipher &cipher = GetBlockCipher();
|
||||
|
||||
if (m_aadLength != m_totalHeaderLength)
|
||||
throw InvalidArgument(AlgorithmName() + ": header length doesn't match that given in SpecifyDataLengths");
|
||||
|
||||
if (m_bufferedDataLength > 0)
|
||||
{
|
||||
xorbuf(cbcBuffer, m_buffer, m_bufferedDataLength);
|
||||
cipher.ProcessBlock(cbcBuffer);
|
||||
m_bufferedDataLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CCM_Base::AuthenticateLastConfidentialBlock()
|
||||
{
|
||||
byte *cbcBuffer = CBC_Buffer();
|
||||
const BlockCipher &cipher = GetBlockCipher();
|
||||
|
||||
if (m_messageLength != m_totalMessageLength)
|
||||
throw InvalidArgument(AlgorithmName() + ": message length doesn't match that given in SpecifyDataLengths");
|
||||
|
||||
if (m_bufferedDataLength > 0)
|
||||
{
|
||||
xorbuf(cbcBuffer, m_buffer, m_bufferedDataLength);
|
||||
cipher.ProcessBlock(cbcBuffer);
|
||||
m_bufferedDataLength = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CCM_Base::AuthenticateLastFooterBlock(byte *mac, size_t macSize)
|
||||
{
|
||||
m_ctr.Seek(0);
|
||||
m_ctr.ProcessData(mac, CBC_Buffer(), macSize);
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
202
CryptoPP/ccm.h
202
CryptoPP/ccm.h
@ -1,101 +1,101 @@
|
||||
#ifndef CRYPTOPP_CCM_H
|
||||
#define CRYPTOPP_CCM_H
|
||||
|
||||
#include "authenc.h"
|
||||
#include "modes.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! .
|
||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CCM_Base : public AuthenticatedSymmetricCipherBase
|
||||
{
|
||||
public:
|
||||
CCM_Base()
|
||||
: m_digestSize(0), m_L(0) {}
|
||||
|
||||
// AuthenticatedSymmetricCipher
|
||||
std::string AlgorithmName() const
|
||||
{return GetBlockCipher().AlgorithmName() + std::string("/CCM");}
|
||||
size_t MinKeyLength() const
|
||||
{return GetBlockCipher().MinKeyLength();}
|
||||
size_t MaxKeyLength() const
|
||||
{return GetBlockCipher().MaxKeyLength();}
|
||||
size_t DefaultKeyLength() const
|
||||
{return GetBlockCipher().DefaultKeyLength();}
|
||||
size_t GetValidKeyLength(size_t n) const
|
||||
{return GetBlockCipher().GetValidKeyLength(n);}
|
||||
bool IsValidKeyLength(size_t n) const
|
||||
{return GetBlockCipher().IsValidKeyLength(n);}
|
||||
unsigned int OptimalDataAlignment() const
|
||||
{return GetBlockCipher().OptimalDataAlignment();}
|
||||
IV_Requirement IVRequirement() const
|
||||
{return UNIQUE_IV;}
|
||||
unsigned int IVSize() const
|
||||
{return 8;}
|
||||
unsigned int MinIVLength() const
|
||||
{return 7;}
|
||||
unsigned int MaxIVLength() const
|
||||
{return 13;}
|
||||
unsigned int DigestSize() const
|
||||
{return m_digestSize;}
|
||||
lword MaxHeaderLength() const
|
||||
{return W64LIT(0)-1;}
|
||||
lword MaxMessageLength() const
|
||||
{return m_L<8 ? (W64LIT(1)<<(8*m_L))-1 : W64LIT(0)-1;}
|
||||
bool NeedsPrespecifiedDataLengths() const
|
||||
{return true;}
|
||||
void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength);
|
||||
|
||||
protected:
|
||||
// AuthenticatedSymmetricCipherBase
|
||||
bool AuthenticationIsOnPlaintext() const
|
||||
{return true;}
|
||||
unsigned int AuthenticationBlockSize() const
|
||||
{return GetBlockCipher().BlockSize();}
|
||||
void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
|
||||
void Resync(const byte *iv, size_t len);
|
||||
size_t AuthenticateBlocks(const byte *data, size_t len);
|
||||
void AuthenticateLastHeaderBlock();
|
||||
void AuthenticateLastConfidentialBlock();
|
||||
void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
|
||||
SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
|
||||
|
||||
virtual BlockCipher & AccessBlockCipher() =0;
|
||||
virtual int DefaultDigestSize() const =0;
|
||||
|
||||
const BlockCipher & GetBlockCipher() const {return const_cast<CCM_Base *>(this)->AccessBlockCipher();};
|
||||
byte *CBC_Buffer() {return m_buffer+REQUIRED_BLOCKSIZE;}
|
||||
|
||||
enum {REQUIRED_BLOCKSIZE = 16};
|
||||
int m_digestSize, m_L;
|
||||
word64 m_messageLength, m_aadLength;
|
||||
CTR_Mode_ExternalCipher::Encryption m_ctr;
|
||||
};
|
||||
|
||||
//! .
|
||||
template <class T_BlockCipher, int T_DefaultDigestSize, bool T_IsEncryption>
|
||||
class CCM_Final : public CCM_Base
|
||||
{
|
||||
public:
|
||||
static std::string StaticAlgorithmName()
|
||||
{return T_BlockCipher::StaticAlgorithmName() + std::string("/CCM");}
|
||||
bool IsForwardTransformation() const
|
||||
{return T_IsEncryption;}
|
||||
|
||||
private:
|
||||
BlockCipher & AccessBlockCipher() {return m_cipher;}
|
||||
int DefaultDigestSize() const {return T_DefaultDigestSize;}
|
||||
typename T_BlockCipher::Encryption m_cipher;
|
||||
};
|
||||
|
||||
/// <a href="http://www.cryptolounge.org/wiki/CCM">CCM</a>
|
||||
template <class T_BlockCipher, int T_DefaultDigestSize = 16>
|
||||
struct CCM : public AuthenticatedSymmetricCipherDocumentation
|
||||
{
|
||||
typedef CCM_Final<T_BlockCipher, T_DefaultDigestSize, true> Encryption;
|
||||
typedef CCM_Final<T_BlockCipher, T_DefaultDigestSize, false> Decryption;
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
#ifndef CRYPTOPP_CCM_H
|
||||
#define CRYPTOPP_CCM_H
|
||||
|
||||
#include "authenc.h"
|
||||
#include "modes.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! .
|
||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CCM_Base : public AuthenticatedSymmetricCipherBase
|
||||
{
|
||||
public:
|
||||
CCM_Base()
|
||||
: m_digestSize(0), m_L(0) {}
|
||||
|
||||
// AuthenticatedSymmetricCipher
|
||||
std::string AlgorithmName() const
|
||||
{return GetBlockCipher().AlgorithmName() + std::string("/CCM");}
|
||||
size_t MinKeyLength() const
|
||||
{return GetBlockCipher().MinKeyLength();}
|
||||
size_t MaxKeyLength() const
|
||||
{return GetBlockCipher().MaxKeyLength();}
|
||||
size_t DefaultKeyLength() const
|
||||
{return GetBlockCipher().DefaultKeyLength();}
|
||||
size_t GetValidKeyLength(size_t n) const
|
||||
{return GetBlockCipher().GetValidKeyLength(n);}
|
||||
bool IsValidKeyLength(size_t n) const
|
||||
{return GetBlockCipher().IsValidKeyLength(n);}
|
||||
unsigned int OptimalDataAlignment() const
|
||||
{return GetBlockCipher().OptimalDataAlignment();}
|
||||
IV_Requirement IVRequirement() const
|
||||
{return UNIQUE_IV;}
|
||||
unsigned int IVSize() const
|
||||
{return 8;}
|
||||
unsigned int MinIVLength() const
|
||||
{return 7;}
|
||||
unsigned int MaxIVLength() const
|
||||
{return 13;}
|
||||
unsigned int DigestSize() const
|
||||
{return m_digestSize;}
|
||||
lword MaxHeaderLength() const
|
||||
{return W64LIT(0)-1;}
|
||||
lword MaxMessageLength() const
|
||||
{return m_L<8 ? (W64LIT(1)<<(8*m_L))-1 : W64LIT(0)-1;}
|
||||
bool NeedsPrespecifiedDataLengths() const
|
||||
{return true;}
|
||||
void UncheckedSpecifyDataLengths(lword headerLength, lword messageLength, lword footerLength);
|
||||
|
||||
protected:
|
||||
// AuthenticatedSymmetricCipherBase
|
||||
bool AuthenticationIsOnPlaintext() const
|
||||
{return true;}
|
||||
unsigned int AuthenticationBlockSize() const
|
||||
{return GetBlockCipher().BlockSize();}
|
||||
void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
|
||||
void Resync(const byte *iv, size_t len);
|
||||
size_t AuthenticateBlocks(const byte *data, size_t len);
|
||||
void AuthenticateLastHeaderBlock();
|
||||
void AuthenticateLastConfidentialBlock();
|
||||
void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
|
||||
SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
|
||||
|
||||
virtual BlockCipher & AccessBlockCipher() =0;
|
||||
virtual int DefaultDigestSize() const =0;
|
||||
|
||||
const BlockCipher & GetBlockCipher() const {return const_cast<CCM_Base *>(this)->AccessBlockCipher();};
|
||||
byte *CBC_Buffer() {return m_buffer+REQUIRED_BLOCKSIZE;}
|
||||
|
||||
enum {REQUIRED_BLOCKSIZE = 16};
|
||||
int m_digestSize, m_L;
|
||||
word64 m_messageLength, m_aadLength;
|
||||
CTR_Mode_ExternalCipher::Encryption m_ctr;
|
||||
};
|
||||
|
||||
//! .
|
||||
template <class T_BlockCipher, int T_DefaultDigestSize, bool T_IsEncryption>
|
||||
class CCM_Final : public CCM_Base
|
||||
{
|
||||
public:
|
||||
static std::string StaticAlgorithmName()
|
||||
{return T_BlockCipher::StaticAlgorithmName() + std::string("/CCM");}
|
||||
bool IsForwardTransformation() const
|
||||
{return T_IsEncryption;}
|
||||
|
||||
private:
|
||||
BlockCipher & AccessBlockCipher() {return m_cipher;}
|
||||
int DefaultDigestSize() const {return T_DefaultDigestSize;}
|
||||
typename T_BlockCipher::Encryption m_cipher;
|
||||
};
|
||||
|
||||
/// <a href="http://www.cryptolounge.org/wiki/CCM">CCM</a>
|
||||
template <class T_BlockCipher, int T_DefaultDigestSize = 16>
|
||||
struct CCM : public AuthenticatedSymmetricCipherDocumentation
|
||||
{
|
||||
typedef CCM_Final<T_BlockCipher, T_DefaultDigestSize, true> Encryption;
|
||||
typedef CCM_Final<T_BlockCipher, T_DefaultDigestSize, false> Decryption;
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
@ -1,122 +1,122 @@
|
||||
// cmac.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#ifndef CRYPTOPP_IMPORTS
|
||||
|
||||
#include "cmac.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
static void MulU(byte *k, unsigned int length)
|
||||
{
|
||||
byte carry = 0;
|
||||
|
||||
for (int i=length-1; i>=1; i-=2)
|
||||
{
|
||||
byte carry2 = k[i] >> 7;
|
||||
k[i] += k[i] + carry;
|
||||
carry = k[i-1] >> 7;
|
||||
k[i-1] += k[i-1] + carry2;
|
||||
}
|
||||
|
||||
if (carry)
|
||||
{
|
||||
switch (length)
|
||||
{
|
||||
case 8:
|
||||
k[7] ^= 0x1b;
|
||||
break;
|
||||
case 16:
|
||||
k[15] ^= 0x87;
|
||||
break;
|
||||
case 32:
|
||||
k[30] ^= 4;
|
||||
k[31] ^= 0x23;
|
||||
break;
|
||||
default:
|
||||
throw InvalidArgument("CMAC: " + IntToString(length) + " is not a supported cipher block size");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
||||
{
|
||||
BlockCipher &cipher = AccessCipher();
|
||||
unsigned int blockSize = cipher.BlockSize();
|
||||
|
||||
cipher.SetKey(key, length, params);
|
||||
m_reg.CleanNew(3*blockSize);
|
||||
m_counter = 0;
|
||||
|
||||
cipher.ProcessBlock(m_reg, m_reg+blockSize);
|
||||
MulU(m_reg+blockSize, blockSize);
|
||||
memcpy(m_reg+2*blockSize, m_reg+blockSize, blockSize);
|
||||
MulU(m_reg+2*blockSize, blockSize);
|
||||
}
|
||||
|
||||
void CMAC_Base::Update(const byte *input, size_t length)
|
||||
{
|
||||
if (!length)
|
||||
return;
|
||||
|
||||
BlockCipher &cipher = AccessCipher();
|
||||
unsigned int blockSize = cipher.BlockSize();
|
||||
|
||||
if (m_counter > 0)
|
||||
{
|
||||
unsigned int len = UnsignedMin(blockSize - m_counter, length);
|
||||
xorbuf(m_reg+m_counter, input, len);
|
||||
length -= len;
|
||||
input += len;
|
||||
m_counter += len;
|
||||
|
||||
if (m_counter == blockSize && length > 0)
|
||||
{
|
||||
cipher.ProcessBlock(m_reg);
|
||||
m_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (length > blockSize)
|
||||
{
|
||||
assert(m_counter == 0);
|
||||
size_t leftOver = 1 + cipher.AdvancedProcessBlocks(m_reg, input, m_reg, length-1, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
|
||||
input += (length - leftOver);
|
||||
length = leftOver;
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
assert(m_counter + length <= blockSize);
|
||||
xorbuf(m_reg+m_counter, input, length);
|
||||
m_counter += (unsigned int)length;
|
||||
}
|
||||
|
||||
assert(m_counter > 0);
|
||||
}
|
||||
|
||||
void CMAC_Base::TruncatedFinal(byte *mac, size_t size)
|
||||
{
|
||||
ThrowIfInvalidTruncatedSize(size);
|
||||
|
||||
BlockCipher &cipher = AccessCipher();
|
||||
unsigned int blockSize = cipher.BlockSize();
|
||||
|
||||
if (m_counter < blockSize)
|
||||
{
|
||||
m_reg[m_counter] ^= 0x80;
|
||||
cipher.AdvancedProcessBlocks(m_reg, m_reg+2*blockSize, m_reg, blockSize, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
|
||||
}
|
||||
else
|
||||
cipher.AdvancedProcessBlocks(m_reg, m_reg+blockSize, m_reg, blockSize, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
|
||||
|
||||
memcpy(mac, m_reg, size);
|
||||
|
||||
m_counter = 0;
|
||||
memset(m_reg, 0, blockSize);
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
// cmac.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
|
||||
#ifndef CRYPTOPP_IMPORTS
|
||||
|
||||
#include "cmac.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
static void MulU(byte *k, unsigned int length)
|
||||
{
|
||||
byte carry = 0;
|
||||
|
||||
for (int i=length-1; i>=1; i-=2)
|
||||
{
|
||||
byte carry2 = k[i] >> 7;
|
||||
k[i] += k[i] + carry;
|
||||
carry = k[i-1] >> 7;
|
||||
k[i-1] += k[i-1] + carry2;
|
||||
}
|
||||
|
||||
if (carry)
|
||||
{
|
||||
switch (length)
|
||||
{
|
||||
case 8:
|
||||
k[7] ^= 0x1b;
|
||||
break;
|
||||
case 16:
|
||||
k[15] ^= 0x87;
|
||||
break;
|
||||
case 32:
|
||||
k[30] ^= 4;
|
||||
k[31] ^= 0x23;
|
||||
break;
|
||||
default:
|
||||
throw InvalidArgument("CMAC: " + IntToString(length) + " is not a supported cipher block size");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CMAC_Base::UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms)
|
||||
{
|
||||
BlockCipher &cipher = AccessCipher();
|
||||
unsigned int blockSize = cipher.BlockSize();
|
||||
|
||||
cipher.SetKey(key, length, params);
|
||||
m_reg.CleanNew(3*blockSize);
|
||||
m_counter = 0;
|
||||
|
||||
cipher.ProcessBlock(m_reg, m_reg+blockSize);
|
||||
MulU(m_reg+blockSize, blockSize);
|
||||
memcpy(m_reg+2*blockSize, m_reg+blockSize, blockSize);
|
||||
MulU(m_reg+2*blockSize, blockSize);
|
||||
}
|
||||
|
||||
void CMAC_Base::Update(const byte *input, size_t length)
|
||||
{
|
||||
if (!length)
|
||||
return;
|
||||
|
||||
BlockCipher &cipher = AccessCipher();
|
||||
unsigned int blockSize = cipher.BlockSize();
|
||||
|
||||
if (m_counter > 0)
|
||||
{
|
||||
unsigned int len = UnsignedMin(blockSize - m_counter, length);
|
||||
xorbuf(m_reg+m_counter, input, len);
|
||||
length -= len;
|
||||
input += len;
|
||||
m_counter += len;
|
||||
|
||||
if (m_counter == blockSize && length > 0)
|
||||
{
|
||||
cipher.ProcessBlock(m_reg);
|
||||
m_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (length > blockSize)
|
||||
{
|
||||
assert(m_counter == 0);
|
||||
size_t leftOver = 1 + cipher.AdvancedProcessBlocks(m_reg, input, m_reg, length-1, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
|
||||
input += (length - leftOver);
|
||||
length = leftOver;
|
||||
}
|
||||
|
||||
if (length > 0)
|
||||
{
|
||||
assert(m_counter + length <= blockSize);
|
||||
xorbuf(m_reg+m_counter, input, length);
|
||||
m_counter += (unsigned int)length;
|
||||
}
|
||||
|
||||
assert(m_counter > 0);
|
||||
}
|
||||
|
||||
void CMAC_Base::TruncatedFinal(byte *mac, size_t size)
|
||||
{
|
||||
ThrowIfInvalidTruncatedSize(size);
|
||||
|
||||
BlockCipher &cipher = AccessCipher();
|
||||
unsigned int blockSize = cipher.BlockSize();
|
||||
|
||||
if (m_counter < blockSize)
|
||||
{
|
||||
m_reg[m_counter] ^= 0x80;
|
||||
cipher.AdvancedProcessBlocks(m_reg, m_reg+2*blockSize, m_reg, blockSize, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
|
||||
}
|
||||
else
|
||||
cipher.AdvancedProcessBlocks(m_reg, m_reg+blockSize, m_reg, blockSize, BlockTransformation::BT_DontIncrementInOutPointers|BlockTransformation::BT_XorInput);
|
||||
|
||||
memcpy(mac, m_reg, size);
|
||||
|
||||
m_counter = 0;
|
||||
memset(m_reg, 0, blockSize);
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
104
CryptoPP/cmac.h
104
CryptoPP/cmac.h
@ -1,52 +1,52 @@
|
||||
#ifndef CRYPTOPP_CMAC_H
|
||||
#define CRYPTOPP_CMAC_H
|
||||
|
||||
#include "seckey.h"
|
||||
#include "secblock.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! _
|
||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode
|
||||
{
|
||||
public:
|
||||
CMAC_Base() {}
|
||||
|
||||
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
|
||||
void Update(const byte *input, size_t length);
|
||||
void TruncatedFinal(byte *mac, size_t size);
|
||||
unsigned int DigestSize() const {return GetCipher().BlockSize();}
|
||||
unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
|
||||
unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
|
||||
|
||||
protected:
|
||||
friend class EAX_Base;
|
||||
|
||||
const BlockCipher & GetCipher() const {return const_cast<CMAC_Base*>(this)->AccessCipher();}
|
||||
virtual BlockCipher & AccessCipher() =0;
|
||||
|
||||
void ProcessBuf();
|
||||
SecByteBlock m_reg;
|
||||
unsigned int m_counter;
|
||||
};
|
||||
|
||||
/// <a href="http://www.cryptolounge.org/wiki/CMAC">CMAC</a>
|
||||
/*! Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32 */
|
||||
template <class T>
|
||||
class CMAC : public MessageAuthenticationCodeImpl<CMAC_Base, CMAC<T> >, public SameKeyLengthAs<T>
|
||||
{
|
||||
public:
|
||||
CMAC() {}
|
||||
CMAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
|
||||
{this->SetKey(key, length);}
|
||||
|
||||
static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";}
|
||||
|
||||
private:
|
||||
BlockCipher & AccessCipher() {return m_cipher;}
|
||||
typename T::Encryption m_cipher;
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
#ifndef CRYPTOPP_CMAC_H
|
||||
#define CRYPTOPP_CMAC_H
|
||||
|
||||
#include "seckey.h"
|
||||
#include "secblock.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! _
|
||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE CMAC_Base : public MessageAuthenticationCode
|
||||
{
|
||||
public:
|
||||
CMAC_Base() {}
|
||||
|
||||
void UncheckedSetKey(const byte *key, unsigned int length, const NameValuePairs ¶ms);
|
||||
void Update(const byte *input, size_t length);
|
||||
void TruncatedFinal(byte *mac, size_t size);
|
||||
unsigned int DigestSize() const {return GetCipher().BlockSize();}
|
||||
unsigned int OptimalBlockSize() const {return GetCipher().BlockSize();}
|
||||
unsigned int OptimalDataAlignment() const {return GetCipher().OptimalDataAlignment();}
|
||||
|
||||
protected:
|
||||
friend class EAX_Base;
|
||||
|
||||
const BlockCipher & GetCipher() const {return const_cast<CMAC_Base*>(this)->AccessCipher();}
|
||||
virtual BlockCipher & AccessCipher() =0;
|
||||
|
||||
void ProcessBuf();
|
||||
SecByteBlock m_reg;
|
||||
unsigned int m_counter;
|
||||
};
|
||||
|
||||
/// <a href="http://www.cryptolounge.org/wiki/CMAC">CMAC</a>
|
||||
/*! Template parameter T should be a class derived from BlockCipherDocumentation, for example AES, with a block size of 8, 16, or 32 */
|
||||
template <class T>
|
||||
class CMAC : public MessageAuthenticationCodeImpl<CMAC_Base, CMAC<T> >, public SameKeyLengthAs<T>
|
||||
{
|
||||
public:
|
||||
CMAC() {}
|
||||
CMAC(const byte *key, size_t length=SameKeyLengthAs<T>::DEFAULT_KEYLENGTH)
|
||||
{this->SetKey(key, length);}
|
||||
|
||||
static std::string StaticAlgorithmName() {return std::string("CMAC(") + T::StaticAlgorithmName() + ")";}
|
||||
|
||||
private:
|
||||
BlockCipher & AccessCipher() {return m_cipher;}
|
||||
typename T::Encryption m_cipher;
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
118
CryptoPP/eax.cpp
118
CryptoPP/eax.cpp
@ -1,59 +1,59 @@
|
||||
// eax.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
#include "eax.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
|
||||
{
|
||||
AccessMAC().SetKey(userKey, keylength, params);
|
||||
m_buffer.New(2*AccessMAC().TagSize());
|
||||
}
|
||||
|
||||
void EAX_Base::Resync(const byte *iv, size_t len)
|
||||
{
|
||||
MessageAuthenticationCode &mac = AccessMAC();
|
||||
unsigned int blockSize = mac.TagSize();
|
||||
|
||||
memset(m_buffer, 0, blockSize);
|
||||
mac.Update(m_buffer, blockSize);
|
||||
mac.CalculateDigest(m_buffer+blockSize, iv, len);
|
||||
|
||||
m_buffer[blockSize-1] = 1;
|
||||
mac.Update(m_buffer, blockSize);
|
||||
|
||||
m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize);
|
||||
}
|
||||
|
||||
size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
|
||||
{
|
||||
AccessMAC().Update(data, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EAX_Base::AuthenticateLastHeaderBlock()
|
||||
{
|
||||
assert(m_bufferedDataLength == 0);
|
||||
MessageAuthenticationCode &mac = AccessMAC();
|
||||
unsigned int blockSize = mac.TagSize();
|
||||
|
||||
mac.Final(m_buffer);
|
||||
xorbuf(m_buffer+blockSize, m_buffer, blockSize);
|
||||
|
||||
memset(m_buffer, 0, blockSize);
|
||||
m_buffer[blockSize-1] = 2;
|
||||
mac.Update(m_buffer, blockSize);
|
||||
}
|
||||
|
||||
void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
|
||||
{
|
||||
assert(m_bufferedDataLength == 0);
|
||||
MessageAuthenticationCode &mac = AccessMAC();
|
||||
unsigned int blockSize = mac.TagSize();
|
||||
|
||||
mac.TruncatedFinal(m_buffer, macSize);
|
||||
xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
// eax.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
#include "eax.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
void EAX_Base::SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms)
|
||||
{
|
||||
AccessMAC().SetKey(userKey, keylength, params);
|
||||
m_buffer.New(2*AccessMAC().TagSize());
|
||||
}
|
||||
|
||||
void EAX_Base::Resync(const byte *iv, size_t len)
|
||||
{
|
||||
MessageAuthenticationCode &mac = AccessMAC();
|
||||
unsigned int blockSize = mac.TagSize();
|
||||
|
||||
memset(m_buffer, 0, blockSize);
|
||||
mac.Update(m_buffer, blockSize);
|
||||
mac.CalculateDigest(m_buffer+blockSize, iv, len);
|
||||
|
||||
m_buffer[blockSize-1] = 1;
|
||||
mac.Update(m_buffer, blockSize);
|
||||
|
||||
m_ctr.SetCipherWithIV(AccessMAC().AccessCipher(), m_buffer+blockSize, blockSize);
|
||||
}
|
||||
|
||||
size_t EAX_Base::AuthenticateBlocks(const byte *data, size_t len)
|
||||
{
|
||||
AccessMAC().Update(data, len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EAX_Base::AuthenticateLastHeaderBlock()
|
||||
{
|
||||
assert(m_bufferedDataLength == 0);
|
||||
MessageAuthenticationCode &mac = AccessMAC();
|
||||
unsigned int blockSize = mac.TagSize();
|
||||
|
||||
mac.Final(m_buffer);
|
||||
xorbuf(m_buffer+blockSize, m_buffer, blockSize);
|
||||
|
||||
memset(m_buffer, 0, blockSize);
|
||||
m_buffer[blockSize-1] = 2;
|
||||
mac.Update(m_buffer, blockSize);
|
||||
}
|
||||
|
||||
void EAX_Base::AuthenticateLastFooterBlock(byte *tag, size_t macSize)
|
||||
{
|
||||
assert(m_bufferedDataLength == 0);
|
||||
MessageAuthenticationCode &mac = AccessMAC();
|
||||
unsigned int blockSize = mac.TagSize();
|
||||
|
||||
mac.TruncatedFinal(m_buffer, macSize);
|
||||
xorbuf(tag, m_buffer, m_buffer+blockSize, macSize);
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
|
1656
CryptoPP/gcm.cpp
1656
CryptoPP/gcm.cpp
File diff suppressed because it is too large
Load Diff
212
CryptoPP/gcm.h
212
CryptoPP/gcm.h
@ -1,106 +1,106 @@
|
||||
#ifndef CRYPTOPP_GCM_H
|
||||
#define CRYPTOPP_GCM_H
|
||||
|
||||
#include "authenc.h"
|
||||
#include "modes.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! .
|
||||
enum GCM_TablesOption {GCM_2K_Tables, GCM_64K_Tables};
|
||||
|
||||
//! .
|
||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE GCM_Base : public AuthenticatedSymmetricCipherBase
|
||||
{
|
||||
public:
|
||||
// AuthenticatedSymmetricCipher
|
||||
std::string AlgorithmName() const
|
||||
{return GetBlockCipher().AlgorithmName() + std::string("/GCM");}
|
||||
size_t MinKeyLength() const
|
||||
{return GetBlockCipher().MinKeyLength();}
|
||||
size_t MaxKeyLength() const
|
||||
{return GetBlockCipher().MaxKeyLength();}
|
||||
size_t DefaultKeyLength() const
|
||||
{return GetBlockCipher().DefaultKeyLength();}
|
||||
size_t GetValidKeyLength(size_t n) const
|
||||
{return GetBlockCipher().GetValidKeyLength(n);}
|
||||
bool IsValidKeyLength(size_t n) const
|
||||
{return GetBlockCipher().IsValidKeyLength(n);}
|
||||
unsigned int OptimalDataAlignment() const;
|
||||
IV_Requirement IVRequirement() const
|
||||
{return UNIQUE_IV;}
|
||||
unsigned int IVSize() const
|
||||
{return 12;}
|
||||
unsigned int MinIVLength() const
|
||||
{return 1;}
|
||||
unsigned int MaxIVLength() const
|
||||
{return UINT_MAX;} // (W64LIT(1)<<61)-1 in the standard
|
||||
unsigned int DigestSize() const
|
||||
{return 16;}
|
||||
lword MaxHeaderLength() const
|
||||
{return (W64LIT(1)<<61)-1;}
|
||||
lword MaxMessageLength() const
|
||||
{return ((W64LIT(1)<<39)-256)/8;}
|
||||
|
||||
protected:
|
||||
// AuthenticatedSymmetricCipherBase
|
||||
bool AuthenticationIsOnPlaintext() const
|
||||
{return false;}
|
||||
unsigned int AuthenticationBlockSize() const
|
||||
{return HASH_BLOCKSIZE;}
|
||||
void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
|
||||
void Resync(const byte *iv, size_t len);
|
||||
size_t AuthenticateBlocks(const byte *data, size_t len);
|
||||
void AuthenticateLastHeaderBlock();
|
||||
void AuthenticateLastConfidentialBlock();
|
||||
void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
|
||||
SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
|
||||
|
||||
virtual BlockCipher & AccessBlockCipher() =0;
|
||||
virtual GCM_TablesOption GetTablesOption() const =0;
|
||||
|
||||
const BlockCipher & GetBlockCipher() const {return const_cast<GCM_Base *>(this)->AccessBlockCipher();};
|
||||
byte *HashBuffer() {return m_buffer+REQUIRED_BLOCKSIZE;}
|
||||
byte *HashKey() {return m_buffer+2*REQUIRED_BLOCKSIZE;}
|
||||
byte *MulTable() {return m_buffer+3*REQUIRED_BLOCKSIZE;}
|
||||
inline void ReverseHashBufferIfNeeded();
|
||||
|
||||
class CRYPTOPP_DLL GCTR : public CTR_Mode_ExternalCipher::Encryption
|
||||
{
|
||||
protected:
|
||||
void IncrementCounterBy256();
|
||||
};
|
||||
|
||||
GCTR m_ctr;
|
||||
static word16 s_reductionTable[256];
|
||||
static volatile bool s_reductionTableInitialized;
|
||||
enum {REQUIRED_BLOCKSIZE = 16, HASH_BLOCKSIZE = 16};
|
||||
};
|
||||
|
||||
//! .
|
||||
template <class T_BlockCipher, GCM_TablesOption T_TablesOption, bool T_IsEncryption>
|
||||
class GCM_Final : public GCM_Base
|
||||
{
|
||||
public:
|
||||
static std::string StaticAlgorithmName()
|
||||
{return T_BlockCipher::StaticAlgorithmName() + std::string("/GCM");}
|
||||
bool IsForwardTransformation() const
|
||||
{return T_IsEncryption;}
|
||||
|
||||
private:
|
||||
GCM_TablesOption GetTablesOption() const {return T_TablesOption;}
|
||||
BlockCipher & AccessBlockCipher() {return m_cipher;}
|
||||
typename T_BlockCipher::Encryption m_cipher;
|
||||
};
|
||||
|
||||
//! <a href="http://www.cryptolounge.org/wiki/GCM">GCM</a>
|
||||
template <class T_BlockCipher, GCM_TablesOption T_TablesOption=GCM_2K_Tables>
|
||||
struct GCM : public AuthenticatedSymmetricCipherDocumentation
|
||||
{
|
||||
typedef GCM_Final<T_BlockCipher, T_TablesOption, true> Encryption;
|
||||
typedef GCM_Final<T_BlockCipher, T_TablesOption, false> Decryption;
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
#ifndef CRYPTOPP_GCM_H
|
||||
#define CRYPTOPP_GCM_H
|
||||
|
||||
#include "authenc.h"
|
||||
#include "modes.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
//! .
|
||||
enum GCM_TablesOption {GCM_2K_Tables, GCM_64K_Tables};
|
||||
|
||||
//! .
|
||||
class CRYPTOPP_DLL CRYPTOPP_NO_VTABLE GCM_Base : public AuthenticatedSymmetricCipherBase
|
||||
{
|
||||
public:
|
||||
// AuthenticatedSymmetricCipher
|
||||
std::string AlgorithmName() const
|
||||
{return GetBlockCipher().AlgorithmName() + std::string("/GCM");}
|
||||
size_t MinKeyLength() const
|
||||
{return GetBlockCipher().MinKeyLength();}
|
||||
size_t MaxKeyLength() const
|
||||
{return GetBlockCipher().MaxKeyLength();}
|
||||
size_t DefaultKeyLength() const
|
||||
{return GetBlockCipher().DefaultKeyLength();}
|
||||
size_t GetValidKeyLength(size_t n) const
|
||||
{return GetBlockCipher().GetValidKeyLength(n);}
|
||||
bool IsValidKeyLength(size_t n) const
|
||||
{return GetBlockCipher().IsValidKeyLength(n);}
|
||||
unsigned int OptimalDataAlignment() const;
|
||||
IV_Requirement IVRequirement() const
|
||||
{return UNIQUE_IV;}
|
||||
unsigned int IVSize() const
|
||||
{return 12;}
|
||||
unsigned int MinIVLength() const
|
||||
{return 1;}
|
||||
unsigned int MaxIVLength() const
|
||||
{return UINT_MAX;} // (W64LIT(1)<<61)-1 in the standard
|
||||
unsigned int DigestSize() const
|
||||
{return 16;}
|
||||
lword MaxHeaderLength() const
|
||||
{return (W64LIT(1)<<61)-1;}
|
||||
lword MaxMessageLength() const
|
||||
{return ((W64LIT(1)<<39)-256)/8;}
|
||||
|
||||
protected:
|
||||
// AuthenticatedSymmetricCipherBase
|
||||
bool AuthenticationIsOnPlaintext() const
|
||||
{return false;}
|
||||
unsigned int AuthenticationBlockSize() const
|
||||
{return HASH_BLOCKSIZE;}
|
||||
void SetKeyWithoutResync(const byte *userKey, size_t keylength, const NameValuePairs ¶ms);
|
||||
void Resync(const byte *iv, size_t len);
|
||||
size_t AuthenticateBlocks(const byte *data, size_t len);
|
||||
void AuthenticateLastHeaderBlock();
|
||||
void AuthenticateLastConfidentialBlock();
|
||||
void AuthenticateLastFooterBlock(byte *mac, size_t macSize);
|
||||
SymmetricCipher & AccessSymmetricCipher() {return m_ctr;}
|
||||
|
||||
virtual BlockCipher & AccessBlockCipher() =0;
|
||||
virtual GCM_TablesOption GetTablesOption() const =0;
|
||||
|
||||
const BlockCipher & GetBlockCipher() const {return const_cast<GCM_Base *>(this)->AccessBlockCipher();};
|
||||
byte *HashBuffer() {return m_buffer+REQUIRED_BLOCKSIZE;}
|
||||
byte *HashKey() {return m_buffer+2*REQUIRED_BLOCKSIZE;}
|
||||
byte *MulTable() {return m_buffer+3*REQUIRED_BLOCKSIZE;}
|
||||
inline void ReverseHashBufferIfNeeded();
|
||||
|
||||
class CRYPTOPP_DLL GCTR : public CTR_Mode_ExternalCipher::Encryption
|
||||
{
|
||||
protected:
|
||||
void IncrementCounterBy256();
|
||||
};
|
||||
|
||||
GCTR m_ctr;
|
||||
static word16 s_reductionTable[256];
|
||||
static volatile bool s_reductionTableInitialized;
|
||||
enum {REQUIRED_BLOCKSIZE = 16, HASH_BLOCKSIZE = 16};
|
||||
};
|
||||
|
||||
//! .
|
||||
template <class T_BlockCipher, GCM_TablesOption T_TablesOption, bool T_IsEncryption>
|
||||
class GCM_Final : public GCM_Base
|
||||
{
|
||||
public:
|
||||
static std::string StaticAlgorithmName()
|
||||
{return T_BlockCipher::StaticAlgorithmName() + std::string("/GCM");}
|
||||
bool IsForwardTransformation() const
|
||||
{return T_IsEncryption;}
|
||||
|
||||
private:
|
||||
GCM_TablesOption GetTablesOption() const {return T_TablesOption;}
|
||||
BlockCipher & AccessBlockCipher() {return m_cipher;}
|
||||
typename T_BlockCipher::Encryption m_cipher;
|
||||
};
|
||||
|
||||
//! <a href="http://www.cryptolounge.org/wiki/GCM">GCM</a>
|
||||
template <class T_BlockCipher, GCM_TablesOption T_TablesOption=GCM_2K_Tables>
|
||||
struct GCM : public AuthenticatedSymmetricCipherDocumentation
|
||||
{
|
||||
typedef GCM_Final<T_BlockCipher, T_TablesOption, true> Encryption;
|
||||
typedef GCM_Final<T_BlockCipher, T_TablesOption, false> Decryption;
|
||||
};
|
||||
|
||||
NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
@ -1,104 +1,104 @@
|
||||
// seed.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
#include "seed.h"
|
||||
#include "misc.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
static const word32 s_kc[16] = {
|
||||
0x9e3779b9, 0x3c6ef373, 0x78dde6e6, 0xf1bbcdcc, 0xe3779b99, 0xc6ef3733, 0x8dde6e67, 0x1bbcdccf,
|
||||
0x3779b99e, 0x6ef3733c, 0xdde6e678, 0xbbcdccf1, 0x779b99e3, 0xef3733c6, 0xde6e678d, 0xbcdccf1b};
|
||||
|
||||
static const byte s_s0[256] = {
|
||||
0xA9, 0x85, 0xD6, 0xD3, 0x54, 0x1D, 0xAC, 0x25, 0x5D, 0x43, 0x18, 0x1E, 0x51, 0xFC, 0xCA, 0x63, 0x28,
|
||||
0x44, 0x20, 0x9D, 0xE0, 0xE2, 0xC8, 0x17, 0xA5, 0x8F, 0x03, 0x7B, 0xBB, 0x13, 0xD2, 0xEE, 0x70, 0x8C,
|
||||
0x3F, 0xA8, 0x32, 0xDD, 0xF6, 0x74, 0xEC, 0x95, 0x0B, 0x57, 0x5C, 0x5B, 0xBD, 0x01, 0x24, 0x1C, 0x73,
|
||||
0x98, 0x10, 0xCC, 0xF2, 0xD9, 0x2C, 0xE7, 0x72, 0x83, 0x9B, 0xD1, 0x86, 0xC9, 0x60, 0x50, 0xA3, 0xEB,
|
||||
0x0D, 0xB6, 0x9E, 0x4F, 0xB7, 0x5A, 0xC6, 0x78, 0xA6, 0x12, 0xAF, 0xD5, 0x61, 0xC3, 0xB4, 0x41, 0x52,
|
||||
0x7D, 0x8D, 0x08, 0x1F, 0x99, 0x00, 0x19, 0x04, 0x53, 0xF7, 0xE1, 0xFD, 0x76, 0x2F, 0x27, 0xB0, 0x8B,
|
||||
0x0E, 0xAB, 0xA2, 0x6E, 0x93, 0x4D, 0x69, 0x7C, 0x09, 0x0A, 0xBF, 0xEF, 0xF3, 0xC5, 0x87, 0x14, 0xFE,
|
||||
0x64, 0xDE, 0x2E, 0x4B, 0x1A, 0x06, 0x21, 0x6B, 0x66, 0x02, 0xF5, 0x92, 0x8A, 0x0C, 0xB3, 0x7E, 0xD0,
|
||||
0x7A, 0x47, 0x96, 0xE5, 0x26, 0x80, 0xAD, 0xDF, 0xA1, 0x30, 0x37, 0xAE, 0x36, 0x15, 0x22, 0x38, 0xF4,
|
||||
0xA7, 0x45, 0x4C, 0x81, 0xE9, 0x84, 0x97, 0x35, 0xCB, 0xCE, 0x3C, 0x71, 0x11, 0xC7, 0x89, 0x75, 0xFB,
|
||||
0xDA, 0xF8, 0x94, 0x59, 0x82, 0xC4, 0xFF, 0x49, 0x39, 0x67, 0xC0, 0xCF, 0xD7, 0xB8, 0x0F, 0x8E, 0x42,
|
||||
0x23, 0x91, 0x6C, 0xDB, 0xA4, 0x34, 0xF1, 0x48, 0xC2, 0x6F, 0x3D, 0x2D, 0x40, 0xBE, 0x3E, 0xBC, 0xC1,
|
||||
0xAA, 0xBA, 0x4E, 0x55, 0x3B, 0xDC, 0x68, 0x7F, 0x9C, 0xD8, 0x4A, 0x56, 0x77, 0xA0, 0xED, 0x46, 0xB5,
|
||||
0x2B, 0x65, 0xFA, 0xE3, 0xB9, 0xB1, 0x9F, 0x5E, 0xF9, 0xE6, 0xB2, 0x31, 0xEA, 0x6D, 0x5F, 0xE4, 0xF0,
|
||||
0xCD, 0x88, 0x16, 0x3A, 0x58, 0xD4, 0x62, 0x29, 0x07, 0x33, 0xE8, 0x1B, 0x05, 0x79, 0x90, 0x6A, 0x2A,
|
||||
0x9A};
|
||||
|
||||
static const byte s_s1[256] = {
|
||||
0x38, 0xE8, 0x2D, 0xA6, 0xCF, 0xDE, 0xB3, 0xB8, 0xAF, 0x60, 0x55, 0xC7, 0x44, 0x6F, 0x6B, 0x5B, 0xC3,
|
||||
0x62, 0x33, 0xB5, 0x29, 0xA0, 0xE2, 0xA7, 0xD3, 0x91, 0x11, 0x06, 0x1C, 0xBC, 0x36, 0x4B, 0xEF, 0x88,
|
||||
0x6C, 0xA8, 0x17, 0xC4, 0x16, 0xF4, 0xC2, 0x45, 0xE1, 0xD6, 0x3F, 0x3D, 0x8E, 0x98, 0x28, 0x4E, 0xF6,
|
||||
0x3E, 0xA5, 0xF9, 0x0D, 0xDF, 0xD8, 0x2B, 0x66, 0x7A, 0x27, 0x2F, 0xF1, 0x72, 0x42, 0xD4, 0x41, 0xC0,
|
||||
0x73, 0x67, 0xAC, 0x8B, 0xF7, 0xAD, 0x80, 0x1F, 0xCA, 0x2C, 0xAA, 0x34, 0xD2, 0x0B, 0xEE, 0xE9, 0x5D,
|
||||
0x94, 0x18, 0xF8, 0x57, 0xAE, 0x08, 0xC5, 0x13, 0xCD, 0x86, 0xB9, 0xFF, 0x7D, 0xC1, 0x31, 0xF5, 0x8A,
|
||||
0x6A, 0xB1, 0xD1, 0x20, 0xD7, 0x02, 0x22, 0x04, 0x68, 0x71, 0x07, 0xDB, 0x9D, 0x99, 0x61, 0xBE, 0xE6,
|
||||
0x59, 0xDD, 0x51, 0x90, 0xDC, 0x9A, 0xA3, 0xAB, 0xD0, 0x81, 0x0F, 0x47, 0x1A, 0xE3, 0xEC, 0x8D, 0xBF,
|
||||
0x96, 0x7B, 0x5C, 0xA2, 0xA1, 0x63, 0x23, 0x4D, 0xC8, 0x9E, 0x9C, 0x3A, 0x0C, 0x2E, 0xBA, 0x6E, 0x9F,
|
||||
0x5A, 0xF2, 0x92, 0xF3, 0x49, 0x78, 0xCC, 0x15, 0xFB, 0x70, 0x75, 0x7F, 0x35, 0x10, 0x03, 0x64, 0x6D,
|
||||
0xC6, 0x74, 0xD5, 0xB4, 0xEA, 0x09, 0x76, 0x19, 0xFE, 0x40, 0x12, 0xE0, 0xBD, 0x05, 0xFA, 0x01, 0xF0,
|
||||
0x2A, 0x5E, 0xA9, 0x56, 0x43, 0x85, 0x14, 0x89, 0x9B, 0xB0, 0xE5, 0x48, 0x79, 0x97, 0xFC, 0x1E, 0x82,
|
||||
0x21, 0x8C, 0x1B, 0x5F, 0x77, 0x54, 0xB2, 0x1D, 0x25, 0x4F, 0x00, 0x46, 0xED, 0x58, 0x52, 0xEB, 0x7E,
|
||||
0xDA, 0xC9, 0xFD, 0x30, 0x95, 0x65, 0x3C, 0xB6, 0xE4, 0xBB, 0x7C, 0x0E, 0x50, 0x39, 0x26, 0x32, 0x84,
|
||||
0x69, 0x93, 0x37, 0xE7, 0x24, 0xA4, 0xCB, 0x53, 0x0A, 0x87, 0xD9, 0x4C, 0x83, 0x8F, 0xCE, 0x3B, 0x4A,
|
||||
0xB7};
|
||||
|
||||
#define SS0(x) ((s_s0[x]*0x01010101UL) & 0x3FCFF3FC)
|
||||
#define SS1(x) ((s_s1[x]*0x01010101UL) & 0xFC3FCFF3)
|
||||
#define SS2(x) ((s_s0[x]*0x01010101UL) & 0xF3FC3FCF)
|
||||
#define SS3(x) ((s_s1[x]*0x01010101UL) & 0xCFF3FC3F)
|
||||
#define G(x) (SS0(GETBYTE(x, 0)) ^ SS1(GETBYTE(x, 1)) ^ SS2(GETBYTE(x, 2)) ^ SS3(GETBYTE(x, 3)))
|
||||
|
||||
void SEED::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
|
||||
{
|
||||
AssertValidKeyLength(length);
|
||||
|
||||
word64 key01, key23;
|
||||
GetBlock<word64, BigEndian> get(userKey);
|
||||
get(key01)(key23);
|
||||
word32 *k = m_k;
|
||||
size_t kInc = 2;
|
||||
if (!IsForwardTransformation())
|
||||
{
|
||||
k = k+30;
|
||||
kInc = 0-kInc;
|
||||
}
|
||||
|
||||
for (int i=0; i<ROUNDS; i++)
|
||||
{
|
||||
word32 t0 = word32(key01>>32) + word32(key23>>32) - s_kc[i];
|
||||
word32 t1 = word32(key01) - word32(key23) + s_kc[i];
|
||||
k[0] = G(t0);
|
||||
k[1] = G(t1);
|
||||
k+=kInc;
|
||||
if (i&1)
|
||||
key23 = rotlFixed<word64>(key23, 8);
|
||||
else
|
||||
key01 = rotrFixed<word64>(key01, 8);
|
||||
}
|
||||
}
|
||||
|
||||
void SEED::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
||||
{
|
||||
typedef BlockGetAndPut<word32, BigEndian> Block;
|
||||
word32 a0, a1, b0, b1, t0, t1;
|
||||
Block::Get(inBlock)(a0)(a1)(b0)(b1);
|
||||
|
||||
for (int i=0; i<ROUNDS; i+=2)
|
||||
{
|
||||
t0 = b0 ^ m_k[2*i+0]; t1 = b1 ^ m_k[2*i+1] ^ t0;
|
||||
t1 = G(t1); t0 += t1; t0 = G(t0); t1 += t0; t1 = G(t1);
|
||||
a0 ^= t0 + t1; a1 ^= t1;
|
||||
|
||||
t0 = a0 ^ m_k[2*i+2]; t1 = a1 ^ m_k[2*i+3] ^ t0;
|
||||
t1 = G(t1); t0 += t1; t0 = G(t0); t1 += t0; t1 = G(t1);
|
||||
b0 ^= t0 + t1; b1 ^= t1;
|
||||
}
|
||||
|
||||
Block::Put(xorBlock, outBlock)(b0)(b1)(a0)(a1);
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
// seed.cpp - written and placed in the public domain by Wei Dai
|
||||
|
||||
#include "pch.h"
|
||||
#include "seed.h"
|
||||
#include "misc.h"
|
||||
|
||||
NAMESPACE_BEGIN(CryptoPP)
|
||||
|
||||
static const word32 s_kc[16] = {
|
||||
0x9e3779b9, 0x3c6ef373, 0x78dde6e6, 0xf1bbcdcc, 0xe3779b99, 0xc6ef3733, 0x8dde6e67, 0x1bbcdccf,
|
||||
0x3779b99e, 0x6ef3733c, 0xdde6e678, 0xbbcdccf1, 0x779b99e3, 0xef3733c6, 0xde6e678d, 0xbcdccf1b};
|
||||
|
||||
static const byte s_s0[256] = {
|
||||
0xA9, 0x85, 0xD6, 0xD3, 0x54, 0x1D, 0xAC, 0x25, 0x5D, 0x43, 0x18, 0x1E, 0x51, 0xFC, 0xCA, 0x63, 0x28,
|
||||
0x44, 0x20, 0x9D, 0xE0, 0xE2, 0xC8, 0x17, 0xA5, 0x8F, 0x03, 0x7B, 0xBB, 0x13, 0xD2, 0xEE, 0x70, 0x8C,
|
||||
0x3F, 0xA8, 0x32, 0xDD, 0xF6, 0x74, 0xEC, 0x95, 0x0B, 0x57, 0x5C, 0x5B, 0xBD, 0x01, 0x24, 0x1C, 0x73,
|
||||
0x98, 0x10, 0xCC, 0xF2, 0xD9, 0x2C, 0xE7, 0x72, 0x83, 0x9B, 0xD1, 0x86, 0xC9, 0x60, 0x50, 0xA3, 0xEB,
|
||||
0x0D, 0xB6, 0x9E, 0x4F, 0xB7, 0x5A, 0xC6, 0x78, 0xA6, 0x12, 0xAF, 0xD5, 0x61, 0xC3, 0xB4, 0x41, 0x52,
|
||||
0x7D, 0x8D, 0x08, 0x1F, 0x99, 0x00, 0x19, 0x04, 0x53, 0xF7, 0xE1, 0xFD, 0x76, 0x2F, 0x27, 0xB0, 0x8B,
|
||||
0x0E, 0xAB, 0xA2, 0x6E, 0x93, 0x4D, 0x69, 0x7C, 0x09, 0x0A, 0xBF, 0xEF, 0xF3, 0xC5, 0x87, 0x14, 0xFE,
|
||||
0x64, 0xDE, 0x2E, 0x4B, 0x1A, 0x06, 0x21, 0x6B, 0x66, 0x02, 0xF5, 0x92, 0x8A, 0x0C, 0xB3, 0x7E, 0xD0,
|
||||
0x7A, 0x47, 0x96, 0xE5, 0x26, 0x80, 0xAD, 0xDF, 0xA1, 0x30, 0x37, 0xAE, 0x36, 0x15, 0x22, 0x38, 0xF4,
|
||||
0xA7, 0x45, 0x4C, 0x81, 0xE9, 0x84, 0x97, 0x35, 0xCB, 0xCE, 0x3C, 0x71, 0x11, 0xC7, 0x89, 0x75, 0xFB,
|
||||
0xDA, 0xF8, 0x94, 0x59, 0x82, 0xC4, 0xFF, 0x49, 0x39, 0x67, 0xC0, 0xCF, 0xD7, 0xB8, 0x0F, 0x8E, 0x42,
|
||||
0x23, 0x91, 0x6C, 0xDB, 0xA4, 0x34, 0xF1, 0x48, 0xC2, 0x6F, 0x3D, 0x2D, 0x40, 0xBE, 0x3E, 0xBC, 0xC1,
|
||||
0xAA, 0xBA, 0x4E, 0x55, 0x3B, 0xDC, 0x68, 0x7F, 0x9C, 0xD8, 0x4A, 0x56, 0x77, 0xA0, 0xED, 0x46, 0xB5,
|
||||
0x2B, 0x65, 0xFA, 0xE3, 0xB9, 0xB1, 0x9F, 0x5E, 0xF9, 0xE6, 0xB2, 0x31, 0xEA, 0x6D, 0x5F, 0xE4, 0xF0,
|
||||
0xCD, 0x88, 0x16, 0x3A, 0x58, 0xD4, 0x62, 0x29, 0x07, 0x33, 0xE8, 0x1B, 0x05, 0x79, 0x90, 0x6A, 0x2A,
|
||||
0x9A};
|
||||
|
||||
static const byte s_s1[256] = {
|
||||
0x38, 0xE8, 0x2D, 0xA6, 0xCF, 0xDE, 0xB3, 0xB8, 0xAF, 0x60, 0x55, 0xC7, 0x44, 0x6F, 0x6B, 0x5B, 0xC3,
|
||||
0x62, 0x33, 0xB5, 0x29, 0xA0, 0xE2, 0xA7, 0xD3, 0x91, 0x11, 0x06, 0x1C, 0xBC, 0x36, 0x4B, 0xEF, 0x88,
|
||||
0x6C, 0xA8, 0x17, 0xC4, 0x16, 0xF4, 0xC2, 0x45, 0xE1, 0xD6, 0x3F, 0x3D, 0x8E, 0x98, 0x28, 0x4E, 0xF6,
|
||||
0x3E, 0xA5, 0xF9, 0x0D, 0xDF, 0xD8, 0x2B, 0x66, 0x7A, 0x27, 0x2F, 0xF1, 0x72, 0x42, 0xD4, 0x41, 0xC0,
|
||||
0x73, 0x67, 0xAC, 0x8B, 0xF7, 0xAD, 0x80, 0x1F, 0xCA, 0x2C, 0xAA, 0x34, 0xD2, 0x0B, 0xEE, 0xE9, 0x5D,
|
||||
0x94, 0x18, 0xF8, 0x57, 0xAE, 0x08, 0xC5, 0x13, 0xCD, 0x86, 0xB9, 0xFF, 0x7D, 0xC1, 0x31, 0xF5, 0x8A,
|
||||
0x6A, 0xB1, 0xD1, 0x20, 0xD7, 0x02, 0x22, 0x04, 0x68, 0x71, 0x07, 0xDB, 0x9D, 0x99, 0x61, 0xBE, 0xE6,
|
||||
0x59, 0xDD, 0x51, 0x90, 0xDC, 0x9A, 0xA3, 0xAB, 0xD0, 0x81, 0x0F, 0x47, 0x1A, 0xE3, 0xEC, 0x8D, 0xBF,
|
||||
0x96, 0x7B, 0x5C, 0xA2, 0xA1, 0x63, 0x23, 0x4D, 0xC8, 0x9E, 0x9C, 0x3A, 0x0C, 0x2E, 0xBA, 0x6E, 0x9F,
|
||||
0x5A, 0xF2, 0x92, 0xF3, 0x49, 0x78, 0xCC, 0x15, 0xFB, 0x70, 0x75, 0x7F, 0x35, 0x10, 0x03, 0x64, 0x6D,
|
||||
0xC6, 0x74, 0xD5, 0xB4, 0xEA, 0x09, 0x76, 0x19, 0xFE, 0x40, 0x12, 0xE0, 0xBD, 0x05, 0xFA, 0x01, 0xF0,
|
||||
0x2A, 0x5E, 0xA9, 0x56, 0x43, 0x85, 0x14, 0x89, 0x9B, 0xB0, 0xE5, 0x48, 0x79, 0x97, 0xFC, 0x1E, 0x82,
|
||||
0x21, 0x8C, 0x1B, 0x5F, 0x77, 0x54, 0xB2, 0x1D, 0x25, 0x4F, 0x00, 0x46, 0xED, 0x58, 0x52, 0xEB, 0x7E,
|
||||
0xDA, 0xC9, 0xFD, 0x30, 0x95, 0x65, 0x3C, 0xB6, 0xE4, 0xBB, 0x7C, 0x0E, 0x50, 0x39, 0x26, 0x32, 0x84,
|
||||
0x69, 0x93, 0x37, 0xE7, 0x24, 0xA4, 0xCB, 0x53, 0x0A, 0x87, 0xD9, 0x4C, 0x83, 0x8F, 0xCE, 0x3B, 0x4A,
|
||||
0xB7};
|
||||
|
||||
#define SS0(x) ((s_s0[x]*0x01010101UL) & 0x3FCFF3FC)
|
||||
#define SS1(x) ((s_s1[x]*0x01010101UL) & 0xFC3FCFF3)
|
||||
#define SS2(x) ((s_s0[x]*0x01010101UL) & 0xF3FC3FCF)
|
||||
#define SS3(x) ((s_s1[x]*0x01010101UL) & 0xCFF3FC3F)
|
||||
#define G(x) (SS0(GETBYTE(x, 0)) ^ SS1(GETBYTE(x, 1)) ^ SS2(GETBYTE(x, 2)) ^ SS3(GETBYTE(x, 3)))
|
||||
|
||||
void SEED::Base::UncheckedSetKey(const byte *userKey, unsigned int length, const NameValuePairs ¶ms)
|
||||
{
|
||||
AssertValidKeyLength(length);
|
||||
|
||||
word64 key01, key23;
|
||||
GetBlock<word64, BigEndian> get(userKey);
|
||||
get(key01)(key23);
|
||||
word32 *k = m_k;
|
||||
size_t kInc = 2;
|
||||
if (!IsForwardTransformation())
|
||||
{
|
||||
k = k+30;
|
||||
kInc = 0-kInc;
|
||||
}
|
||||
|
||||
for (int i=0; i<ROUNDS; i++)
|
||||
{
|
||||
word32 t0 = word32(key01>>32) + word32(key23>>32) - s_kc[i];
|
||||
word32 t1 = word32(key01) - word32(key23) + s_kc[i];
|
||||
k[0] = G(t0);
|
||||
k[1] = G(t1);
|
||||
k+=kInc;
|
||||
if (i&1)
|
||||
key23 = rotlFixed<word64>(key23, 8);
|
||||
else
|
||||
key01 = rotrFixed<word64>(key01, 8);
|
||||
}
|
||||
}
|
||||
|
||||
void SEED::Base::ProcessAndXorBlock(const byte *inBlock, const byte *xorBlock, byte *outBlock) const
|
||||
{
|
||||
typedef BlockGetAndPut<word32, BigEndian> Block;
|
||||
word32 a0, a1, b0, b1, t0, t1;
|
||||
Block::Get(inBlock)(a0)(a1)(b0)(b1);
|
||||
|
||||
for (int i=0; i<ROUNDS; i+=2)
|
||||
{
|
||||
t0 = b0 ^ m_k[2*i+0]; t1 = b1 ^ m_k[2*i+1] ^ t0;
|
||||
t1 = G(t1); t0 += t1; t0 = G(t0); t1 += t0; t1 = G(t1);
|
||||
a0 ^= t0 + t1; a1 ^= t1;
|
||||
|
||||
t0 = a0 ^ m_k[2*i+2]; t1 = a1 ^ m_k[2*i+3] ^ t0;
|
||||
t1 = G(t1); t0 += t1; t0 = G(t0); t1 += t0; t1 = G(t1);
|
||||
b0 ^= t0 + t1; b1 ^= t1;
|
||||
}
|
||||
|
||||
Block::Put(xorBlock, outBlock)(b0)(b1)(a0)(a1);
|
||||
}
|
||||
|
||||
NAMESPACE_END
|
||||
|
@ -1,21 +1,21 @@
|
||||
Copyright (C) 1994-2008 Lua.org, PUC-Rio.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Copyright (C) 1994-2008 Lua.org, PUC-Rio.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
||||
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
||||
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
|
||||
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
|
||||
OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
@ -1,27 +1,27 @@
|
||||
/************************************************************************
|
||||
* lsqlite3 *
|
||||
* Copyright (C) 2002-2013 Tiago Dionizio, Doug Currie *
|
||||
* All rights reserved. *
|
||||
* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> *
|
||||
* Author : Doug Currie <doug.currie@alum.mit.edu> *
|
||||
* Library : lsqlite3 - a SQLite 3 database binding for Lua 5 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining *
|
||||
* a copy of this software and associated documentation files (the *
|
||||
* "Software"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to *
|
||||
* the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be *
|
||||
* included in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, *
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
************************************************************************/
|
||||
/************************************************************************
|
||||
* lsqlite3 *
|
||||
* Copyright (C) 2002-2013 Tiago Dionizio, Doug Currie *
|
||||
* All rights reserved. *
|
||||
* Author : Tiago Dionizio <tiago.dionizio@ist.utl.pt> *
|
||||
* Author : Doug Currie <doug.currie@alum.mit.edu> *
|
||||
* Library : lsqlite3 - a SQLite 3 database binding for Lua 5 *
|
||||
* *
|
||||
* Permission is hereby granted, free of charge, to any person obtaining *
|
||||
* a copy of this software and associated documentation files (the *
|
||||
* "Software"), to deal in the Software without restriction, including *
|
||||
* without limitation the rights to use, copy, modify, merge, publish, *
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to *
|
||||
* permit persons to whom the Software is furnished to do so, subject to *
|
||||
* the following conditions: *
|
||||
* *
|
||||
* The above copyright notice and this permission notice shall be *
|
||||
* included in all copies or substantial portions of the Software. *
|
||||
* *
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*
|
||||
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *
|
||||
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, *
|
||||
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
|
||||
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
||||
************************************************************************/
|
||||
|
@ -1,43 +1,43 @@
|
||||
// The Mersenne Twister is an algorithm for generating random numbers. It
|
||||
// was designed with consideration of the flaws in various other generators.
|
||||
// The period, 2^19937-1, and the order of equidistribution, 623 dimensions,
|
||||
// are far greater. The generator is also fast; it avoids multiplication and
|
||||
// division, and it benefits from caches and pipelines. For more information
|
||||
// see the inventors' web page at
|
||||
// http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
||||
|
||||
// Reference
|
||||
// M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
|
||||
// Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on
|
||||
// Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
|
||||
|
||||
// Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
||||
// Copyright (C) 2000 - 2009, Richard J. Wagner
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. The names of its contributors may not be used to endorse or promote
|
||||
// products derived from this software without specific prior written
|
||||
// permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// The Mersenne Twister is an algorithm for generating random numbers. It
|
||||
// was designed with consideration of the flaws in various other generators.
|
||||
// The period, 2^19937-1, and the order of equidistribution, 623 dimensions,
|
||||
// are far greater. The generator is also fast; it avoids multiplication and
|
||||
// division, and it benefits from caches and pipelines. For more information
|
||||
// see the inventors' web page at
|
||||
// http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
||||
|
||||
// Reference
|
||||
// M. Matsumoto and T. Nishimura, "Mersenne Twister: A 623-Dimensionally
|
||||
// Equidistributed Uniform Pseudo-Random Number Generator", ACM Transactions on
|
||||
// Modeling and Computer Simulation, Vol. 8, No. 1, January 1998, pp 3-30.
|
||||
|
||||
// Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
||||
// Copyright (C) 2000 - 2009, Richard J. Wagner
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
//
|
||||
// 3. The names of its contributors may not be used to endorse or promote
|
||||
// products derived from this software without specific prior written
|
||||
// permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
// POSSIBILITY OF SUCH DAMAGE.
|
@ -1,18 +1,18 @@
|
||||
..\MCServer\MCServer.exe
|
||||
..\MCServer\Plugins
|
||||
..\MCServer\webadmin
|
||||
..\MCServer\crafting.txt
|
||||
..\MCServer\furnace.txt
|
||||
..\MCServer\items.ini
|
||||
..\MCServer\monsters.ini
|
||||
MCServer*debug.cmd
|
||||
banned.example.ini
|
||||
groups.example.ini
|
||||
Lua-LICENSE.txt
|
||||
LuaExpat-license.html
|
||||
LuaSQLite3-LICENSE.txt
|
||||
MersenneTwister-LICENSE.txt
|
||||
settings.example.ini
|
||||
users.example.ini
|
||||
webadmin.example.ini
|
||||
..\MCServer\MCServer.exe
|
||||
..\MCServer\Plugins
|
||||
..\MCServer\webadmin
|
||||
..\MCServer\crafting.txt
|
||||
..\MCServer\furnace.txt
|
||||
..\MCServer\items.ini
|
||||
..\MCServer\monsters.ini
|
||||
MCServer*debug.cmd
|
||||
banned.example.ini
|
||||
groups.example.ini
|
||||
Lua-LICENSE.txt
|
||||
LuaExpat-license.html
|
||||
LuaSQLite3-LICENSE.txt
|
||||
MersenneTwister-LICENSE.txt
|
||||
settings.example.ini
|
||||
users.example.ini
|
||||
webadmin.example.ini
|
||||
whitelist.example.ini
|
@ -1,8 +1,8 @@
|
||||
MCServer\*.pdb
|
||||
VC2008\Release\*.pdb
|
||||
VC2008\Release\JsonCpp\*.pdb
|
||||
VC2008\Release\Lua\*.pdb
|
||||
VC2008\Release\ToLua\*.pdb
|
||||
VC2008\Release\webserver\*.pdb
|
||||
VC2008\Release\zlib\*.pdb
|
||||
MCServer\*.pdb
|
||||
VC2008\Release\*.pdb
|
||||
VC2008\Release\JsonCpp\*.pdb
|
||||
VC2008\Release\Lua\*.pdb
|
||||
VC2008\Release\ToLua\*.pdb
|
||||
VC2008\Release\webserver\*.pdb
|
||||
VC2008\Release\zlib\*.pdb
|
||||
source\Bindings.*
|
@ -1,3 +1,3 @@
|
||||
[Banned]
|
||||
;PlayerName=1
|
||||
|
||||
[Banned]
|
||||
;PlayerName=1
|
||||
|
||||
|
@ -1,17 +1,17 @@
|
||||
[Admins]
|
||||
Permissions=*
|
||||
Color=c
|
||||
|
||||
[Mods]
|
||||
Color=5
|
||||
Inherits=Vips
|
||||
Permissions=core.time,core.item
|
||||
|
||||
[Vips]
|
||||
Permissions=core.teleport
|
||||
Color=2
|
||||
Inherits=Default
|
||||
|
||||
[Default]
|
||||
Permissions=core.build,core.help,core.playerlist,core.pluginlist,core.spawn
|
||||
[Admins]
|
||||
Permissions=*
|
||||
Color=c
|
||||
|
||||
[Mods]
|
||||
Color=5
|
||||
Inherits=Vips
|
||||
Permissions=core.time,core.item
|
||||
|
||||
[Vips]
|
||||
Permissions=core.teleport
|
||||
Color=2
|
||||
Inherits=Default
|
||||
|
||||
[Default]
|
||||
Permissions=core.build,core.help,core.playerlist,core.pluginlist,core.spawn
|
||||
Color=7
|
@ -1,31 +1,31 @@
|
||||
[Server]
|
||||
Port=25565
|
||||
MaxPlayers=42
|
||||
Description=MCServer - Slightly more custom!
|
||||
|
||||
[Worlds]
|
||||
DefaultWorld=world
|
||||
;World=world_sexy
|
||||
|
||||
[Plugins]
|
||||
NewPlugin=Core
|
||||
NewPlugin=ChatLog
|
||||
|
||||
[HelpPlugin]
|
||||
ShowPluginNames=1
|
||||
|
||||
[Physics]
|
||||
Water=0
|
||||
|
||||
[Redstone]
|
||||
SimulateRedstone=0
|
||||
|
||||
[Monsters]
|
||||
AnimalsOn=0
|
||||
AnimalSpawnInterval=10
|
||||
Types=Spider,Chicken,Cow,Pig,Sheep,Squid,Enderman,Zombiepigman,Cavespider,Creeper,Ghast,Silverfish,Skeleton,Slime,Spider,Zombie
|
||||
|
||||
[Authentication]
|
||||
Server=session.minecraft.net
|
||||
Address=/game/checkserver.jsp?user=%USERNAME%&serverId=%SERVERID%
|
||||
Authenticate=0
|
||||
[Server]
|
||||
Port=25565
|
||||
MaxPlayers=42
|
||||
Description=MCServer - Slightly more custom!
|
||||
|
||||
[Worlds]
|
||||
DefaultWorld=world
|
||||
;World=world_sexy
|
||||
|
||||
[Plugins]
|
||||
NewPlugin=Core
|
||||
NewPlugin=ChatLog
|
||||
|
||||
[HelpPlugin]
|
||||
ShowPluginNames=1
|
||||
|
||||
[Physics]
|
||||
Water=0
|
||||
|
||||
[Redstone]
|
||||
SimulateRedstone=0
|
||||
|
||||
[Monsters]
|
||||
AnimalsOn=0
|
||||
AnimalSpawnInterval=10
|
||||
Types=Spider,Chicken,Cow,Pig,Sheep,Squid,Enderman,Zombiepigman,Cavespider,Creeper,Ghast,Silverfish,Skeleton,Slime,Spider,Zombie
|
||||
|
||||
[Authentication]
|
||||
Server=session.minecraft.net
|
||||
Address=/game/checkserver.jsp?user=%USERNAME%&serverId=%SERVERID%
|
||||
Authenticate=0
|
||||
|
@ -1,8 +1,8 @@
|
||||
[SomeAdmin]
|
||||
Groups=Admins
|
||||
|
||||
[FancyModerator]
|
||||
Groups=Moderators
|
||||
|
||||
[ImportantPerson]
|
||||
[SomeAdmin]
|
||||
Groups=Admins
|
||||
|
||||
[FancyModerator]
|
||||
Groups=Moderators
|
||||
|
||||
[ImportantPerson]
|
||||
Groups=Vips
|
@ -1,6 +1,6 @@
|
||||
[WebAdmin]
|
||||
Enabled=1
|
||||
Port=8080
|
||||
|
||||
[User:admin]
|
||||
[WebAdmin]
|
||||
Enabled=1
|
||||
Port=8080
|
||||
|
||||
[User:admin]
|
||||
Password=admin
|
@ -1,6 +1,6 @@
|
||||
[WhiteListSettings]
|
||||
WhiteListOn=0
|
||||
|
||||
[WhiteList]
|
||||
;PlayerName=1
|
||||
|
||||
[WhiteListSettings]
|
||||
WhiteListOn=0
|
||||
|
||||
[WhiteList]
|
||||
;PlayerName=1
|
||||
|
||||
|
@ -1,32 +1,32 @@
|
||||
|
||||
-- plugin.lua
|
||||
|
||||
-- Implements the main entrypoint for the plugin, as well as all the handling needed
|
||||
|
||||
-- ChatLog plugin logs all chat messages into the server log
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function Initialize(Plugin)
|
||||
Plugin:SetName("ChatLog")
|
||||
Plugin:SetVersion(3)
|
||||
|
||||
PluginManager = cRoot:Get():GetPluginManager()
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT)
|
||||
|
||||
LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChat(Player, Message)
|
||||
-- Lets get loggin'
|
||||
LOGINFO("[" .. Player:GetName() .. "]: " .. StripColorCodes(Message));
|
||||
|
||||
return false
|
||||
|
||||
-- plugin.lua
|
||||
|
||||
-- Implements the main entrypoint for the plugin, as well as all the handling needed
|
||||
|
||||
-- ChatLog plugin logs all chat messages into the server log
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function Initialize(Plugin)
|
||||
Plugin:SetName("ChatLog")
|
||||
Plugin:SetVersion(3)
|
||||
|
||||
PluginManager = cRoot:Get():GetPluginManager()
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT)
|
||||
|
||||
LOG("Initialized " .. Plugin:GetName() .. " v." .. Plugin:GetVersion())
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChat(Player, Message)
|
||||
-- Lets get loggin'
|
||||
LOGINFO("[" .. Player:GetName() .. "]: " .. StripColorCodes(Message));
|
||||
|
||||
return false
|
||||
end
|
@ -1,257 +1,257 @@
|
||||
local function Buttons_Player( Name )
|
||||
return "<form method='POST'><input type='hidden' name='PlayerName' value='"..Name.."'><input type='submit' name='PlayerExact' value='Exact'><input type='submit' name='Player3x3' value='3x3'></form>"
|
||||
end
|
||||
|
||||
local function Button_World( Name )
|
||||
return "<form method='POST'><input type='hidden' name='WorldName' value='"..Name.."'><input type='submit' name='SelectWorld' value='Select'></form>"
|
||||
end
|
||||
|
||||
function HandleRequest_Generation( Request )
|
||||
local Content = ""
|
||||
if (Request.PostParams["AGHRRRR"] ~= nil) then
|
||||
GENERATION_STATE = 0
|
||||
WW_instance:SaveAllChunks()
|
||||
WW_instance:UnloadUnusedChunks()
|
||||
LOGERROR("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": works ABORTED by admin")
|
||||
end
|
||||
--Content = Content .. "<head><meta http-equiv=\"refresh\" content=\"2;\"></head>"
|
||||
-- PROCESSING
|
||||
--------------------------------------------------------------------------------------------------
|
||||
local function ProcessingContent()
|
||||
local _small_content = ""
|
||||
_small_content = _small_content .. "<head><meta http-equiv=\"refresh\" content=\"2;\"></head>"
|
||||
_small_content = _small_content .. "<h4>World for operations:</h4>"..WORK_WORLD
|
||||
if (OPERATION_CODE == 0) then
|
||||
_small_content = _small_content .. "<h4>Operation:</h4>Generation"
|
||||
elseif (OPERATION_CODE == 1) then
|
||||
_small_content = _small_content .. "<h4>Operation:</h4>Regeneration"
|
||||
end
|
||||
_small_content = _small_content .. "<h4>Area: </h4>["..AreaStartX..":"..AreaStartZ.."] ["..AreaEndX..":"..AreaEndZ.."]"
|
||||
_small_content = _small_content .. "<h4>Progress:</h4>"..CURRENT.."/"..TOTAL
|
||||
_small_content = _small_content .. "<br>"
|
||||
_small_content = _small_content .. "<form method='POST'>"
|
||||
_small_content = _small_content .. "<input type='submit' name='AGHRRRR' value='Stop'>"
|
||||
_small_content = _small_content .. "</form>"
|
||||
return _small_content
|
||||
end
|
||||
if (GENERATION_STATE == 2 or GENERATION_STATE == 4) then
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
-- SELECTING
|
||||
--------------------------------------------------------------------------------------------------
|
||||
if ( Request.PostParams["FormSetWorld"] ) then
|
||||
WORK_WORLD = Request.PostParams["FormWorldName"]
|
||||
WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
|
||||
end
|
||||
|
||||
if( Request.PostParams["SelectWorld"] ~= nil
|
||||
and Request.PostParams["WorldName"] ~= nil ) then -- World is selected!
|
||||
WORK_WORLD = Request.PostParams["WorldName"]
|
||||
WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
|
||||
end
|
||||
|
||||
if(Request.PostParams["OperationGenerate"] ~= nil) then
|
||||
OPERATION_CODE = 0
|
||||
end
|
||||
if(Request.PostParams["OperationReGenerate"] ~= nil) then
|
||||
OPERATION_CODE = 1
|
||||
end
|
||||
|
||||
if (GENERATION_STATE == 0) then
|
||||
if( Request.PostParams["FormAreaStartX"] ~= nil
|
||||
and Request.PostParams["FormAreaStartZ"] ~= nil
|
||||
and Request.PostParams["FormAreaEndX"] ~= nil
|
||||
and Request.PostParams["FormAreaEndZ"] ~= nil ) then --(Re)Generation valid!
|
||||
-- COMMON (Re)gen
|
||||
if( Request.PostParams["StartArea"]) then
|
||||
AreaStartX = tonumber(Request.PostParams["FormAreaStartX"])
|
||||
AreaStartZ = tonumber(Request.PostParams["FormAreaStartZ"])
|
||||
AreaEndX = tonumber(Request.PostParams["FormAreaEndX"])
|
||||
AreaEndZ = tonumber(Request.PostParams["FormAreaEndZ"])
|
||||
|
||||
PLUGIN.IniFile:DeleteValue("Area data", "StartX")
|
||||
PLUGIN.IniFile:DeleteValue("Area data", "StartZ")
|
||||
PLUGIN.IniFile:DeleteValue("Area data", "EndX")
|
||||
PLUGIN.IniFile:DeleteValue("Area data", "EndZ")
|
||||
PLUGIN.IniFile:SetValueI("Area data", "StartX", AreaStartX)
|
||||
PLUGIN.IniFile:SetValueI("Area data", "StartZ", AreaStartZ)
|
||||
PLUGIN.IniFile:SetValueI("Area data", "EndX", AreaEndX)
|
||||
PLUGIN.IniFile:SetValueI("Area data", "EndZ", AreaEndZ)
|
||||
if (OPERATION_CODE == 0) then
|
||||
GENERATION_STATE = 1
|
||||
elseif (OPERATION_CODE == 1) then
|
||||
GENERATION_STATE = 3
|
||||
end
|
||||
PLUGIN.IniFile:WriteFile()
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
end
|
||||
if( Request.PostParams["FormRadialX"] ~= nil
|
||||
and Request.PostParams["FormRadialZ"] ~= nil
|
||||
and Request.PostParams["FormRadius"] ~= nil ) then --(Re)Generation valid!
|
||||
-- COMMON (Re)gen
|
||||
if( Request.PostParams["StartRadial"]) then
|
||||
RadialX = tonumber(Request.PostParams["FormRadialX"])
|
||||
RadialZ = tonumber(Request.PostParams["FormRadialZ"])
|
||||
Radius = tonumber(Request.PostParams["FormRadius"])
|
||||
AreaStartX = RadialX - Radius
|
||||
AreaStartZ = RadialZ - Radius
|
||||
AreaEndX = RadialX + Radius
|
||||
AreaEndZ = RadialZ + Radius
|
||||
|
||||
PLUGIN.IniFile:DeleteValue("Radial data", "RadialX")
|
||||
PLUGIN.IniFile:DeleteValue("Radial data", "RadialZ")
|
||||
PLUGIN.IniFile:DeleteValue("Radial data", "Radius")
|
||||
PLUGIN.IniFile:SetValueI("Radial data", "RadialX", RadialX)
|
||||
PLUGIN.IniFile:SetValueI("Radial data", "RadialZ", RadialZ)
|
||||
PLUGIN.IniFile:SetValueI("Radial data", "Radius", Radius)
|
||||
if (OPERATION_CODE == 0) then
|
||||
GENERATION_STATE = 1
|
||||
elseif (OPERATION_CODE == 1) then
|
||||
GENERATION_STATE = 3
|
||||
end
|
||||
PLUGIN.IniFile:WriteFile()
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
end
|
||||
-- POINT REGEN!
|
||||
if( Request.PostParams["FormPointX"] ~= nil
|
||||
and Request.PostParams["FormPointZ"] ~= nil ) then --ReGeneration valid!
|
||||
-- EXACT
|
||||
if ( Request.PostParams["PointExact"] ~= nil) then
|
||||
AreaStartX = tonumber(Request.PostParams["FormPointX"])
|
||||
AreaStartZ = tonumber(Request.PostParams["FormPointZ"])
|
||||
AreaEndX = AreaStartX
|
||||
AreaEndZ = AreaStartZ
|
||||
GENERATION_STATE = 3
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
-- 3x3
|
||||
if ( Request.PostParams["Point3x3"] ~= nil) then
|
||||
AreaStartX = tonumber(Request.PostParams["FormPointX"]) - 1
|
||||
AreaStartZ = tonumber(Request.PostParams["FormPointZ"]) - 1
|
||||
AreaEndX = AreaStartX + 2
|
||||
AreaEndZ = AreaStartZ + 2
|
||||
GENERATION_STATE = 3
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
end
|
||||
|
||||
local GetAreaByPlayer = function(Player)
|
||||
-- Player is valid only within this function, it cannot be stord and used later!
|
||||
AreaStartX = Player:GetChunkX()
|
||||
AreaStartZ = Player:GetChunkZ()
|
||||
end
|
||||
-- PLAYERS REGEN!
|
||||
if( Request.PostParams["PlayerExact"] ~= nil
|
||||
and Request.PostParams["PlayerName"] ~= nil ) then -- Making BOOM! I meant, regenereate...
|
||||
cRoot:Get():GetWorld(WORK_WORLD):DoWithPlayer(Request.PostParams["PlayerName"],GetAreaByPlayer)
|
||||
AreaEndX = AreaStartX
|
||||
AreaEndZ = AreaStartZ
|
||||
GENERATION_STATE = 3
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
if( Request.PostParams["Player3x3"] ~= nil
|
||||
and Request.PostParams["PlayerName"] ~= nil ) then -- Making BOOM! I meant, regenereate...
|
||||
cRoot:Get():GetWorld(WORK_WORLD):DoWithPlayer(Request.PostParams["PlayerName"],GetAreaByPlayer)
|
||||
AreaStartX = AreaStartX - 1
|
||||
AreaStartZ = AreaStartZ - 1
|
||||
AreaEndX = AreaStartX + 2
|
||||
AreaEndZ = AreaStartZ + 2
|
||||
GENERATION_STATE = 3
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
end
|
||||
|
||||
--Content = Content .. "<h4>World for operations: " .. WORK_WORLD .. "</h4>"
|
||||
--Content = Content .. "<form method='POST'>"
|
||||
--Content = Content .. "<input type='text' name='FormWorldName' value='Input world name here'><input type='submit' name='FormSetWorld' value='Set world'>"
|
||||
--Content = Content .. "</form>"
|
||||
|
||||
-- SELECTING WORK_WORLD
|
||||
Content = Content .. "<h4>World for operations: " .. WORK_WORLD .. "</h4>"
|
||||
Content = Content .. "<table>"
|
||||
local WorldNum = 0
|
||||
local AddWorldToTable = function(World)
|
||||
WorldNum = WorldNum + 1
|
||||
Content = Content .. "<tr>"
|
||||
Content = Content .. "<td style='width: 10px;'>" .. WorldNum .. ".</td>"
|
||||
Content = Content .. "<td>" .. World:GetName() .. "</td>"
|
||||
Content = Content .. "<td>" .. Button_World(World:GetName()) .. "</td>"
|
||||
Content = Content .. "</tr>"
|
||||
end
|
||||
cRoot:Get():ForEachWorld(AddWorldToTable)
|
||||
if( WorldNum == 0 ) then
|
||||
Content = Content .. "<tr><td>No worlds! O_O</td></tr>"
|
||||
end
|
||||
Content = Content .. "</table>"
|
||||
Content = Content .. "<br>"
|
||||
|
||||
-- SELECTING OPERATION
|
||||
if (OPERATION_CODE == 0) then
|
||||
Content = Content .. "<h4>Operation: Generation</h4>"
|
||||
elseif (OPERATION_CODE == 1) then
|
||||
Content = Content .. "<h4>Operation: Regeneration</h4>"
|
||||
end
|
||||
Content = Content .. "<form method='POST'>"
|
||||
Content = Content .. "<input type='submit' name='OperationGenerate' value='Generation'>"
|
||||
Content = Content .. "<input type='submit' name='OperationReGenerate' value='Regeneration'>"
|
||||
Content = Content .. "</form>"
|
||||
|
||||
-- SELECTING AREA
|
||||
Content = Content .. "<h4>Area: </h4>Start X, Start Z; End X, End Z"
|
||||
Content = Content .. "<form method='POST'>"
|
||||
Content = Content .. "<input type='text' name='FormAreaStartX' value='" .. AreaStartX .. "'><input type='text' name='FormAreaStartZ' value='" .. AreaStartZ .. "'>"
|
||||
Content = Content .. "<input type='text' name='FormAreaEndX' value='" .. AreaEndX .. "'><input type='text' name='FormAreaEndZ' value='" .. AreaEndZ .. "'>"
|
||||
Content = Content .. "<input type='submit' name='StartArea' value='Start'>"
|
||||
Content = Content .. "</form>"
|
||||
|
||||
-- SELECTING RADIAL
|
||||
Content = Content .. "<h4>Radial: </h4>Center X, Center Z, Raduis (0 to any)"
|
||||
Content = Content .. "<form method='POST'>"
|
||||
Content = Content .. "<input type='text' name='FormRadialX' value='" .. RadialX .. "'><input type='text' name='FormRadialZ' value='" .. RadialZ .. "'><input type='text' name='FormRadius' value='" .. Radius .. "'>"
|
||||
Content = Content .. "<input type='submit' name='StartRadial' value='Start'>"
|
||||
Content = Content .. "</form>"
|
||||
Content = Content .. "<br>"
|
||||
Content = Content .. "<br>"
|
||||
Content = Content .. "<br>"
|
||||
|
||||
-- SELECTING POINT
|
||||
Content = Content .. "<h4>Point regeneration:</h4> X, Z"
|
||||
Content = Content .. "<form method='POST'>"
|
||||
Content = Content .. "<input type='text' name='FormPointX' value='0'><input type='text' name='FormPointZ' value='0'>"
|
||||
Content = Content .. "<input type='submit' name='PointExact' value='Exact'>"
|
||||
Content = Content .. "<input type='submit' name='Point3x3' value='3x3'>"
|
||||
Content = Content .. "</form>"
|
||||
|
||||
-- SELECTING PLAYERS
|
||||
Content = Content .. "<h4>Player-based regeneration:</h4>"
|
||||
Content = Content .. "<table>"
|
||||
local PlayerNum = 0
|
||||
local AddPlayerToTable = function( Player )
|
||||
PlayerNum = PlayerNum + 1
|
||||
Content = Content .. "<tr>"
|
||||
Content = Content .. "<td style='width: 10px;'>" .. PlayerNum .. ".</td>"
|
||||
Content = Content .. "<td>" .. Player:GetName() .. "</td>"
|
||||
Content = Content .. "<td>" .. Buttons_Player(Player:GetName()) .. "</td>"
|
||||
Content = Content .. "</tr>"
|
||||
end
|
||||
if (cRoot:Get():GetWorld(WORK_WORLD) == nil) then
|
||||
Content = Content .. "<tr><td>Incorrect world selection</td></tr>"
|
||||
else
|
||||
cRoot:Get():GetWorld(WORK_WORLD):ForEachPlayer( AddPlayerToTable )
|
||||
if( PlayerNum == 0 ) then
|
||||
Content = Content .. "<tr><td>No connected players</td></tr>"
|
||||
end
|
||||
end
|
||||
Content = Content .. "</table>"
|
||||
Content = Content .. "<br>"
|
||||
return Content
|
||||
local function Buttons_Player( Name )
|
||||
return "<form method='POST'><input type='hidden' name='PlayerName' value='"..Name.."'><input type='submit' name='PlayerExact' value='Exact'><input type='submit' name='Player3x3' value='3x3'></form>"
|
||||
end
|
||||
|
||||
local function Button_World( Name )
|
||||
return "<form method='POST'><input type='hidden' name='WorldName' value='"..Name.."'><input type='submit' name='SelectWorld' value='Select'></form>"
|
||||
end
|
||||
|
||||
function HandleRequest_Generation( Request )
|
||||
local Content = ""
|
||||
if (Request.PostParams["AGHRRRR"] ~= nil) then
|
||||
GENERATION_STATE = 0
|
||||
WW_instance:SaveAllChunks()
|
||||
WW_instance:UnloadUnusedChunks()
|
||||
LOGERROR("" .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. ": works ABORTED by admin")
|
||||
end
|
||||
--Content = Content .. "<head><meta http-equiv=\"refresh\" content=\"2;\"></head>"
|
||||
-- PROCESSING
|
||||
--------------------------------------------------------------------------------------------------
|
||||
local function ProcessingContent()
|
||||
local _small_content = ""
|
||||
_small_content = _small_content .. "<head><meta http-equiv=\"refresh\" content=\"2;\"></head>"
|
||||
_small_content = _small_content .. "<h4>World for operations:</h4>"..WORK_WORLD
|
||||
if (OPERATION_CODE == 0) then
|
||||
_small_content = _small_content .. "<h4>Operation:</h4>Generation"
|
||||
elseif (OPERATION_CODE == 1) then
|
||||
_small_content = _small_content .. "<h4>Operation:</h4>Regeneration"
|
||||
end
|
||||
_small_content = _small_content .. "<h4>Area: </h4>["..AreaStartX..":"..AreaStartZ.."] ["..AreaEndX..":"..AreaEndZ.."]"
|
||||
_small_content = _small_content .. "<h4>Progress:</h4>"..CURRENT.."/"..TOTAL
|
||||
_small_content = _small_content .. "<br>"
|
||||
_small_content = _small_content .. "<form method='POST'>"
|
||||
_small_content = _small_content .. "<input type='submit' name='AGHRRRR' value='Stop'>"
|
||||
_small_content = _small_content .. "</form>"
|
||||
return _small_content
|
||||
end
|
||||
if (GENERATION_STATE == 2 or GENERATION_STATE == 4) then
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
-- SELECTING
|
||||
--------------------------------------------------------------------------------------------------
|
||||
if ( Request.PostParams["FormSetWorld"] ) then
|
||||
WORK_WORLD = Request.PostParams["FormWorldName"]
|
||||
WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
|
||||
end
|
||||
|
||||
if( Request.PostParams["SelectWorld"] ~= nil
|
||||
and Request.PostParams["WorldName"] ~= nil ) then -- World is selected!
|
||||
WORK_WORLD = Request.PostParams["WorldName"]
|
||||
WW_instance = cRoot:Get():GetWorld(WORK_WORLD)
|
||||
end
|
||||
|
||||
if(Request.PostParams["OperationGenerate"] ~= nil) then
|
||||
OPERATION_CODE = 0
|
||||
end
|
||||
if(Request.PostParams["OperationReGenerate"] ~= nil) then
|
||||
OPERATION_CODE = 1
|
||||
end
|
||||
|
||||
if (GENERATION_STATE == 0) then
|
||||
if( Request.PostParams["FormAreaStartX"] ~= nil
|
||||
and Request.PostParams["FormAreaStartZ"] ~= nil
|
||||
and Request.PostParams["FormAreaEndX"] ~= nil
|
||||
and Request.PostParams["FormAreaEndZ"] ~= nil ) then --(Re)Generation valid!
|
||||
-- COMMON (Re)gen
|
||||
if( Request.PostParams["StartArea"]) then
|
||||
AreaStartX = tonumber(Request.PostParams["FormAreaStartX"])
|
||||
AreaStartZ = tonumber(Request.PostParams["FormAreaStartZ"])
|
||||
AreaEndX = tonumber(Request.PostParams["FormAreaEndX"])
|
||||
AreaEndZ = tonumber(Request.PostParams["FormAreaEndZ"])
|
||||
|
||||
PLUGIN.IniFile:DeleteValue("Area data", "StartX")
|
||||
PLUGIN.IniFile:DeleteValue("Area data", "StartZ")
|
||||
PLUGIN.IniFile:DeleteValue("Area data", "EndX")
|
||||
PLUGIN.IniFile:DeleteValue("Area data", "EndZ")
|
||||
PLUGIN.IniFile:SetValueI("Area data", "StartX", AreaStartX)
|
||||
PLUGIN.IniFile:SetValueI("Area data", "StartZ", AreaStartZ)
|
||||
PLUGIN.IniFile:SetValueI("Area data", "EndX", AreaEndX)
|
||||
PLUGIN.IniFile:SetValueI("Area data", "EndZ", AreaEndZ)
|
||||
if (OPERATION_CODE == 0) then
|
||||
GENERATION_STATE = 1
|
||||
elseif (OPERATION_CODE == 1) then
|
||||
GENERATION_STATE = 3
|
||||
end
|
||||
PLUGIN.IniFile:WriteFile()
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
end
|
||||
if( Request.PostParams["FormRadialX"] ~= nil
|
||||
and Request.PostParams["FormRadialZ"] ~= nil
|
||||
and Request.PostParams["FormRadius"] ~= nil ) then --(Re)Generation valid!
|
||||
-- COMMON (Re)gen
|
||||
if( Request.PostParams["StartRadial"]) then
|
||||
RadialX = tonumber(Request.PostParams["FormRadialX"])
|
||||
RadialZ = tonumber(Request.PostParams["FormRadialZ"])
|
||||
Radius = tonumber(Request.PostParams["FormRadius"])
|
||||
AreaStartX = RadialX - Radius
|
||||
AreaStartZ = RadialZ - Radius
|
||||
AreaEndX = RadialX + Radius
|
||||
AreaEndZ = RadialZ + Radius
|
||||
|
||||
PLUGIN.IniFile:DeleteValue("Radial data", "RadialX")
|
||||
PLUGIN.IniFile:DeleteValue("Radial data", "RadialZ")
|
||||
PLUGIN.IniFile:DeleteValue("Radial data", "Radius")
|
||||
PLUGIN.IniFile:SetValueI("Radial data", "RadialX", RadialX)
|
||||
PLUGIN.IniFile:SetValueI("Radial data", "RadialZ", RadialZ)
|
||||
PLUGIN.IniFile:SetValueI("Radial data", "Radius", Radius)
|
||||
if (OPERATION_CODE == 0) then
|
||||
GENERATION_STATE = 1
|
||||
elseif (OPERATION_CODE == 1) then
|
||||
GENERATION_STATE = 3
|
||||
end
|
||||
PLUGIN.IniFile:WriteFile()
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
end
|
||||
-- POINT REGEN!
|
||||
if( Request.PostParams["FormPointX"] ~= nil
|
||||
and Request.PostParams["FormPointZ"] ~= nil ) then --ReGeneration valid!
|
||||
-- EXACT
|
||||
if ( Request.PostParams["PointExact"] ~= nil) then
|
||||
AreaStartX = tonumber(Request.PostParams["FormPointX"])
|
||||
AreaStartZ = tonumber(Request.PostParams["FormPointZ"])
|
||||
AreaEndX = AreaStartX
|
||||
AreaEndZ = AreaStartZ
|
||||
GENERATION_STATE = 3
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
-- 3x3
|
||||
if ( Request.PostParams["Point3x3"] ~= nil) then
|
||||
AreaStartX = tonumber(Request.PostParams["FormPointX"]) - 1
|
||||
AreaStartZ = tonumber(Request.PostParams["FormPointZ"]) - 1
|
||||
AreaEndX = AreaStartX + 2
|
||||
AreaEndZ = AreaStartZ + 2
|
||||
GENERATION_STATE = 3
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
end
|
||||
|
||||
local GetAreaByPlayer = function(Player)
|
||||
-- Player is valid only within this function, it cannot be stord and used later!
|
||||
AreaStartX = Player:GetChunkX()
|
||||
AreaStartZ = Player:GetChunkZ()
|
||||
end
|
||||
-- PLAYERS REGEN!
|
||||
if( Request.PostParams["PlayerExact"] ~= nil
|
||||
and Request.PostParams["PlayerName"] ~= nil ) then -- Making BOOM! I meant, regenereate...
|
||||
cRoot:Get():GetWorld(WORK_WORLD):DoWithPlayer(Request.PostParams["PlayerName"],GetAreaByPlayer)
|
||||
AreaEndX = AreaStartX
|
||||
AreaEndZ = AreaStartZ
|
||||
GENERATION_STATE = 3
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
if( Request.PostParams["Player3x3"] ~= nil
|
||||
and Request.PostParams["PlayerName"] ~= nil ) then -- Making BOOM! I meant, regenereate...
|
||||
cRoot:Get():GetWorld(WORK_WORLD):DoWithPlayer(Request.PostParams["PlayerName"],GetAreaByPlayer)
|
||||
AreaStartX = AreaStartX - 1
|
||||
AreaStartZ = AreaStartZ - 1
|
||||
AreaEndX = AreaStartX + 2
|
||||
AreaEndZ = AreaStartZ + 2
|
||||
GENERATION_STATE = 3
|
||||
Content = ProcessingContent()
|
||||
return Content
|
||||
end
|
||||
end
|
||||
|
||||
--Content = Content .. "<h4>World for operations: " .. WORK_WORLD .. "</h4>"
|
||||
--Content = Content .. "<form method='POST'>"
|
||||
--Content = Content .. "<input type='text' name='FormWorldName' value='Input world name here'><input type='submit' name='FormSetWorld' value='Set world'>"
|
||||
--Content = Content .. "</form>"
|
||||
|
||||
-- SELECTING WORK_WORLD
|
||||
Content = Content .. "<h4>World for operations: " .. WORK_WORLD .. "</h4>"
|
||||
Content = Content .. "<table>"
|
||||
local WorldNum = 0
|
||||
local AddWorldToTable = function(World)
|
||||
WorldNum = WorldNum + 1
|
||||
Content = Content .. "<tr>"
|
||||
Content = Content .. "<td style='width: 10px;'>" .. WorldNum .. ".</td>"
|
||||
Content = Content .. "<td>" .. World:GetName() .. "</td>"
|
||||
Content = Content .. "<td>" .. Button_World(World:GetName()) .. "</td>"
|
||||
Content = Content .. "</tr>"
|
||||
end
|
||||
cRoot:Get():ForEachWorld(AddWorldToTable)
|
||||
if( WorldNum == 0 ) then
|
||||
Content = Content .. "<tr><td>No worlds! O_O</td></tr>"
|
||||
end
|
||||
Content = Content .. "</table>"
|
||||
Content = Content .. "<br>"
|
||||
|
||||
-- SELECTING OPERATION
|
||||
if (OPERATION_CODE == 0) then
|
||||
Content = Content .. "<h4>Operation: Generation</h4>"
|
||||
elseif (OPERATION_CODE == 1) then
|
||||
Content = Content .. "<h4>Operation: Regeneration</h4>"
|
||||
end
|
||||
Content = Content .. "<form method='POST'>"
|
||||
Content = Content .. "<input type='submit' name='OperationGenerate' value='Generation'>"
|
||||
Content = Content .. "<input type='submit' name='OperationReGenerate' value='Regeneration'>"
|
||||
Content = Content .. "</form>"
|
||||
|
||||
-- SELECTING AREA
|
||||
Content = Content .. "<h4>Area: </h4>Start X, Start Z; End X, End Z"
|
||||
Content = Content .. "<form method='POST'>"
|
||||
Content = Content .. "<input type='text' name='FormAreaStartX' value='" .. AreaStartX .. "'><input type='text' name='FormAreaStartZ' value='" .. AreaStartZ .. "'>"
|
||||
Content = Content .. "<input type='text' name='FormAreaEndX' value='" .. AreaEndX .. "'><input type='text' name='FormAreaEndZ' value='" .. AreaEndZ .. "'>"
|
||||
Content = Content .. "<input type='submit' name='StartArea' value='Start'>"
|
||||
Content = Content .. "</form>"
|
||||
|
||||
-- SELECTING RADIAL
|
||||
Content = Content .. "<h4>Radial: </h4>Center X, Center Z, Raduis (0 to any)"
|
||||
Content = Content .. "<form method='POST'>"
|
||||
Content = Content .. "<input type='text' name='FormRadialX' value='" .. RadialX .. "'><input type='text' name='FormRadialZ' value='" .. RadialZ .. "'><input type='text' name='FormRadius' value='" .. Radius .. "'>"
|
||||
Content = Content .. "<input type='submit' name='StartRadial' value='Start'>"
|
||||
Content = Content .. "</form>"
|
||||
Content = Content .. "<br>"
|
||||
Content = Content .. "<br>"
|
||||
Content = Content .. "<br>"
|
||||
|
||||
-- SELECTING POINT
|
||||
Content = Content .. "<h4>Point regeneration:</h4> X, Z"
|
||||
Content = Content .. "<form method='POST'>"
|
||||
Content = Content .. "<input type='text' name='FormPointX' value='0'><input type='text' name='FormPointZ' value='0'>"
|
||||
Content = Content .. "<input type='submit' name='PointExact' value='Exact'>"
|
||||
Content = Content .. "<input type='submit' name='Point3x3' value='3x3'>"
|
||||
Content = Content .. "</form>"
|
||||
|
||||
-- SELECTING PLAYERS
|
||||
Content = Content .. "<h4>Player-based regeneration:</h4>"
|
||||
Content = Content .. "<table>"
|
||||
local PlayerNum = 0
|
||||
local AddPlayerToTable = function( Player )
|
||||
PlayerNum = PlayerNum + 1
|
||||
Content = Content .. "<tr>"
|
||||
Content = Content .. "<td style='width: 10px;'>" .. PlayerNum .. ".</td>"
|
||||
Content = Content .. "<td>" .. Player:GetName() .. "</td>"
|
||||
Content = Content .. "<td>" .. Buttons_Player(Player:GetName()) .. "</td>"
|
||||
Content = Content .. "</tr>"
|
||||
end
|
||||
if (cRoot:Get():GetWorld(WORK_WORLD) == nil) then
|
||||
Content = Content .. "<tr><td>Incorrect world selection</td></tr>"
|
||||
else
|
||||
cRoot:Get():GetWorld(WORK_WORLD):ForEachPlayer( AddPlayerToTable )
|
||||
if( PlayerNum == 0 ) then
|
||||
Content = Content .. "<tr><td>No connected players</td></tr>"
|
||||
end
|
||||
end
|
||||
Content = Content .. "</table>"
|
||||
Content = Content .. "<br>"
|
||||
return Content
|
||||
end
|
File diff suppressed because it is too large
Load Diff
@ -1,83 +1,83 @@
|
||||
|
||||
-- DiamondMover.lua
|
||||
|
||||
-- An example Lua plugin using the cBlockArea object
|
||||
-- When a player rclks with a diamond in their hand, an area around the clicked block is moved in the direction the player is facing
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Global variables
|
||||
PLUGIN = {} -- Reference to own plugin object
|
||||
MOVER_SIZE_X = 4;
|
||||
MOVER_SIZE_Y = 4;
|
||||
MOVER_SIZE_Z = 4;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function Initialize(Plugin)
|
||||
PLUGIN = Plugin;
|
||||
|
||||
Plugin:SetName("DiamondMover");
|
||||
Plugin:SetVersion(1);
|
||||
|
||||
PluginManager = cRoot:Get():GetPluginManager();
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USED_ITEM);
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsedItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
|
||||
|
||||
-- Don't check if the direction is in the air
|
||||
if (BlockFace == -1) then
|
||||
return false;
|
||||
end;
|
||||
|
||||
if (Player:HasPermission("diamondmover.move") == false) then
|
||||
return true;
|
||||
end;
|
||||
|
||||
-- Rclk with a diamond to push in the direction the player is facing
|
||||
if (Player:GetEquippedItem().m_ItemType == E_ITEM_DIAMOND) then
|
||||
local Area = cBlockArea();
|
||||
Area:Read(Player:GetWorld(),
|
||||
BlockX - MOVER_SIZE_X, BlockX + MOVER_SIZE_X,
|
||||
BlockY - MOVER_SIZE_Y, BlockY + MOVER_SIZE_Y,
|
||||
BlockZ - MOVER_SIZE_Z, BlockZ + MOVER_SIZE_Z
|
||||
);
|
||||
|
||||
local PlayerPitch = Player:GetPitch();
|
||||
if (PlayerPitch < -70) then -- looking up
|
||||
BlockY = BlockY + 1;
|
||||
else
|
||||
if (PlayerPitch > 70) then -- looking down
|
||||
BlockY = BlockY - 1;
|
||||
else
|
||||
local PlayerRot = Player:GetRotation() + 180; -- Convert [-180, 180] into [0, 360] for simpler conditions
|
||||
if ((PlayerRot < 45) or (PlayerRot > 315)) then
|
||||
BlockZ = BlockZ - 1;
|
||||
else
|
||||
if (PlayerRot < 135) then
|
||||
BlockX = BlockX + 1;
|
||||
else
|
||||
if (PlayerRot < 225) then
|
||||
BlockZ = BlockZ + 1;
|
||||
else
|
||||
BlockX = BlockX - 1;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Area:Write(Player:GetWorld(), BlockX - MOVER_SIZE_X, BlockY - MOVER_SIZE_Y, BlockZ - MOVER_SIZE_Z);
|
||||
return false;
|
||||
end
|
||||
|
||||
-- DiamondMover.lua
|
||||
|
||||
-- An example Lua plugin using the cBlockArea object
|
||||
-- When a player rclks with a diamond in their hand, an area around the clicked block is moved in the direction the player is facing
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Global variables
|
||||
PLUGIN = {} -- Reference to own plugin object
|
||||
MOVER_SIZE_X = 4;
|
||||
MOVER_SIZE_Y = 4;
|
||||
MOVER_SIZE_Z = 4;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function Initialize(Plugin)
|
||||
PLUGIN = Plugin;
|
||||
|
||||
Plugin:SetName("DiamondMover");
|
||||
Plugin:SetVersion(1);
|
||||
|
||||
PluginManager = cRoot:Get():GetPluginManager();
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USED_ITEM);
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsedItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, CursorY, CursorZ)
|
||||
|
||||
-- Don't check if the direction is in the air
|
||||
if (BlockFace == -1) then
|
||||
return false;
|
||||
end;
|
||||
|
||||
if (Player:HasPermission("diamondmover.move") == false) then
|
||||
return true;
|
||||
end;
|
||||
|
||||
-- Rclk with a diamond to push in the direction the player is facing
|
||||
if (Player:GetEquippedItem().m_ItemType == E_ITEM_DIAMOND) then
|
||||
local Area = cBlockArea();
|
||||
Area:Read(Player:GetWorld(),
|
||||
BlockX - MOVER_SIZE_X, BlockX + MOVER_SIZE_X,
|
||||
BlockY - MOVER_SIZE_Y, BlockY + MOVER_SIZE_Y,
|
||||
BlockZ - MOVER_SIZE_Z, BlockZ + MOVER_SIZE_Z
|
||||
);
|
||||
|
||||
local PlayerPitch = Player:GetPitch();
|
||||
if (PlayerPitch < -70) then -- looking up
|
||||
BlockY = BlockY + 1;
|
||||
else
|
||||
if (PlayerPitch > 70) then -- looking down
|
||||
BlockY = BlockY - 1;
|
||||
else
|
||||
local PlayerRot = Player:GetRotation() + 180; -- Convert [-180, 180] into [0, 360] for simpler conditions
|
||||
if ((PlayerRot < 45) or (PlayerRot > 315)) then
|
||||
BlockZ = BlockZ - 1;
|
||||
else
|
||||
if (PlayerRot < 135) then
|
||||
BlockX = BlockX + 1;
|
||||
else
|
||||
if (PlayerRot < 225) then
|
||||
BlockZ = BlockZ + 1;
|
||||
else
|
||||
BlockX = BlockX - 1;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Area:Write(Player:GetWorld(), BlockX - MOVER_SIZE_X, BlockY - MOVER_SIZE_Y, BlockZ - MOVER_SIZE_Z);
|
||||
return false;
|
||||
end
|
||||
end
|
@ -1,28 +1,28 @@
|
||||
-- Global variables
|
||||
PLUGIN = {} -- Reference to own plugin object
|
||||
CHEST_WIDTH = 9
|
||||
HANDY_VERSION = 1
|
||||
--[[
|
||||
|
||||
Handy is a plugin for other plugins. It contain no commands, no hooks, but functions to ease plugins developers' life.
|
||||
|
||||
API:
|
||||
|
||||
|
||||
TODO:
|
||||
1. GetChestSlot wrapper, so it will detect double chest neighbour chest and will be able to access it.
|
||||
]]
|
||||
|
||||
function Initialize(Plugin)
|
||||
PLUGIN = Plugin
|
||||
PLUGIN:SetName("Handy")
|
||||
PLUGIN:SetVersion(HANDY_VERSION)
|
||||
|
||||
PluginManager = cRoot:Get():GetPluginManager()
|
||||
LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
|
||||
return true
|
||||
end
|
||||
|
||||
function OnDisable()
|
||||
LOG(PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " is shutting down...")
|
||||
-- Global variables
|
||||
PLUGIN = {} -- Reference to own plugin object
|
||||
CHEST_WIDTH = 9
|
||||
HANDY_VERSION = 1
|
||||
--[[
|
||||
|
||||
Handy is a plugin for other plugins. It contain no commands, no hooks, but functions to ease plugins developers' life.
|
||||
|
||||
API:
|
||||
|
||||
|
||||
TODO:
|
||||
1. GetChestSlot wrapper, so it will detect double chest neighbour chest and will be able to access it.
|
||||
]]
|
||||
|
||||
function Initialize(Plugin)
|
||||
PLUGIN = Plugin
|
||||
PLUGIN:SetName("Handy")
|
||||
PLUGIN:SetVersion(HANDY_VERSION)
|
||||
|
||||
PluginManager = cRoot:Get():GetPluginManager()
|
||||
LOG("Initialized " .. PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion())
|
||||
return true
|
||||
end
|
||||
|
||||
function OnDisable()
|
||||
LOG(PLUGIN:GetName() .. " v" .. PLUGIN:GetVersion() .. " is shutting down...")
|
||||
end
|
@ -1,355 +1,355 @@
|
||||
--[[
|
||||
General stuff
|
||||
]]
|
||||
-- Returns Handy plugin version number
|
||||
function GetHandyVersion()
|
||||
return HANDY_VERSION
|
||||
end
|
||||
-- Checks if handy is in proper version
|
||||
function CheckForRequiedVersion(IN_version)
|
||||
if (IN_version > HANDY_VERSION) then return false end
|
||||
return true
|
||||
end
|
||||
--[[
|
||||
MCS-specific _functions and nasty hacks :D
|
||||
]]
|
||||
-- There's a "GetChestHeight" function inside source code, but it's not lua-exported
|
||||
function GetChestHeightCheat(IN_chest)
|
||||
if (IN_chest:GetSlot(28) == nil) then -- this means we're trying to get double chest slot and FAIL
|
||||
LOGWARN("HANDY: single chest checked")
|
||||
return 3
|
||||
end
|
||||
LOGWARN("HANDY: double chest checked")
|
||||
return 6
|
||||
end
|
||||
-- Those two checks how many items of given IN_itemID chest and player have, and how much they could fit inside them
|
||||
function ReadChestForItem(IN_chest, IN_itemID)
|
||||
local _items_found = 0
|
||||
local _free_space = 0
|
||||
-- stalk through chest slots...
|
||||
local _slot_counter = 0
|
||||
local _slot_item
|
||||
local _item_max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
_slot_item = IN_chest:GetSlot(_slot_counter)
|
||||
if (_slot_item ~= nil) then
|
||||
if (_slot_item.m_ItemID == IN_itemID) then
|
||||
_items_found = _items_found + _slot_item.m_ItemCount
|
||||
_free_space = _free_space + (_item_max_stack - _slot_item.m_ItemCount)
|
||||
end
|
||||
if (_slot_item:IsEmpty() == true) then
|
||||
_free_space = _free_space + _item_max_stack
|
||||
end
|
||||
end
|
||||
_slot_counter = _slot_counter + 1
|
||||
if (_slot_counter == CHEST_WIDTH*GetChestHeightCheat(IN_chest)) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return _items_found, _free_space
|
||||
end
|
||||
function ReadPlayerForItem(IN_player, IN_itemID)
|
||||
local _items_found = 0
|
||||
local _free_space = 0
|
||||
-- stalk through IN_player inventory slots...
|
||||
local _slot_counter = 9
|
||||
if (ItemIsArmor(IN_itemID) == true) then _slot_counter = 5 end
|
||||
local _slot_item
|
||||
local _item_max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
_slot_item = IN_player:GetInventory():GetSlot(_slot_counter)
|
||||
if (_slot_item ~= nil) then
|
||||
if (_slot_item.m_ItemID == IN_itemID) then
|
||||
_items_found = _items_found + _slot_item.m_ItemCount
|
||||
_free_space = _free_space + (_item_max_stack - _slot_item.m_ItemCount)
|
||||
end
|
||||
if (_slot_item:IsEmpty() == true) then
|
||||
_free_space = _free_space + _item_max_stack
|
||||
end
|
||||
end
|
||||
_slot_counter = _slot_counter + 1
|
||||
if (_slot_counter == 45) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return _items_found, _free_space
|
||||
end
|
||||
-- Following functions are for chest-related operations (since noone was bothered writing them in MCS code)
|
||||
-- BEWARE! Those assume you did checked if chest has items/space in it!
|
||||
function TakeItemsFromChest(IN_chest, IN_itemID, IN_ammount) -- UNSAFE! CHECK FOR ITEMS FIRST!!
|
||||
-- stalk through chest slots...
|
||||
local _slot_counter = 0
|
||||
local _slot_item
|
||||
local _take_count = IN_ammount
|
||||
while true do
|
||||
_slot_item = IN_chest:GetSlot(_slot_counter)
|
||||
if (_slot_item ~= nil) then
|
||||
if (_slot_item.m_ItemID == IN_itemID) then
|
||||
-- assuming player have enought money
|
||||
if (_take_count > 0) then
|
||||
if (_take_count > _slot_item.m_ItemCount) then
|
||||
_take_count = _take_count - _slot_item.m_ItemCount
|
||||
IN_chest:SetSlot(_slot_counter, cItem()) -- a bit hacky, can't make cItem:Clear() work(
|
||||
else
|
||||
local _left_count = _slot_item.m_ItemCount - _take_count
|
||||
IN_chest:SetSlot(_slot_counter, cItem(_slot_item.m_ItemID, _left_count)) -- a bit hacky
|
||||
_take_count = 0
|
||||
end
|
||||
end
|
||||
if (_take_count == 0) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
_slot_counter = _slot_counter + 1
|
||||
if (_slot_counter == CHEST_WIDTH*GetChestHeightCheat(IN_chest)) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
function PutItemsToChest(IN_chest, IN_itemID, IN_ammount) -- UNSAFE! CHECK FOR SPACE FIRST!!
|
||||
-- stalk through chest slots...
|
||||
local _slot_counter = 0
|
||||
local _slot_item
|
||||
local _put_count = IN_ammount
|
||||
local _max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
_slot_item = IN_chest:GetSlot(_slot_counter)
|
||||
local _portion = 0
|
||||
local _ammount_to_set = 0
|
||||
if (_slot_item ~= nil) then
|
||||
if (_slot_item:IsEmpty() == true) then
|
||||
_portion = math.min(_max_stack, _put_count)
|
||||
_ammount_to_set = _portion
|
||||
else
|
||||
if (_slot_item.m_ItemID == IN_itemID) then
|
||||
-- choose between how much we need to put and how much free space left
|
||||
_portion = math.min(_put_count, _max_stack - _slot_item.m_ItemCount)
|
||||
_ammount_to_set = _slot_item.m_ItemCount + _portion
|
||||
end
|
||||
end
|
||||
end
|
||||
IN_chest:SetSlot(_slot_counter, cItem(IN_itemID, _ammount_to_set)) -- we add max stack to chest
|
||||
_put_count = _put_count - _portion
|
||||
if (_put_count == 0) then break end
|
||||
_slot_counter = _slot_counter + 1
|
||||
if (_slot_counter == CHEST_WIDTH*GetChestHeightCheat(IN_chest)) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Similar to chest-related.
|
||||
function TakeItemsFromPlayer(IN_player, IN_itemID, IN_ammount) -- UNSAFE! CHECK FIRST!
|
||||
local _put_count = IN_ammount
|
||||
local _max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
local _portion = math.min(_max_stack, _put_count)
|
||||
IN_player:GetInventory():RemoveItem(cItem(IN_itemID, _portion))
|
||||
_put_count = _put_count - _portion
|
||||
if (_put_count == 0) then break end
|
||||
end
|
||||
end
|
||||
function GiveItemsToPlayer(IN_player, IN_itemID, IN_ammount) -- UNSAFE! CHECK FIRST!
|
||||
local _put_count = IN_ammount
|
||||
local _max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
local _portion = math.min(_max_stack, _put_count)
|
||||
IN_player:GetInventory():AddItem(cItem(IN_itemID, _portion))
|
||||
_put_count = _put_count - _portion
|
||||
if (_put_count == 0) then break end
|
||||
end
|
||||
end
|
||||
-- This function returns item max stack for a given itemID. It uses vanilla max stack size, and uses several non-common items notations;
|
||||
-- Those are:
|
||||
-- oneonerecord (because aparently 11record wasn't the best idea in lua scripting application)
|
||||
-- carrotonastick (because it wasn't added to items.txt yet)
|
||||
-- waitrecord (for same reason)
|
||||
-- Feel free to ignore the difference, or to add those to items.txt
|
||||
function GetItemMaxStack(IN_itemID)
|
||||
local _result = 64
|
||||
-- Tools and swords
|
||||
if (IN_itemID == woodensword) then _result = 1 end
|
||||
if (IN_itemID == woodenshovel) then _result = 1 end
|
||||
if (IN_itemID == woodenpickaxe) then _result = 1 end
|
||||
if (IN_itemID == woodenaxe) then _result = 1 end
|
||||
if (IN_itemID == woodenhoe) then _result = 1 end
|
||||
if (IN_itemID == stonesword) then _result = 1 end
|
||||
if (IN_itemID == stoneshovel) then _result = 1 end
|
||||
if (IN_itemID == stonepickaxe) then _result = 1 end
|
||||
if (IN_itemID == stoneaxe) then _result = 1 end
|
||||
if (IN_itemID == stonehoe) then _result = 1 end
|
||||
if (IN_itemID == ironsword) then _result = 1 end
|
||||
if (IN_itemID == ironshovel) then _result = 1 end
|
||||
if (IN_itemID == ironpickaxe) then _result = 1 end
|
||||
if (IN_itemID == ironaxe) then _result = 1 end
|
||||
if (IN_itemID == ironhoe) then _result = 1 end
|
||||
if (IN_itemID == diamondsword) then _result = 1 end
|
||||
if (IN_itemID == diamondshovel) then _result = 1 end
|
||||
if (IN_itemID == diamondpickaxe) then _result = 1 end
|
||||
if (IN_itemID == diamondaxe) then _result = 1 end
|
||||
if (IN_itemID == diamondhoe) then _result = 1 end
|
||||
if (IN_itemID == goldensword) then _result = 1 end
|
||||
if (IN_itemID == goldenshovel) then _result = 1 end
|
||||
if (IN_itemID == goldenpickaxe) then _result = 1 end
|
||||
if (IN_itemID == goldenaxe) then _result = 1 end
|
||||
if (IN_itemID == goldenhoe) then _result = 1 end
|
||||
|
||||
if (IN_itemID == flintandsteel) then _result = 1 end
|
||||
if (IN_itemID == bow) then _result = 1 end
|
||||
if (IN_itemID == sign) then _result = 16 end
|
||||
if (IN_itemID == woodendoor) then _result = 1 end
|
||||
if (IN_itemID == irondoor) then _result = 1 end
|
||||
if (IN_itemID == cake) then _result = 1 end
|
||||
if (IN_itemID == cauldron) then _result = 1 end
|
||||
if (IN_itemID == mushroomstew) then _result = 1 end
|
||||
if (IN_itemID == painting) then _result = 1 end
|
||||
if (IN_itemID == bucket) then _result = 16 end
|
||||
if (IN_itemID == waterbucket) then _result = 1 end
|
||||
if (IN_itemID == lavabucket) then _result = 1 end
|
||||
if (IN_itemID == minecart) then _result = 1 end
|
||||
if (IN_itemID == saddle) then _result = 1 end
|
||||
if (IN_itemID == snowball) then _result = 16 end
|
||||
if (IN_itemID == boat) then _result = 1 end
|
||||
if (IN_itemID == milkbucket) then _result = 1 end
|
||||
if (IN_itemID == storageminecart) then _result = 1 end
|
||||
if (IN_itemID == poweredminecart) then _result = 1 end
|
||||
if (IN_itemID == egg) then _result = 16 end
|
||||
if (IN_itemID == fishingrod) then _result = 1 end
|
||||
if (IN_itemID == bed) then _result = 1 end
|
||||
if (IN_itemID == map) then _result = 1 end
|
||||
if (IN_itemID == shears) then _result = 1 end
|
||||
if (IN_itemID == enderpearl) then _result = 16 end
|
||||
if (IN_itemID == potion) then _result = 1 end
|
||||
if (IN_itemID == spawnegg) then _result = 1 end
|
||||
if (IN_itemID == bookandquill) then _result = 1 end
|
||||
if (IN_itemID == writtenbook) then _result = 1 end
|
||||
if (IN_itemID == carrotonastick) then _result = 1 end
|
||||
|
||||
if (IN_itemID == goldrecord) then _result = 1 end
|
||||
if (IN_itemID == greenrecord) then _result = 1 end
|
||||
if (IN_itemID == blocksrecord) then _result = 1 end
|
||||
if (IN_itemID == chirprecord) then _result = 1 end
|
||||
if (IN_itemID == farrecord) then _result = 1 end
|
||||
if (IN_itemID == mallrecord) then _result = 1 end
|
||||
if (IN_itemID == mellohirecord) then _result = 1 end
|
||||
if (IN_itemID == stalrecord) then _result = 1 end
|
||||
if (IN_itemID == stradrecord) then _result = 1 end
|
||||
if (IN_itemID == wardrecord) then _result = 1 end
|
||||
if (IN_itemID == oneonerecord) then _result = 1 end
|
||||
if (IN_itemID == waitrecord) then _result = 1 end
|
||||
|
||||
--if (IN_itemID == xxxxxxxxx) then _result = 1 end
|
||||
|
||||
if (IN_itemID == leatherhelmet) then _result = 1 end
|
||||
if (IN_itemID == leatherchestplate) then _result = 1 end
|
||||
if (IN_itemID == leatherpants) then _result = 1 end
|
||||
if (IN_itemID == leatherboots) then _result = 1 end
|
||||
|
||||
if (IN_itemID == chainmailhelmet) then _result = 1 end
|
||||
if (IN_itemID == chainmailchestplate) then _result = 1 end
|
||||
if (IN_itemID == chainmailpants) then _result = 1 end
|
||||
if (IN_itemID == chainmailboots) then _result = 1 end
|
||||
|
||||
if (IN_itemID == ironhelmet) then _result = 1 end
|
||||
if (IN_itemID == ironchestplate) then _result = 1 end
|
||||
if (IN_itemID == ironpants) then _result = 1 end
|
||||
if (IN_itemID == ironboots) then _result = 1 end
|
||||
|
||||
if (IN_itemID == diamondhelmet) then _result = 1 end
|
||||
if (IN_itemID == diamondchestplate) then _result = 1 end
|
||||
if (IN_itemID == diamondpants) then _result = 1 end
|
||||
if (IN_itemID == diamondboots) then _result = 1 end
|
||||
|
||||
if (IN_itemID == goldenhelmet) then _result = 1 end
|
||||
if (IN_itemID == goldenchestplate) then _result = 1 end
|
||||
if (IN_itemID == goldenpants) then _result = 1 end
|
||||
if (IN_itemID == goldenboots) then _result = 1 end
|
||||
return _result
|
||||
end
|
||||
function ItemIsArmor(IN_itemID)
|
||||
local _result = false
|
||||
if (IN_itemID == leatherhelmet) then _result = true end
|
||||
if (IN_itemID == leatherchestplate) then _result = true end
|
||||
if (IN_itemID == leatherpants) then _result = true end
|
||||
if (IN_itemID == leatherboots) then _result = true end
|
||||
|
||||
if (IN_itemID == chainmailhelmet) then _result = true end
|
||||
if (IN_itemID == chainmailchestplate) then _result = true end
|
||||
if (IN_itemID == chainmailpants) then _result = true end
|
||||
if (IN_itemID == chainmailboots) then _result = true end
|
||||
|
||||
if (IN_itemID == ironhelmet) then _result = true end
|
||||
if (IN_itemID == ironchestplate) then _result = true end
|
||||
if (IN_itemID == ironpants) then _result = true end
|
||||
if (IN_itemID == ironboots) then _result = true end
|
||||
|
||||
if (IN_itemID == diamondhelmet) then _result = true end
|
||||
if (IN_itemID == diamondchestplate) then _result = true end
|
||||
if (IN_itemID == diamondpants) then _result = true end
|
||||
if (IN_itemID == diamondboots) then _result = true end
|
||||
|
||||
if (IN_itemID == goldenhelmet) then _result = true end
|
||||
if (IN_itemID == goldenchestplate) then _result = true end
|
||||
if (IN_itemID == goldenpants) then _result = true end
|
||||
if (IN_itemID == goldenboots) then _result = true end
|
||||
return _result
|
||||
end
|
||||
-- Returns full-length playername for a short name (usefull for parsing commands)
|
||||
function GetExactPlayername(IN_playername)
|
||||
local _result = IN_playername
|
||||
local function SetProcessingPlayername(IN_player)
|
||||
_result = IN_player:GetName()
|
||||
end
|
||||
cRoot:Get():FindAndDoWithPlayer(IN_playername, SetProcessingPlayername)
|
||||
return _result
|
||||
end
|
||||
function GetPlayerByName(IN_playername)
|
||||
local _player
|
||||
local PlayerSetter = function (Player)
|
||||
_player = Player
|
||||
end
|
||||
cRoot:Get():FindAndDoWithPlayer(IN_playername, PlayerSetter)
|
||||
return _player
|
||||
end
|
||||
--[[
|
||||
Not-so-usual math _functions
|
||||
]]
|
||||
-- Rounds floating point number. Because lua guys think this function doesn't deserve to be presented in lua's math
|
||||
function round(IN_x)
|
||||
if (IN_x%2 ~= 0.5) then
|
||||
return math.floor(IN_x+0.5)
|
||||
end
|
||||
return IN_x-0.5
|
||||
end
|
||||
--[[
|
||||
Functions I use for filework and stringswork
|
||||
]]
|
||||
function PluralString(IN_value, IN_singular_string, IN_plural_string)
|
||||
local _value_string = tostring(IN_value)
|
||||
if (_value_string[#_value_string] == "1") then
|
||||
return IN_singular_string
|
||||
end
|
||||
return IN_plural_string
|
||||
end
|
||||
function PluralItemName(IN_itemID, IN_ammount) -- BEWARE! TEMPORAL SOLUTION THERE! :D
|
||||
local _value_string = tostring(IN_value)
|
||||
local _name = ""
|
||||
if (_value_string[#_value_string] == "1") then
|
||||
-- singular names
|
||||
_name = ItemTypeToString(IN_itemID)
|
||||
else
|
||||
-- plural names
|
||||
_name = ItemTypeToString(IN_itemID).."s"
|
||||
end
|
||||
return _name
|
||||
end
|
||||
-- for filewriting purposes. 0 = false, 1 = true
|
||||
function StringToBool(value)
|
||||
if value=="1" then return true end
|
||||
return false
|
||||
end
|
||||
-- same, but reversal
|
||||
function BoolToString(value)
|
||||
if value==true then return 1 end
|
||||
return 0
|
||||
--[[
|
||||
General stuff
|
||||
]]
|
||||
-- Returns Handy plugin version number
|
||||
function GetHandyVersion()
|
||||
return HANDY_VERSION
|
||||
end
|
||||
-- Checks if handy is in proper version
|
||||
function CheckForRequiedVersion(IN_version)
|
||||
if (IN_version > HANDY_VERSION) then return false end
|
||||
return true
|
||||
end
|
||||
--[[
|
||||
MCS-specific _functions and nasty hacks :D
|
||||
]]
|
||||
-- There's a "GetChestHeight" function inside source code, but it's not lua-exported
|
||||
function GetChestHeightCheat(IN_chest)
|
||||
if (IN_chest:GetSlot(28) == nil) then -- this means we're trying to get double chest slot and FAIL
|
||||
LOGWARN("HANDY: single chest checked")
|
||||
return 3
|
||||
end
|
||||
LOGWARN("HANDY: double chest checked")
|
||||
return 6
|
||||
end
|
||||
-- Those two checks how many items of given IN_itemID chest and player have, and how much they could fit inside them
|
||||
function ReadChestForItem(IN_chest, IN_itemID)
|
||||
local _items_found = 0
|
||||
local _free_space = 0
|
||||
-- stalk through chest slots...
|
||||
local _slot_counter = 0
|
||||
local _slot_item
|
||||
local _item_max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
_slot_item = IN_chest:GetSlot(_slot_counter)
|
||||
if (_slot_item ~= nil) then
|
||||
if (_slot_item.m_ItemID == IN_itemID) then
|
||||
_items_found = _items_found + _slot_item.m_ItemCount
|
||||
_free_space = _free_space + (_item_max_stack - _slot_item.m_ItemCount)
|
||||
end
|
||||
if (_slot_item:IsEmpty() == true) then
|
||||
_free_space = _free_space + _item_max_stack
|
||||
end
|
||||
end
|
||||
_slot_counter = _slot_counter + 1
|
||||
if (_slot_counter == CHEST_WIDTH*GetChestHeightCheat(IN_chest)) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return _items_found, _free_space
|
||||
end
|
||||
function ReadPlayerForItem(IN_player, IN_itemID)
|
||||
local _items_found = 0
|
||||
local _free_space = 0
|
||||
-- stalk through IN_player inventory slots...
|
||||
local _slot_counter = 9
|
||||
if (ItemIsArmor(IN_itemID) == true) then _slot_counter = 5 end
|
||||
local _slot_item
|
||||
local _item_max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
_slot_item = IN_player:GetInventory():GetSlot(_slot_counter)
|
||||
if (_slot_item ~= nil) then
|
||||
if (_slot_item.m_ItemID == IN_itemID) then
|
||||
_items_found = _items_found + _slot_item.m_ItemCount
|
||||
_free_space = _free_space + (_item_max_stack - _slot_item.m_ItemCount)
|
||||
end
|
||||
if (_slot_item:IsEmpty() == true) then
|
||||
_free_space = _free_space + _item_max_stack
|
||||
end
|
||||
end
|
||||
_slot_counter = _slot_counter + 1
|
||||
if (_slot_counter == 45) then
|
||||
break
|
||||
end
|
||||
end
|
||||
return _items_found, _free_space
|
||||
end
|
||||
-- Following functions are for chest-related operations (since noone was bothered writing them in MCS code)
|
||||
-- BEWARE! Those assume you did checked if chest has items/space in it!
|
||||
function TakeItemsFromChest(IN_chest, IN_itemID, IN_ammount) -- UNSAFE! CHECK FOR ITEMS FIRST!!
|
||||
-- stalk through chest slots...
|
||||
local _slot_counter = 0
|
||||
local _slot_item
|
||||
local _take_count = IN_ammount
|
||||
while true do
|
||||
_slot_item = IN_chest:GetSlot(_slot_counter)
|
||||
if (_slot_item ~= nil) then
|
||||
if (_slot_item.m_ItemID == IN_itemID) then
|
||||
-- assuming player have enought money
|
||||
if (_take_count > 0) then
|
||||
if (_take_count > _slot_item.m_ItemCount) then
|
||||
_take_count = _take_count - _slot_item.m_ItemCount
|
||||
IN_chest:SetSlot(_slot_counter, cItem()) -- a bit hacky, can't make cItem:Clear() work(
|
||||
else
|
||||
local _left_count = _slot_item.m_ItemCount - _take_count
|
||||
IN_chest:SetSlot(_slot_counter, cItem(_slot_item.m_ItemID, _left_count)) -- a bit hacky
|
||||
_take_count = 0
|
||||
end
|
||||
end
|
||||
if (_take_count == 0) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
_slot_counter = _slot_counter + 1
|
||||
if (_slot_counter == CHEST_WIDTH*GetChestHeightCheat(IN_chest)) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
function PutItemsToChest(IN_chest, IN_itemID, IN_ammount) -- UNSAFE! CHECK FOR SPACE FIRST!!
|
||||
-- stalk through chest slots...
|
||||
local _slot_counter = 0
|
||||
local _slot_item
|
||||
local _put_count = IN_ammount
|
||||
local _max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
_slot_item = IN_chest:GetSlot(_slot_counter)
|
||||
local _portion = 0
|
||||
local _ammount_to_set = 0
|
||||
if (_slot_item ~= nil) then
|
||||
if (_slot_item:IsEmpty() == true) then
|
||||
_portion = math.min(_max_stack, _put_count)
|
||||
_ammount_to_set = _portion
|
||||
else
|
||||
if (_slot_item.m_ItemID == IN_itemID) then
|
||||
-- choose between how much we need to put and how much free space left
|
||||
_portion = math.min(_put_count, _max_stack - _slot_item.m_ItemCount)
|
||||
_ammount_to_set = _slot_item.m_ItemCount + _portion
|
||||
end
|
||||
end
|
||||
end
|
||||
IN_chest:SetSlot(_slot_counter, cItem(IN_itemID, _ammount_to_set)) -- we add max stack to chest
|
||||
_put_count = _put_count - _portion
|
||||
if (_put_count == 0) then break end
|
||||
_slot_counter = _slot_counter + 1
|
||||
if (_slot_counter == CHEST_WIDTH*GetChestHeightCheat(IN_chest)) then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Similar to chest-related.
|
||||
function TakeItemsFromPlayer(IN_player, IN_itemID, IN_ammount) -- UNSAFE! CHECK FIRST!
|
||||
local _put_count = IN_ammount
|
||||
local _max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
local _portion = math.min(_max_stack, _put_count)
|
||||
IN_player:GetInventory():RemoveItem(cItem(IN_itemID, _portion))
|
||||
_put_count = _put_count - _portion
|
||||
if (_put_count == 0) then break end
|
||||
end
|
||||
end
|
||||
function GiveItemsToPlayer(IN_player, IN_itemID, IN_ammount) -- UNSAFE! CHECK FIRST!
|
||||
local _put_count = IN_ammount
|
||||
local _max_stack = GetItemMaxStack(IN_itemID)
|
||||
while true do
|
||||
local _portion = math.min(_max_stack, _put_count)
|
||||
IN_player:GetInventory():AddItem(cItem(IN_itemID, _portion))
|
||||
_put_count = _put_count - _portion
|
||||
if (_put_count == 0) then break end
|
||||
end
|
||||
end
|
||||
-- This function returns item max stack for a given itemID. It uses vanilla max stack size, and uses several non-common items notations;
|
||||
-- Those are:
|
||||
-- oneonerecord (because aparently 11record wasn't the best idea in lua scripting application)
|
||||
-- carrotonastick (because it wasn't added to items.txt yet)
|
||||
-- waitrecord (for same reason)
|
||||
-- Feel free to ignore the difference, or to add those to items.txt
|
||||
function GetItemMaxStack(IN_itemID)
|
||||
local _result = 64
|
||||
-- Tools and swords
|
||||
if (IN_itemID == woodensword) then _result = 1 end
|
||||
if (IN_itemID == woodenshovel) then _result = 1 end
|
||||
if (IN_itemID == woodenpickaxe) then _result = 1 end
|
||||
if (IN_itemID == woodenaxe) then _result = 1 end
|
||||
if (IN_itemID == woodenhoe) then _result = 1 end
|
||||
if (IN_itemID == stonesword) then _result = 1 end
|
||||
if (IN_itemID == stoneshovel) then _result = 1 end
|
||||
if (IN_itemID == stonepickaxe) then _result = 1 end
|
||||
if (IN_itemID == stoneaxe) then _result = 1 end
|
||||
if (IN_itemID == stonehoe) then _result = 1 end
|
||||
if (IN_itemID == ironsword) then _result = 1 end
|
||||
if (IN_itemID == ironshovel) then _result = 1 end
|
||||
if (IN_itemID == ironpickaxe) then _result = 1 end
|
||||
if (IN_itemID == ironaxe) then _result = 1 end
|
||||
if (IN_itemID == ironhoe) then _result = 1 end
|
||||
if (IN_itemID == diamondsword) then _result = 1 end
|
||||
if (IN_itemID == diamondshovel) then _result = 1 end
|
||||
if (IN_itemID == diamondpickaxe) then _result = 1 end
|
||||
if (IN_itemID == diamondaxe) then _result = 1 end
|
||||
if (IN_itemID == diamondhoe) then _result = 1 end
|
||||
if (IN_itemID == goldensword) then _result = 1 end
|
||||
if (IN_itemID == goldenshovel) then _result = 1 end
|
||||
if (IN_itemID == goldenpickaxe) then _result = 1 end
|
||||
if (IN_itemID == goldenaxe) then _result = 1 end
|
||||
if (IN_itemID == goldenhoe) then _result = 1 end
|
||||
|
||||
if (IN_itemID == flintandsteel) then _result = 1 end
|
||||
if (IN_itemID == bow) then _result = 1 end
|
||||
if (IN_itemID == sign) then _result = 16 end
|
||||
if (IN_itemID == woodendoor) then _result = 1 end
|
||||
if (IN_itemID == irondoor) then _result = 1 end
|
||||
if (IN_itemID == cake) then _result = 1 end
|
||||
if (IN_itemID == cauldron) then _result = 1 end
|
||||
if (IN_itemID == mushroomstew) then _result = 1 end
|
||||
if (IN_itemID == painting) then _result = 1 end
|
||||
if (IN_itemID == bucket) then _result = 16 end
|
||||
if (IN_itemID == waterbucket) then _result = 1 end
|
||||
if (IN_itemID == lavabucket) then _result = 1 end
|
||||
if (IN_itemID == minecart) then _result = 1 end
|
||||
if (IN_itemID == saddle) then _result = 1 end
|
||||
if (IN_itemID == snowball) then _result = 16 end
|
||||
if (IN_itemID == boat) then _result = 1 end
|
||||
if (IN_itemID == milkbucket) then _result = 1 end
|
||||
if (IN_itemID == storageminecart) then _result = 1 end
|
||||
if (IN_itemID == poweredminecart) then _result = 1 end
|
||||
if (IN_itemID == egg) then _result = 16 end
|
||||
if (IN_itemID == fishingrod) then _result = 1 end
|
||||
if (IN_itemID == bed) then _result = 1 end
|
||||
if (IN_itemID == map) then _result = 1 end
|
||||
if (IN_itemID == shears) then _result = 1 end
|
||||
if (IN_itemID == enderpearl) then _result = 16 end
|
||||
if (IN_itemID == potion) then _result = 1 end
|
||||
if (IN_itemID == spawnegg) then _result = 1 end
|
||||
if (IN_itemID == bookandquill) then _result = 1 end
|
||||
if (IN_itemID == writtenbook) then _result = 1 end
|
||||
if (IN_itemID == carrotonastick) then _result = 1 end
|
||||
|
||||
if (IN_itemID == goldrecord) then _result = 1 end
|
||||
if (IN_itemID == greenrecord) then _result = 1 end
|
||||
if (IN_itemID == blocksrecord) then _result = 1 end
|
||||
if (IN_itemID == chirprecord) then _result = 1 end
|
||||
if (IN_itemID == farrecord) then _result = 1 end
|
||||
if (IN_itemID == mallrecord) then _result = 1 end
|
||||
if (IN_itemID == mellohirecord) then _result = 1 end
|
||||
if (IN_itemID == stalrecord) then _result = 1 end
|
||||
if (IN_itemID == stradrecord) then _result = 1 end
|
||||
if (IN_itemID == wardrecord) then _result = 1 end
|
||||
if (IN_itemID == oneonerecord) then _result = 1 end
|
||||
if (IN_itemID == waitrecord) then _result = 1 end
|
||||
|
||||
--if (IN_itemID == xxxxxxxxx) then _result = 1 end
|
||||
|
||||
if (IN_itemID == leatherhelmet) then _result = 1 end
|
||||
if (IN_itemID == leatherchestplate) then _result = 1 end
|
||||
if (IN_itemID == leatherpants) then _result = 1 end
|
||||
if (IN_itemID == leatherboots) then _result = 1 end
|
||||
|
||||
if (IN_itemID == chainmailhelmet) then _result = 1 end
|
||||
if (IN_itemID == chainmailchestplate) then _result = 1 end
|
||||
if (IN_itemID == chainmailpants) then _result = 1 end
|
||||
if (IN_itemID == chainmailboots) then _result = 1 end
|
||||
|
||||
if (IN_itemID == ironhelmet) then _result = 1 end
|
||||
if (IN_itemID == ironchestplate) then _result = 1 end
|
||||
if (IN_itemID == ironpants) then _result = 1 end
|
||||
if (IN_itemID == ironboots) then _result = 1 end
|
||||
|
||||
if (IN_itemID == diamondhelmet) then _result = 1 end
|
||||
if (IN_itemID == diamondchestplate) then _result = 1 end
|
||||
if (IN_itemID == diamondpants) then _result = 1 end
|
||||
if (IN_itemID == diamondboots) then _result = 1 end
|
||||
|
||||
if (IN_itemID == goldenhelmet) then _result = 1 end
|
||||
if (IN_itemID == goldenchestplate) then _result = 1 end
|
||||
if (IN_itemID == goldenpants) then _result = 1 end
|
||||
if (IN_itemID == goldenboots) then _result = 1 end
|
||||
return _result
|
||||
end
|
||||
function ItemIsArmor(IN_itemID)
|
||||
local _result = false
|
||||
if (IN_itemID == leatherhelmet) then _result = true end
|
||||
if (IN_itemID == leatherchestplate) then _result = true end
|
||||
if (IN_itemID == leatherpants) then _result = true end
|
||||
if (IN_itemID == leatherboots) then _result = true end
|
||||
|
||||
if (IN_itemID == chainmailhelmet) then _result = true end
|
||||
if (IN_itemID == chainmailchestplate) then _result = true end
|
||||
if (IN_itemID == chainmailpants) then _result = true end
|
||||
if (IN_itemID == chainmailboots) then _result = true end
|
||||
|
||||
if (IN_itemID == ironhelmet) then _result = true end
|
||||
if (IN_itemID == ironchestplate) then _result = true end
|
||||
if (IN_itemID == ironpants) then _result = true end
|
||||
if (IN_itemID == ironboots) then _result = true end
|
||||
|
||||
if (IN_itemID == diamondhelmet) then _result = true end
|
||||
if (IN_itemID == diamondchestplate) then _result = true end
|
||||
if (IN_itemID == diamondpants) then _result = true end
|
||||
if (IN_itemID == diamondboots) then _result = true end
|
||||
|
||||
if (IN_itemID == goldenhelmet) then _result = true end
|
||||
if (IN_itemID == goldenchestplate) then _result = true end
|
||||
if (IN_itemID == goldenpants) then _result = true end
|
||||
if (IN_itemID == goldenboots) then _result = true end
|
||||
return _result
|
||||
end
|
||||
-- Returns full-length playername for a short name (usefull for parsing commands)
|
||||
function GetExactPlayername(IN_playername)
|
||||
local _result = IN_playername
|
||||
local function SetProcessingPlayername(IN_player)
|
||||
_result = IN_player:GetName()
|
||||
end
|
||||
cRoot:Get():FindAndDoWithPlayer(IN_playername, SetProcessingPlayername)
|
||||
return _result
|
||||
end
|
||||
function GetPlayerByName(IN_playername)
|
||||
local _player
|
||||
local PlayerSetter = function (Player)
|
||||
_player = Player
|
||||
end
|
||||
cRoot:Get():FindAndDoWithPlayer(IN_playername, PlayerSetter)
|
||||
return _player
|
||||
end
|
||||
--[[
|
||||
Not-so-usual math _functions
|
||||
]]
|
||||
-- Rounds floating point number. Because lua guys think this function doesn't deserve to be presented in lua's math
|
||||
function round(IN_x)
|
||||
if (IN_x%2 ~= 0.5) then
|
||||
return math.floor(IN_x+0.5)
|
||||
end
|
||||
return IN_x-0.5
|
||||
end
|
||||
--[[
|
||||
Functions I use for filework and stringswork
|
||||
]]
|
||||
function PluralString(IN_value, IN_singular_string, IN_plural_string)
|
||||
local _value_string = tostring(IN_value)
|
||||
if (_value_string[#_value_string] == "1") then
|
||||
return IN_singular_string
|
||||
end
|
||||
return IN_plural_string
|
||||
end
|
||||
function PluralItemName(IN_itemID, IN_ammount) -- BEWARE! TEMPORAL SOLUTION THERE! :D
|
||||
local _value_string = tostring(IN_value)
|
||||
local _name = ""
|
||||
if (_value_string[#_value_string] == "1") then
|
||||
-- singular names
|
||||
_name = ItemTypeToString(IN_itemID)
|
||||
else
|
||||
-- plural names
|
||||
_name = ItemTypeToString(IN_itemID).."s"
|
||||
end
|
||||
return _name
|
||||
end
|
||||
-- for filewriting purposes. 0 = false, 1 = true
|
||||
function StringToBool(value)
|
||||
if value=="1" then return true end
|
||||
return false
|
||||
end
|
||||
-- same, but reversal
|
||||
function BoolToString(value)
|
||||
if value==true then return 1 end
|
||||
return 0
|
||||
end
|
@ -1,404 +1,404 @@
|
||||
|
||||
-- Global variables
|
||||
PLUGIN = {} -- Reference to own plugin object
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function Initialize(Plugin)
|
||||
PLUGIN = Plugin
|
||||
|
||||
Plugin:SetName("HookNotify");
|
||||
Plugin:SetVersion(1);
|
||||
|
||||
PluginManager = cPluginManager:Get();
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_TO_PICKUPS);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_AVAILABLE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_UNLOADED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_UNLOADING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_COLLECTING_PICKUP);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_DISCONNECT);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_EXECUTE_COMMAND);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_HANDSHAKE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_LOGIN);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BREAKING_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BROKEN_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_EATING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_JOINED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_LEFT_CLICK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_MOVING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_PLACED_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_PLACING_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_SHOOTING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_SPAWNED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_TOSSING_ITEM);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USED_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USED_ITEM);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_POST_CRAFTING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PRE_CRAFTING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_UPDATED_SIGN);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_UPDATING_SIGN);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_WEATHER_CHANGED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_WEATHER_CHANGING);
|
||||
|
||||
LOGINFO("HookNotify plugin is installed, beware, the log output may be quite large!");
|
||||
LOGINFO("You want this plugin enabled only when developing another plugin, not for regular gameplay.");
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function LogHook(FnName, ...)
|
||||
LOG(FnName .. "(");
|
||||
for i, v in ipairs(arg) do
|
||||
local vt = tostring(v);
|
||||
local TypeString = type(v);
|
||||
if (type(v) == "userdata") then
|
||||
TypeString = tolua.type(v);
|
||||
end;
|
||||
LOG(" " .. tostring(i) .. ": " .. TypeString .. ": " .. tostring(v));
|
||||
end
|
||||
LOG(")");
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnBlockToPickups(...)
|
||||
LogHook("OnBlockToPickups", unpack(arg));
|
||||
local World, Digger, BlockX, BlockY, BlockZ, BlockType, BlockMeta, Pickups = unpack(arg);
|
||||
if (Pickups ~= nil) then
|
||||
local Name = "NULL";
|
||||
if (Digger ~= nil) then
|
||||
Name = Digger:GetName()
|
||||
end
|
||||
LOG("Got cItems from " .. Name .. ", trying to manipulate them.");
|
||||
Pickups:Add(cItem:new(E_ITEM_DIAMOND_SHOVEL, 1));
|
||||
LOG("Current size: " .. Pickups:Size());
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChat(...)
|
||||
LogHook("OnChat", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkAvailable(...)
|
||||
LogHook("OnChunkAvailable", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkGenerated(...)
|
||||
LogHook("OnChunkGenerated", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkGenerating(...)
|
||||
LogHook("OnChunkGenerating", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkUnloaded(...)
|
||||
LogHook("OnChunkUnloaded", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkUnloading(...)
|
||||
LogHook("OnChunkUnloading", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsingItem(...)
|
||||
LogHook("OnPlayerUsingItem", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnCollectingPickup(...)
|
||||
LogHook("OnCollectingPickup", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
function OnCraftingNoRecipe(...)
|
||||
LogHook("OnCraftingNoRecipe", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnDisconnect(...)
|
||||
LogHook("OnDisconnect", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnExecuteCommand(...)
|
||||
LogHook("OnExecuteCommand", unpack(arg));
|
||||
|
||||
-- For some reason logging doesn't work for this callback, so list some stuff manually to verify:
|
||||
LOG("arg1 type: " .. type(arg[1]));
|
||||
if (arg[1] ~= nil) then
|
||||
LOG("Player name: " .. arg[1]:GetName());
|
||||
end
|
||||
LOG("Command: " .. arg[2][1]);
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnHandshake(...)
|
||||
LogHook("OnHandshake", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnKilling(...)
|
||||
LogHook("OnKilling", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnLogin(...)
|
||||
LogHook("OnLogin", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerBreakingBlock(...)
|
||||
LogHook("OnPlayerBreakingBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerBrokenBlock(...)
|
||||
LogHook("OnPlayerBrokenBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerEating(...)
|
||||
LogHook("OnPlayerEating", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerJoined(...)
|
||||
LogHook("OnPlayerJoined", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerLeftClick(...)
|
||||
LogHook("OnPlayerLeftClick", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerMoving(...)
|
||||
LogHook("OnPlayerMoving", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerPlacedBlock(...)
|
||||
LogHook("OnPlayerPlacedBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerPlacingBlock(...)
|
||||
LogHook("OnPlayerPlacingBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerRightClick(...)
|
||||
LogHook("OnPlayerRightClick", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerShooting(...)
|
||||
LogHook("OnPlayerShooting", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerSpawned(...)
|
||||
LogHook("OnPlayerSpawned", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerTossingItem(...)
|
||||
LogHook("OnPlayerTossingItem", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsedBlock(...)
|
||||
LogHook("OnPlayerUsedBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsedItem(...)
|
||||
LogHook("OnPlayerUsedItem", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsingBlock(...)
|
||||
LogHook("OnPlayerUsingBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsingItem(...)
|
||||
LogHook("OnPlayerUsingItem", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPostCrafting(...)
|
||||
LogHook("OnPostCrafting", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPreCrafting(...)
|
||||
LogHook("OnPreCrafting", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnUpdatedSign(...)
|
||||
LogHook("OnUpdatedSign", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnUpdatingSign(...)
|
||||
LogHook("OnUpdatingSign", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnWeatherChanged(...)
|
||||
LogHook("OnWeatherChanged", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnWeatherChanging(...)
|
||||
LogHook("OnWeatherChanging", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Special handling for OnTakeDamage to print the contents of TDI:
|
||||
|
||||
function OnTakeDamage(Receiver, TDI)
|
||||
-- Receiver is cPawn
|
||||
-- TDI is TakeDamageInfo
|
||||
|
||||
LOG("OnTakeDamage(): " .. Receiver:GetClass() .. " was dealt RawDamage " .. TDI.RawDamage .. ", FinalDamage " .. TDI.FinalDamage .. " (that is, " .. (TDI.RawDamage - TDI.FinalDamage) .. " HPs covered by armor)");
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
-- Global variables
|
||||
PLUGIN = {} -- Reference to own plugin object
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function Initialize(Plugin)
|
||||
PLUGIN = Plugin
|
||||
|
||||
Plugin:SetName("HookNotify");
|
||||
Plugin:SetVersion(1);
|
||||
|
||||
PluginManager = cPluginManager:Get();
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_BLOCK_TO_PICKUPS);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHAT);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_AVAILABLE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_GENERATING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_UNLOADED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CHUNK_UNLOADING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_COLLECTING_PICKUP);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_CRAFTING_NO_RECIPE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_DISCONNECT);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_EXECUTE_COMMAND);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_HANDSHAKE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_KILLING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_LOGIN);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BREAKING_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_BROKEN_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_EATING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_JOINED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_LEFT_CLICK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_MOVING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_PLACED_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_PLACING_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_RIGHT_CLICK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_SHOOTING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_SPAWNED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_TOSSING_ITEM);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USED_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USED_ITEM);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_BLOCK);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PLAYER_USING_ITEM);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_POST_CRAFTING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_PRE_CRAFTING);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_TAKE_DAMAGE);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_UPDATED_SIGN);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_UPDATING_SIGN);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_WEATHER_CHANGED);
|
||||
PluginManager:AddHook(Plugin, cPluginManager.HOOK_WEATHER_CHANGING);
|
||||
|
||||
LOGINFO("HookNotify plugin is installed, beware, the log output may be quite large!");
|
||||
LOGINFO("You want this plugin enabled only when developing another plugin, not for regular gameplay.");
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function LogHook(FnName, ...)
|
||||
LOG(FnName .. "(");
|
||||
for i, v in ipairs(arg) do
|
||||
local vt = tostring(v);
|
||||
local TypeString = type(v);
|
||||
if (type(v) == "userdata") then
|
||||
TypeString = tolua.type(v);
|
||||
end;
|
||||
LOG(" " .. tostring(i) .. ": " .. TypeString .. ": " .. tostring(v));
|
||||
end
|
||||
LOG(")");
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnBlockToPickups(...)
|
||||
LogHook("OnBlockToPickups", unpack(arg));
|
||||
local World, Digger, BlockX, BlockY, BlockZ, BlockType, BlockMeta, Pickups = unpack(arg);
|
||||
if (Pickups ~= nil) then
|
||||
local Name = "NULL";
|
||||
if (Digger ~= nil) then
|
||||
Name = Digger:GetName()
|
||||
end
|
||||
LOG("Got cItems from " .. Name .. ", trying to manipulate them.");
|
||||
Pickups:Add(cItem:new(E_ITEM_DIAMOND_SHOVEL, 1));
|
||||
LOG("Current size: " .. Pickups:Size());
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChat(...)
|
||||
LogHook("OnChat", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkAvailable(...)
|
||||
LogHook("OnChunkAvailable", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkGenerated(...)
|
||||
LogHook("OnChunkGenerated", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkGenerating(...)
|
||||
LogHook("OnChunkGenerating", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkUnloaded(...)
|
||||
LogHook("OnChunkUnloaded", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnChunkUnloading(...)
|
||||
LogHook("OnChunkUnloading", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsingItem(...)
|
||||
LogHook("OnPlayerUsingItem", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnCollectingPickup(...)
|
||||
LogHook("OnCollectingPickup", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
function OnCraftingNoRecipe(...)
|
||||
LogHook("OnCraftingNoRecipe", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnDisconnect(...)
|
||||
LogHook("OnDisconnect", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnExecuteCommand(...)
|
||||
LogHook("OnExecuteCommand", unpack(arg));
|
||||
|
||||
-- For some reason logging doesn't work for this callback, so list some stuff manually to verify:
|
||||
LOG("arg1 type: " .. type(arg[1]));
|
||||
if (arg[1] ~= nil) then
|
||||
LOG("Player name: " .. arg[1]:GetName());
|
||||
end
|
||||
LOG("Command: " .. arg[2][1]);
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnHandshake(...)
|
||||
LogHook("OnHandshake", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnKilling(...)
|
||||
LogHook("OnKilling", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnLogin(...)
|
||||
LogHook("OnLogin", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerBreakingBlock(...)
|
||||
LogHook("OnPlayerBreakingBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerBrokenBlock(...)
|
||||
LogHook("OnPlayerBrokenBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerEating(...)
|
||||
LogHook("OnPlayerEating", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerJoined(...)
|
||||
LogHook("OnPlayerJoined", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerLeftClick(...)
|
||||
LogHook("OnPlayerLeftClick", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerMoving(...)
|
||||
LogHook("OnPlayerMoving", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerPlacedBlock(...)
|
||||
LogHook("OnPlayerPlacedBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerPlacingBlock(...)
|
||||
LogHook("OnPlayerPlacingBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerRightClick(...)
|
||||
LogHook("OnPlayerRightClick", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerShooting(...)
|
||||
LogHook("OnPlayerShooting", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerSpawned(...)
|
||||
LogHook("OnPlayerSpawned", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerTossingItem(...)
|
||||
LogHook("OnPlayerTossingItem", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsedBlock(...)
|
||||
LogHook("OnPlayerUsedBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsedItem(...)
|
||||
LogHook("OnPlayerUsedItem", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsingBlock(...)
|
||||
LogHook("OnPlayerUsingBlock", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPlayerUsingItem(...)
|
||||
LogHook("OnPlayerUsingItem", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPostCrafting(...)
|
||||
LogHook("OnPostCrafting", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnPreCrafting(...)
|
||||
LogHook("OnPreCrafting", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnUpdatedSign(...)
|
||||
LogHook("OnUpdatedSign", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnUpdatingSign(...)
|
||||
LogHook("OnUpdatingSign", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnWeatherChanged(...)
|
||||
LogHook("OnWeatherChanged", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function OnWeatherChanging(...)
|
||||
LogHook("OnWeatherChanging", unpack(arg));
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------
|
||||
-- Special handling for OnTakeDamage to print the contents of TDI:
|
||||
|
||||
function OnTakeDamage(Receiver, TDI)
|
||||
-- Receiver is cPawn
|
||||
-- TDI is TakeDamageInfo
|
||||
|
||||
LOG("OnTakeDamage(): " .. Receiver:GetClass() .. " was dealt RawDamage " .. TDI.RawDamage .. ", FinalDamage " .. TDI.FinalDamage .. " (that is, " .. (TDI.RawDamage - TDI.FinalDamage) .. " HPs covered by armor)");
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -1,97 +1,97 @@
|
||||
-- Location object
|
||||
cLocation = {}
|
||||
function cLocation:new( x, y, z )
|
||||
local object = { x = x, y = y, z = z }
|
||||
setmetatable(object, { __index = cLocation })
|
||||
return object
|
||||
end
|
||||
|
||||
-- Offsets
|
||||
cFibers = { }
|
||||
function cFibers:new()
|
||||
local object = {
|
||||
cLocation:new( 2, -1, 2 ),
|
||||
cLocation:new( 2, -1, 1 ),
|
||||
cLocation:new( 2, -1, 0 ),
|
||||
cLocation:new( 2, -1, -1 ),
|
||||
cLocation:new( 2, -1, -2 ),
|
||||
cLocation:new( 1, -1, 2 ),
|
||||
cLocation:new( 1, -1, 1 ),
|
||||
cLocation:new( 1, -1, 0 ),
|
||||
cLocation:new( 1, -1, -1 ),
|
||||
cLocation:new( 1, -1, -2 ),
|
||||
cLocation:new( 0, -1, 2 ),
|
||||
cLocation:new( 0, -1, 1 ),
|
||||
cLocation:new( 0, -1, 0 ),
|
||||
cLocation:new( 0, -1, -1 ),
|
||||
cLocation:new( 0, -1, -2 ),
|
||||
cLocation:new( -1, -1, 2 ),
|
||||
cLocation:new( -1, -1, 1 ),
|
||||
cLocation:new( -1, -1, 0 ),
|
||||
cLocation:new( -1, -1, -1 ),
|
||||
cLocation:new( -1, -1, -2 ),
|
||||
cLocation:new( -2, -1, 2 ),
|
||||
cLocation:new( -2, -1, 1 ),
|
||||
cLocation:new( -2, -1, 0 ),
|
||||
cLocation:new( -2, -1, -1 ),
|
||||
cLocation:new( -2, -1, -2 ),
|
||||
imadeit = false,
|
||||
}
|
||||
setmetatable(object, { __index = cFibers })
|
||||
return object;
|
||||
end
|
||||
|
||||
-- Carpet object
|
||||
cCarpet = {}
|
||||
function cCarpet:new()
|
||||
local object = { Location = cLocation:new(0,0,0),
|
||||
Fibers = cFibers:new(),
|
||||
}
|
||||
setmetatable(object, { __index = cCarpet })
|
||||
return object
|
||||
end
|
||||
|
||||
function cCarpet:remove()
|
||||
local World = cRoot:Get():GetDefaultWorld()
|
||||
for i, fib in ipairs( self.Fibers ) do
|
||||
local x = self.Location.x + fib.x
|
||||
local y = self.Location.y + fib.y
|
||||
local z = self.Location.z + fib.z
|
||||
local BlockID = World:GetBlock( x, y, z )
|
||||
if( fib.imadeit == true and BlockID == E_BLOCK_GLASS ) then
|
||||
World:SetBlock( x, y, z, 0, 0 )
|
||||
fib.imadeit = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function cCarpet:draw()
|
||||
local World = cRoot:Get():GetDefaultWorld()
|
||||
for i, fib in ipairs( self.Fibers ) do
|
||||
local x = self.Location.x + fib.x
|
||||
local y = self.Location.y + fib.y
|
||||
local z = self.Location.z + fib.z
|
||||
local BlockID = World:GetBlock( x, y, z )
|
||||
if( BlockID == 0 ) then
|
||||
fib.imadeit = true
|
||||
World:SetBlock( x, y, z, E_BLOCK_GLASS, 0 )
|
||||
else
|
||||
fib.imadeit = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function cCarpet:moveTo( NewPos )
|
||||
local x = math.floor( NewPos.x )
|
||||
local y = math.floor( NewPos.y )
|
||||
local z = math.floor( NewPos.z )
|
||||
if( self.Location.x ~= x or self.Location.y ~= y or self.Location.z ~= z ) then
|
||||
self:remove()
|
||||
self.Location = cLocation:new( x, y, z )
|
||||
self:draw()
|
||||
end
|
||||
end
|
||||
|
||||
function cCarpet:getY()
|
||||
return self.Location.y
|
||||
-- Location object
|
||||
cLocation = {}
|
||||
function cLocation:new( x, y, z )
|
||||
local object = { x = x, y = y, z = z }
|
||||
setmetatable(object, { __index = cLocation })
|
||||
return object
|
||||
end
|
||||
|
||||
-- Offsets
|
||||
cFibers = { }
|
||||
function cFibers:new()
|
||||
local object = {
|
||||
cLocation:new( 2, -1, 2 ),
|
||||
cLocation:new( 2, -1, 1 ),
|
||||
cLocation:new( 2, -1, 0 ),
|
||||
cLocation:new( 2, -1, -1 ),
|
||||
cLocation:new( 2, -1, -2 ),
|
||||
cLocation:new( 1, -1, 2 ),
|
||||
cLocation:new( 1, -1, 1 ),
|
||||
cLocation:new( 1, -1, 0 ),
|
||||
cLocation:new( 1, -1, -1 ),
|
||||
cLocation:new( 1, -1, -2 ),
|
||||
cLocation:new( 0, -1, 2 ),
|
||||
cLocation:new( 0, -1, 1 ),
|
||||
cLocation:new( 0, -1, 0 ),
|
||||
cLocation:new( 0, -1, -1 ),
|
||||
cLocation:new( 0, -1, -2 ),
|
||||
cLocation:new( -1, -1, 2 ),
|
||||
cLocation:new( -1, -1, 1 ),
|
||||
cLocation:new( -1, -1, 0 ),
|
||||
cLocation:new( -1, -1, -1 ),
|
||||
cLocation:new( -1, -1, -2 ),
|
||||
cLocation:new( -2, -1, 2 ),
|
||||
cLocation:new( -2, -1, 1 ),
|
||||
cLocation:new( -2, -1, 0 ),
|
||||
cLocation:new( -2, -1, -1 ),
|
||||
cLocation:new( -2, -1, -2 ),
|
||||
imadeit = false,
|
||||
}
|
||||
setmetatable(object, { __index = cFibers })
|
||||
return object;
|
||||
end
|
||||
|
||||
-- Carpet object
|
||||
cCarpet = {}
|
||||
function cCarpet:new()
|
||||
local object = { Location = cLocation:new(0,0,0),
|
||||
Fibers = cFibers:new(),
|
||||
}
|
||||
setmetatable(object, { __index = cCarpet })
|
||||
return object
|
||||
end
|
||||
|
||||
function cCarpet:remove()
|
||||
local World = cRoot:Get():GetDefaultWorld()
|
||||
for i, fib in ipairs( self.Fibers ) do
|
||||
local x = self.Location.x + fib.x
|
||||
local y = self.Location.y + fib.y
|
||||
local z = self.Location.z + fib.z
|
||||
local BlockID = World:GetBlock( x, y, z )
|
||||
if( fib.imadeit == true and BlockID == E_BLOCK_GLASS ) then
|
||||
World:SetBlock( x, y, z, 0, 0 )
|
||||
fib.imadeit = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function cCarpet:draw()
|
||||
local World = cRoot:Get():GetDefaultWorld()
|
||||
for i, fib in ipairs( self.Fibers ) do
|
||||
local x = self.Location.x + fib.x
|
||||
local y = self.Location.y + fib.y
|
||||
local z = self.Location.z + fib.z
|
||||
local BlockID = World:GetBlock( x, y, z )
|
||||
if( BlockID == 0 ) then
|
||||
fib.imadeit = true
|
||||
World:SetBlock( x, y, z, E_BLOCK_GLASS, 0 )
|
||||
else
|
||||
fib.imadeit = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function cCarpet:moveTo( NewPos )
|
||||
local x = math.floor( NewPos.x )
|
||||
local y = math.floor( NewPos.y )
|
||||
local z = math.floor( NewPos.z )
|
||||
if( self.Location.x ~= x or self.Location.y ~= y or self.Location.z ~= z ) then
|
||||
self:remove()
|
||||
self.Location = cLocation:new( x, y, z )
|
||||
self:draw()
|
||||
end
|
||||
end
|
||||
|
||||
function cCarpet:getY()
|
||||
return self.Location.y
|
||||
end
|
@ -1,322 +1,322 @@
|
||||
|
||||
-- CommandHandlers.lua
|
||||
-- Defines the individual command handlers
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function InitializeCommandHandlers()
|
||||
local PlgMgr = cRoot:Get():GetPluginManager();
|
||||
for idx, Cmd in ipairs(CommandReg()) do
|
||||
PlgMgr:BindCommand(Cmd[2], Cmd[3], Cmd[1], Cmd[4]);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Handles the ProtAdd command
|
||||
function HandleAddArea(a_Split, a_Player)
|
||||
-- Command syntax: ProtAdd username1 [username2] [username3] ...
|
||||
if (#a_Split < 2) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedListOfUsernames);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Get the cuboid that the player had selected
|
||||
local CmdState = GetCommandStateForPlayer(a_Player);
|
||||
if (CmdState == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrCmdStateNilAddArea);
|
||||
return true;
|
||||
end
|
||||
local Cuboid = CmdState:GetCurrentCuboid();
|
||||
if (Cuboid == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrNoAreaWanded);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Put all allowed players into a table:
|
||||
AllowedNames = {};
|
||||
for i = 2, #a_Split do
|
||||
table.insert(AllowedNames, a_Split[i]);
|
||||
end
|
||||
|
||||
-- Add the area to the storage
|
||||
local AreaID = g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
|
||||
a_Player:SendMessage(string.format(g_Msgs.AreaAdded, AreaID));
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleAddAreaCoords(a_Split, a_Player)
|
||||
-- Command syntax: ProtAddCoords x1 z1 x2 z2 username1 [username2] [username3] ...
|
||||
if (#a_Split < 6) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedCoordsUsernames);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Convert the coords to a cCuboid
|
||||
local x1, z1 = tonumber(a_Split[2]), tonumber(a_Split[3]);
|
||||
local x2, z2 = tonumber(a_Split[4]), tonumber(a_Split[5]);
|
||||
if ((x1 == nil) or (z1 == nil) or (x2 == nil) or (z2 == nil)) then
|
||||
a_Player:SendMessage(g_Msgs.ErrParseCoords);
|
||||
return true;
|
||||
end
|
||||
local Cuboid = cCuboid(x1, 0, z1, x2, 255, z1);
|
||||
Cuboid:Sort();
|
||||
|
||||
-- Put all allowed players into a table:
|
||||
AllowedNames = {};
|
||||
for i = 6, #a_Split do
|
||||
table.insert(AllowedNames, a_Split[i]);
|
||||
end
|
||||
|
||||
-- Add the area to the storage
|
||||
local AreaID = g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
|
||||
a_Player:SendMessage(string.format(g_Msgs.AreaAdded, AreaID));
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleAddAreaUser(a_Split, a_Player)
|
||||
-- Command syntax: ProtAddUser AreaID username1 [username2] [username3] ...
|
||||
if (#a_Split < 3) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedAreaIDUsernames);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Put all allowed players into a table:
|
||||
AllowedNames = {};
|
||||
for i = 3, #a_Split do
|
||||
table.insert(AllowedNames, a_Split[i]);
|
||||
end
|
||||
|
||||
-- Add the area to the storage
|
||||
if (not(g_Storage:AddAreaUsers(
|
||||
tonumber(a_Split[2]), a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames))
|
||||
) then
|
||||
LOGWARNING("g_Storage:AddAreaUsers failed");
|
||||
a_Player:SendMessage(g_Msgs.ErrDBFailAddUsers);
|
||||
return true;
|
||||
end
|
||||
if (#AllowedNames == 0) then
|
||||
a_Player:SendMessage(g_Msgs.AllUsersAlreadyAllowed);
|
||||
else
|
||||
a_Player:SendMessage(string.format(g_Msgs.UsersAdded, table.concat(AllowedNames, ", ")));
|
||||
end
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleDelArea(a_Split, a_Player)
|
||||
-- Command syntax: ProtDelArea AreaID
|
||||
if (#a_Split ~= 2) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedAreaID);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Parse the AreaID
|
||||
local AreaID = tonumber(a_Split[2]);
|
||||
if (AreaID == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrParseAreaID);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Delete the area
|
||||
g_Storage:DelArea(a_Player:GetWorld():GetName(), AreaID);
|
||||
|
||||
a_Player:SendMessage(string.format(g_Msgs.AreaDeleted, AreaID));
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleGiveWand(a_Split, a_Player)
|
||||
local NumGiven = a_Player:GetInventory():AddItem(cConfig:GetWandItem());
|
||||
if (NumGiven == 1) then
|
||||
a_Player:SendMessage(g_Msgs.WandGiven);
|
||||
else
|
||||
a_Player:SendMessage(g_Msgs.ErrNoSpaceForWand);
|
||||
end
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleListAreas(a_Split, a_Player)
|
||||
-- Command syntax: ProtListAreas [x, z]
|
||||
|
||||
local x, z;
|
||||
if (#a_Split == 1) then
|
||||
-- Get the last "wanded" coord
|
||||
local CmdState = GetCommandStateForPlayer(a_Player);
|
||||
if (CmdState == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrCmdStateNilListAreas);
|
||||
return true;
|
||||
end
|
||||
x, z = CmdState:GetLastCoords();
|
||||
if ((x == nil) or (z == nil)) then
|
||||
a_Player:SendMessage(g_Msgs.ErrListNotWanded);
|
||||
return true;
|
||||
end
|
||||
elseif (#a_Split == 3) then
|
||||
-- Parse the coords from the command params
|
||||
x = tonumber(a_Split[2]);
|
||||
z = tonumber(a_Split[3]);
|
||||
if ((x == nil) or (z == nil)) then
|
||||
a_Player:SendMessage(g_Msgs.ErrParseCoordsListAreas);
|
||||
return true;
|
||||
end
|
||||
else
|
||||
-- Wrong number of params, report back to the user
|
||||
a_Player:SendMessage(g_Msgs.ErrSyntaxErrorListAreas);
|
||||
return true;
|
||||
end
|
||||
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListAreasHeader, x, z));
|
||||
|
||||
-- List areas intersecting the coords
|
||||
local PlayerName = a_Player:GetName();
|
||||
local WorldName = a_Player:GetWorld():GetName();
|
||||
g_Storage:ForEachArea(x, z, WorldName,
|
||||
function(AreaID, MinX, MinZ, MaxX, MaxZ, CreatorName)
|
||||
local Coords = string.format("%s: {%d, %d} - {%d, %d} ", AreaID, MinX, MinZ, MaxX, MaxZ);
|
||||
local Allowance;
|
||||
if (g_Storage:IsAreaAllowed(AreaID, PlayerName, WorldName)) then
|
||||
Allowance = g_Msgs.AreaAllowed;
|
||||
else
|
||||
Allowance = g_Msgs.AreaNotAllowed;
|
||||
end
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListAreasRow, Coords, Allowance, CreatorName));
|
||||
end
|
||||
);
|
||||
|
||||
a_Player:SendMessage(g_Msgs.ListAreasFooter);
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Lists all allowed users for a particular area
|
||||
function HandleListUsers(a_Split, a_Player)
|
||||
-- Command syntax: ProtListUsers AreaID
|
||||
if (#a_Split ~= 2) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedAreaID);
|
||||
end
|
||||
|
||||
-- Get the general info about the area
|
||||
local AreaID = a_Split[2];
|
||||
local WorldName = a_Player:GetWorld():GetName();
|
||||
local MinX, MinZ, MaxX, MaxZ, CreatorName = g_Storage:GetArea(AreaID, WorldName);
|
||||
if (MinX == nil) then
|
||||
a_Player:SendMessage(string.format(g_Msgs.ErrNoSuchArea, AreaID));
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Send the header
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListUsersHeader, AreaID, MinX, MinZ, MaxX, MaxZ, CreatorName));
|
||||
|
||||
-- List and count the allowed users
|
||||
local NumUsers = 0;
|
||||
g_Storage:ForEachUserInArea(AreaID, WorldName,
|
||||
function(UserName)
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListUsersRow, UserName));
|
||||
NumUsers = NumUsers + 1;
|
||||
end
|
||||
);
|
||||
|
||||
-- Send the footer
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListUsersFooter, AreaID, NumUsers));
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleRemoveUser(a_Split, a_Player)
|
||||
-- Command syntax: ProtRemUser AreaID UserName
|
||||
if (#a_Split ~= 3) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedAreaIDUserName);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Parse the AreaID
|
||||
local AreaID = tonumber(a_Split[2]);
|
||||
if (AreaID == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrParseAreaID);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Remove the user from the DB
|
||||
local UserName = a_Split[3];
|
||||
g_Storage:RemoveUser(AreaID, UserName, a_Player:GetWorld():GetName());
|
||||
|
||||
-- Send confirmation
|
||||
a_Player:SendMessage(string.format(g_Msgs.RemovedUser, UserName, AreaID));
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleRemoveUserAll(a_Split, a_Player)
|
||||
-- Command syntax: ProtRemUserAll UserName
|
||||
if (#a_Split ~= 2) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedUserName);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Remove the user from the DB
|
||||
g_Storage:RemoveUserAll(a_Split[2], a_Player:GetWorld():GetName());
|
||||
|
||||
-- Send confirmation
|
||||
a_Player:SendMessage(string.format(g_Msgs.RemovedUserAll, UserName));
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- CommandHandlers.lua
|
||||
-- Defines the individual command handlers
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function InitializeCommandHandlers()
|
||||
local PlgMgr = cRoot:Get():GetPluginManager();
|
||||
for idx, Cmd in ipairs(CommandReg()) do
|
||||
PlgMgr:BindCommand(Cmd[2], Cmd[3], Cmd[1], Cmd[4]);
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Handles the ProtAdd command
|
||||
function HandleAddArea(a_Split, a_Player)
|
||||
-- Command syntax: ProtAdd username1 [username2] [username3] ...
|
||||
if (#a_Split < 2) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedListOfUsernames);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Get the cuboid that the player had selected
|
||||
local CmdState = GetCommandStateForPlayer(a_Player);
|
||||
if (CmdState == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrCmdStateNilAddArea);
|
||||
return true;
|
||||
end
|
||||
local Cuboid = CmdState:GetCurrentCuboid();
|
||||
if (Cuboid == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrNoAreaWanded);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Put all allowed players into a table:
|
||||
AllowedNames = {};
|
||||
for i = 2, #a_Split do
|
||||
table.insert(AllowedNames, a_Split[i]);
|
||||
end
|
||||
|
||||
-- Add the area to the storage
|
||||
local AreaID = g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
|
||||
a_Player:SendMessage(string.format(g_Msgs.AreaAdded, AreaID));
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleAddAreaCoords(a_Split, a_Player)
|
||||
-- Command syntax: ProtAddCoords x1 z1 x2 z2 username1 [username2] [username3] ...
|
||||
if (#a_Split < 6) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedCoordsUsernames);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Convert the coords to a cCuboid
|
||||
local x1, z1 = tonumber(a_Split[2]), tonumber(a_Split[3]);
|
||||
local x2, z2 = tonumber(a_Split[4]), tonumber(a_Split[5]);
|
||||
if ((x1 == nil) or (z1 == nil) or (x2 == nil) or (z2 == nil)) then
|
||||
a_Player:SendMessage(g_Msgs.ErrParseCoords);
|
||||
return true;
|
||||
end
|
||||
local Cuboid = cCuboid(x1, 0, z1, x2, 255, z1);
|
||||
Cuboid:Sort();
|
||||
|
||||
-- Put all allowed players into a table:
|
||||
AllowedNames = {};
|
||||
for i = 6, #a_Split do
|
||||
table.insert(AllowedNames, a_Split[i]);
|
||||
end
|
||||
|
||||
-- Add the area to the storage
|
||||
local AreaID = g_Storage:AddArea(Cuboid, a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames);
|
||||
a_Player:SendMessage(string.format(g_Msgs.AreaAdded, AreaID));
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleAddAreaUser(a_Split, a_Player)
|
||||
-- Command syntax: ProtAddUser AreaID username1 [username2] [username3] ...
|
||||
if (#a_Split < 3) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedAreaIDUsernames);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Put all allowed players into a table:
|
||||
AllowedNames = {};
|
||||
for i = 3, #a_Split do
|
||||
table.insert(AllowedNames, a_Split[i]);
|
||||
end
|
||||
|
||||
-- Add the area to the storage
|
||||
if (not(g_Storage:AddAreaUsers(
|
||||
tonumber(a_Split[2]), a_Player:GetWorld():GetName(), a_Player:GetName(), AllowedNames))
|
||||
) then
|
||||
LOGWARNING("g_Storage:AddAreaUsers failed");
|
||||
a_Player:SendMessage(g_Msgs.ErrDBFailAddUsers);
|
||||
return true;
|
||||
end
|
||||
if (#AllowedNames == 0) then
|
||||
a_Player:SendMessage(g_Msgs.AllUsersAlreadyAllowed);
|
||||
else
|
||||
a_Player:SendMessage(string.format(g_Msgs.UsersAdded, table.concat(AllowedNames, ", ")));
|
||||
end
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleDelArea(a_Split, a_Player)
|
||||
-- Command syntax: ProtDelArea AreaID
|
||||
if (#a_Split ~= 2) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedAreaID);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Parse the AreaID
|
||||
local AreaID = tonumber(a_Split[2]);
|
||||
if (AreaID == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrParseAreaID);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Delete the area
|
||||
g_Storage:DelArea(a_Player:GetWorld():GetName(), AreaID);
|
||||
|
||||
a_Player:SendMessage(string.format(g_Msgs.AreaDeleted, AreaID));
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleGiveWand(a_Split, a_Player)
|
||||
local NumGiven = a_Player:GetInventory():AddItem(cConfig:GetWandItem());
|
||||
if (NumGiven == 1) then
|
||||
a_Player:SendMessage(g_Msgs.WandGiven);
|
||||
else
|
||||
a_Player:SendMessage(g_Msgs.ErrNoSpaceForWand);
|
||||
end
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleListAreas(a_Split, a_Player)
|
||||
-- Command syntax: ProtListAreas [x, z]
|
||||
|
||||
local x, z;
|
||||
if (#a_Split == 1) then
|
||||
-- Get the last "wanded" coord
|
||||
local CmdState = GetCommandStateForPlayer(a_Player);
|
||||
if (CmdState == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrCmdStateNilListAreas);
|
||||
return true;
|
||||
end
|
||||
x, z = CmdState:GetLastCoords();
|
||||
if ((x == nil) or (z == nil)) then
|
||||
a_Player:SendMessage(g_Msgs.ErrListNotWanded);
|
||||
return true;
|
||||
end
|
||||
elseif (#a_Split == 3) then
|
||||
-- Parse the coords from the command params
|
||||
x = tonumber(a_Split[2]);
|
||||
z = tonumber(a_Split[3]);
|
||||
if ((x == nil) or (z == nil)) then
|
||||
a_Player:SendMessage(g_Msgs.ErrParseCoordsListAreas);
|
||||
return true;
|
||||
end
|
||||
else
|
||||
-- Wrong number of params, report back to the user
|
||||
a_Player:SendMessage(g_Msgs.ErrSyntaxErrorListAreas);
|
||||
return true;
|
||||
end
|
||||
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListAreasHeader, x, z));
|
||||
|
||||
-- List areas intersecting the coords
|
||||
local PlayerName = a_Player:GetName();
|
||||
local WorldName = a_Player:GetWorld():GetName();
|
||||
g_Storage:ForEachArea(x, z, WorldName,
|
||||
function(AreaID, MinX, MinZ, MaxX, MaxZ, CreatorName)
|
||||
local Coords = string.format("%s: {%d, %d} - {%d, %d} ", AreaID, MinX, MinZ, MaxX, MaxZ);
|
||||
local Allowance;
|
||||
if (g_Storage:IsAreaAllowed(AreaID, PlayerName, WorldName)) then
|
||||
Allowance = g_Msgs.AreaAllowed;
|
||||
else
|
||||
Allowance = g_Msgs.AreaNotAllowed;
|
||||
end
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListAreasRow, Coords, Allowance, CreatorName));
|
||||
end
|
||||
);
|
||||
|
||||
a_Player:SendMessage(g_Msgs.ListAreasFooter);
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
--- Lists all allowed users for a particular area
|
||||
function HandleListUsers(a_Split, a_Player)
|
||||
-- Command syntax: ProtListUsers AreaID
|
||||
if (#a_Split ~= 2) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedAreaID);
|
||||
end
|
||||
|
||||
-- Get the general info about the area
|
||||
local AreaID = a_Split[2];
|
||||
local WorldName = a_Player:GetWorld():GetName();
|
||||
local MinX, MinZ, MaxX, MaxZ, CreatorName = g_Storage:GetArea(AreaID, WorldName);
|
||||
if (MinX == nil) then
|
||||
a_Player:SendMessage(string.format(g_Msgs.ErrNoSuchArea, AreaID));
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Send the header
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListUsersHeader, AreaID, MinX, MinZ, MaxX, MaxZ, CreatorName));
|
||||
|
||||
-- List and count the allowed users
|
||||
local NumUsers = 0;
|
||||
g_Storage:ForEachUserInArea(AreaID, WorldName,
|
||||
function(UserName)
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListUsersRow, UserName));
|
||||
NumUsers = NumUsers + 1;
|
||||
end
|
||||
);
|
||||
|
||||
-- Send the footer
|
||||
a_Player:SendMessage(string.format(g_Msgs.ListUsersFooter, AreaID, NumUsers));
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleRemoveUser(a_Split, a_Player)
|
||||
-- Command syntax: ProtRemUser AreaID UserName
|
||||
if (#a_Split ~= 3) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedAreaIDUserName);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Parse the AreaID
|
||||
local AreaID = tonumber(a_Split[2]);
|
||||
if (AreaID == nil) then
|
||||
a_Player:SendMessage(g_Msgs.ErrParseAreaID);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Remove the user from the DB
|
||||
local UserName = a_Split[3];
|
||||
g_Storage:RemoveUser(AreaID, UserName, a_Player:GetWorld():GetName());
|
||||
|
||||
-- Send confirmation
|
||||
a_Player:SendMessage(string.format(g_Msgs.RemovedUser, UserName, AreaID));
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function HandleRemoveUserAll(a_Split, a_Player)
|
||||
-- Command syntax: ProtRemUserAll UserName
|
||||
if (#a_Split ~= 2) then
|
||||
a_Player:SendMessage(g_Msgs.ErrExpectedUserName);
|
||||
return true;
|
||||
end
|
||||
|
||||
-- Remove the user from the DB
|
||||
g_Storage:RemoveUserAll(a_Split[2], a_Player:GetWorld():GetName());
|
||||
|
||||
-- Send confirmation
|
||||
a_Player:SendMessage(string.format(g_Msgs.RemovedUserAll, UserName));
|
||||
|
||||
-- Reload all currently logged in players
|
||||
ReloadAllPlayersInWorld(a_Player:GetWorld():GetName());
|
||||
|
||||
return true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,121 +1,121 @@
|
||||
|
||||
-- CommandState.lua
|
||||
|
||||
-- Implements the cCommandState class representing a command state for each VIP player
|
||||
|
||||
--[[
|
||||
The command state holds internal info, such as the coords they selected using the wand
|
||||
The command state needs to be held in a per-entity manner, so that we can support multiple logins
|
||||
from the same account (just for the fun of it)
|
||||
The OOP class implementation follows the PiL 16.1
|
||||
|
||||
Also, a global table g_CommandStates is the map of PlayerEntityID -> cCommandState
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cCommandState = {
|
||||
-- Default coords
|
||||
m_Coords1 = {x = 0, z = 0}; -- lclk coords
|
||||
m_Coords2 = {x = 0, z = 0}; -- rclk coords
|
||||
m_LastCoords = 0; -- When Coords1 or Coords2 is set, this gets set to 1 or 2, signifying the last changed set of coords
|
||||
m_HasCoords1 = false; -- Set to true when m_Coords1 has been set by the user
|
||||
m_HasCoords2 = false; -- Set to true when m_Coords2 has been set by the user
|
||||
};
|
||||
|
||||
g_CommandStates = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function cCommandState:new(obj)
|
||||
obj = obj or {};
|
||||
setmetatable(obj, self);
|
||||
self.__index = self;
|
||||
return obj;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns the current coord pair as a cCuboid object
|
||||
function cCommandState:GetCurrentCuboid()
|
||||
if (not(self.m_HasCoords1) or not(self.m_HasCoords2)) then
|
||||
-- Some of the coords haven't been set yet
|
||||
return nil;
|
||||
end
|
||||
|
||||
local res = cCuboid(
|
||||
self.m_Coords1.x, 0, self.m_Coords1.z,
|
||||
self.m_Coords2.x, 255, self.m_Coords2.z
|
||||
);
|
||||
res:Sort();
|
||||
return res;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns the x, z coords that were the set last,
|
||||
-- That is, either m_Coords1 or m_Coords2, based on m_LastCoords member
|
||||
-- Returns nothing if no coords were set yet
|
||||
function cCommandState:GetLastCoords()
|
||||
if (self.m_LastCoords == 0) then
|
||||
-- No coords have been set yet
|
||||
return;
|
||||
elseif (self.m_LastCoords == 1) then
|
||||
return self.m_Coords1.x, self.m_Coords1.z;
|
||||
elseif (self.m_LastCoords == 2) then
|
||||
return self.m_Coords2.x, self.m_Coords2.z;
|
||||
else
|
||||
LOGWARNING(PluginPrefix .. "cCommandState is in an unexpected state, m_LastCoords == " .. self.m_LastCoords);
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Sets the first set of coords (upon rclk with a wand)
|
||||
function cCommandState:SetCoords1(a_BlockX, a_BlockZ)
|
||||
self.m_Coords1.x = a_BlockX;
|
||||
self.m_Coords1.z = a_BlockZ;
|
||||
self.m_LastCoords = 1;
|
||||
self.m_HasCoords1 = true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Sets the second set of coords (upon lclk with a wand)
|
||||
function cCommandState:SetCoords2(a_BlockX, a_BlockZ)
|
||||
self.m_Coords2.x = a_BlockX;
|
||||
self.m_Coords2.z = a_BlockZ;
|
||||
self.m_LastCoords = 2;
|
||||
self.m_HasCoords2 = true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns the cCommandState for the specified player; creates one if not existant
|
||||
function GetCommandStateForPlayer(a_Player)
|
||||
local res = g_CommandStates[a_Player:GetUniqueID()];
|
||||
if (res == nil) then
|
||||
res = cCommandState:new();
|
||||
g_CommandStates[a_Player:GetUniqueID()] = res;
|
||||
end
|
||||
return res;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- CommandState.lua
|
||||
|
||||
-- Implements the cCommandState class representing a command state for each VIP player
|
||||
|
||||
--[[
|
||||
The command state holds internal info, such as the coords they selected using the wand
|
||||
The command state needs to be held in a per-entity manner, so that we can support multiple logins
|
||||
from the same account (just for the fun of it)
|
||||
The OOP class implementation follows the PiL 16.1
|
||||
|
||||
Also, a global table g_CommandStates is the map of PlayerEntityID -> cCommandState
|
||||
--]]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cCommandState = {
|
||||
-- Default coords
|
||||
m_Coords1 = {x = 0, z = 0}; -- lclk coords
|
||||
m_Coords2 = {x = 0, z = 0}; -- rclk coords
|
||||
m_LastCoords = 0; -- When Coords1 or Coords2 is set, this gets set to 1 or 2, signifying the last changed set of coords
|
||||
m_HasCoords1 = false; -- Set to true when m_Coords1 has been set by the user
|
||||
m_HasCoords2 = false; -- Set to true when m_Coords2 has been set by the user
|
||||
};
|
||||
|
||||
g_CommandStates = {};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function cCommandState:new(obj)
|
||||
obj = obj or {};
|
||||
setmetatable(obj, self);
|
||||
self.__index = self;
|
||||
return obj;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns the current coord pair as a cCuboid object
|
||||
function cCommandState:GetCurrentCuboid()
|
||||
if (not(self.m_HasCoords1) or not(self.m_HasCoords2)) then
|
||||
-- Some of the coords haven't been set yet
|
||||
return nil;
|
||||
end
|
||||
|
||||
local res = cCuboid(
|
||||
self.m_Coords1.x, 0, self.m_Coords1.z,
|
||||
self.m_Coords2.x, 255, self.m_Coords2.z
|
||||
);
|
||||
res:Sort();
|
||||
return res;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns the x, z coords that were the set last,
|
||||
-- That is, either m_Coords1 or m_Coords2, based on m_LastCoords member
|
||||
-- Returns nothing if no coords were set yet
|
||||
function cCommandState:GetLastCoords()
|
||||
if (self.m_LastCoords == 0) then
|
||||
-- No coords have been set yet
|
||||
return;
|
||||
elseif (self.m_LastCoords == 1) then
|
||||
return self.m_Coords1.x, self.m_Coords1.z;
|
||||
elseif (self.m_LastCoords == 2) then
|
||||
return self.m_Coords2.x, self.m_Coords2.z;
|
||||
else
|
||||
LOGWARNING(PluginPrefix .. "cCommandState is in an unexpected state, m_LastCoords == " .. self.m_LastCoords);
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Sets the first set of coords (upon rclk with a wand)
|
||||
function cCommandState:SetCoords1(a_BlockX, a_BlockZ)
|
||||
self.m_Coords1.x = a_BlockX;
|
||||
self.m_Coords1.z = a_BlockZ;
|
||||
self.m_LastCoords = 1;
|
||||
self.m_HasCoords1 = true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Sets the second set of coords (upon lclk with a wand)
|
||||
function cCommandState:SetCoords2(a_BlockX, a_BlockZ)
|
||||
self.m_Coords2.x = a_BlockX;
|
||||
self.m_Coords2.z = a_BlockZ;
|
||||
self.m_LastCoords = 2;
|
||||
self.m_HasCoords2 = true;
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns the cCommandState for the specified player; creates one if not existant
|
||||
function GetCommandStateForPlayer(a_Player)
|
||||
local res = g_CommandStates[a_Player:GetUniqueID()];
|
||||
if (res == nil) then
|
||||
res = cCommandState:new();
|
||||
g_CommandStates[a_Player:GetUniqueID()] = res;
|
||||
end
|
||||
return res;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -1,55 +1,55 @@
|
||||
|
||||
-- Config.lua
|
||||
|
||||
-- Implements the cConfig class that holds the general plugin configuration
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cConfig = {
|
||||
m_Wand = cItem(E_ITEM_STICK, 1, 1); -- The item to be used as the selection wand
|
||||
m_AllowInteractNoArea = true; -- If there's no area, is a player allowed to build / dig?
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Initializes the cConfig object, loads the configuration from an INI file
|
||||
function InitializeConfig()
|
||||
local ini = cIniFile("ProtectionAreas.ini");
|
||||
if (not(ini:ReadFile())) then
|
||||
LOGINFO(PluginPrefix .. "Cannot read ProtectionAreas.ini, all plugin configuration is set to defaults");
|
||||
end
|
||||
local WandItem = cItem();
|
||||
if (
|
||||
StringToItem(ini:GetValueSet("ProtectionAreas", "WandItem", ItemToString(cConfig.m_Wand)), WandItem) and
|
||||
IsValidItem(WandItem.m_ItemType)
|
||||
) then
|
||||
cConfig.m_Wand = WandItem;
|
||||
end
|
||||
cConfig.m_AllowInteractNoArea = ini:GetValueSetB("ProtectionAreas", "AllowInteractNoArea", cConfig.m_AllowInteractNoArea);
|
||||
ini:WriteFile();
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns true if a_Item is the wand tool item
|
||||
function cConfig:IsWand(a_Item)
|
||||
return (
|
||||
(a_Item.m_ItemType == self.m_Wand.m_ItemType) and
|
||||
(a_Item.m_ItemDamage == self.m_Wand.m_ItemDamage)
|
||||
);
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns the wand tool item as a cItem object
|
||||
function cConfig:GetWandItem()
|
||||
return self.m_Wand;
|
||||
|
||||
-- Config.lua
|
||||
|
||||
-- Implements the cConfig class that holds the general plugin configuration
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cConfig = {
|
||||
m_Wand = cItem(E_ITEM_STICK, 1, 1); -- The item to be used as the selection wand
|
||||
m_AllowInteractNoArea = true; -- If there's no area, is a player allowed to build / dig?
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Initializes the cConfig object, loads the configuration from an INI file
|
||||
function InitializeConfig()
|
||||
local ini = cIniFile("ProtectionAreas.ini");
|
||||
if (not(ini:ReadFile())) then
|
||||
LOGINFO(PluginPrefix .. "Cannot read ProtectionAreas.ini, all plugin configuration is set to defaults");
|
||||
end
|
||||
local WandItem = cItem();
|
||||
if (
|
||||
StringToItem(ini:GetValueSet("ProtectionAreas", "WandItem", ItemToString(cConfig.m_Wand)), WandItem) and
|
||||
IsValidItem(WandItem.m_ItemType)
|
||||
) then
|
||||
cConfig.m_Wand = WandItem;
|
||||
end
|
||||
cConfig.m_AllowInteractNoArea = ini:GetValueSetB("ProtectionAreas", "AllowInteractNoArea", cConfig.m_AllowInteractNoArea);
|
||||
ini:WriteFile();
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns true if a_Item is the wand tool item
|
||||
function cConfig:IsWand(a_Item)
|
||||
return (
|
||||
(a_Item.m_ItemType == self.m_Wand.m_ItemType) and
|
||||
(a_Item.m_ItemDamage == self.m_Wand.m_ItemDamage)
|
||||
);
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Returns the wand tool item as a cItem object
|
||||
function cConfig:GetWandItem()
|
||||
return self.m_Wand;
|
||||
end
|
@ -1,76 +1,76 @@
|
||||
|
||||
-- CurrentLng.lua
|
||||
-- This file provides all the translatable strings
|
||||
-- The expectation is that the translators will create copies of this file, translate the texts and then the users will overwrite this file with a specific language version
|
||||
-- Note that the individual languages must not have ".lua" extension, otherwise MCServer will load them and the plugin won't work!
|
||||
|
||||
|
||||
|
||||
|
||||
-- Individual commands, and their help strings. Don't touch the first symbol on each line!
|
||||
-- This needs to be implemented as a function, because it references other functions which might not yet be loaded while Lua is processing the globals
|
||||
|
||||
function CommandReg()
|
||||
return {
|
||||
-- Handler function | Command | Permission | Help text
|
||||
{HandleAddArea, "/ProtAdd", "Prot.Add", "<UserNames> - Adds a new protected area"},
|
||||
{HandleAddAreaCoords, "/ProtAddCoords", "Prot.Add", "<x1> <z1> <x2> <z2> <UserNames> - Adds a new protected area by coords"},
|
||||
{HandleAddAreaUser, "/ProtAddUser", "Prot.AddUser", "<AreaID> <UserNames> - Adds new users to an existing protected area"},
|
||||
{HandleDelArea, "/ProtDelID", "Prot.Del", "<AreaID> - Deletes a protected area by ID"},
|
||||
{HandleGiveWand, "/ProtWand", "Prot.Wand", " - Gives you the wand used for protection"},
|
||||
{HandleListAreas, "/ProtList", "Prot.List", "[<x> <z>] - Lists all areas for the marked block or given coords"},
|
||||
{HandleListUsers, "/ProtUsers", "Prot.List", "<AreaID> - Lists all allowed users for a given area ID"},
|
||||
{HandleRemoveUser, "/ProtRemUser", "Prot.RemUser", "<AreaID> <UserName> - Removes a user from the protected area"},
|
||||
{HandleRemoveUserAll, "/ProtRemUserAll", "Prot.RemUser", "<UserName> - Removes a user from all protected areas"},
|
||||
};
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
--- Messages sent to players
|
||||
g_Msgs =
|
||||
{
|
||||
AllUsersAlreadyAllowed = "All the specified users were already allowed.";
|
||||
AreaAdded = "Area added, ID %s";
|
||||
AreaAllowed = "Allowed";
|
||||
AreaDeleted = "Area ID %s deleted";
|
||||
AreaNotAllowed = "NOT allowed";
|
||||
Coords1Set = "Coords1 set as {%d, %d}";
|
||||
Coords2Set = "Coords2 set as {%d, %d}";
|
||||
ErrCmdStateNilAddArea = "Cannot add area, internal plugin error (CmdState == nil)";
|
||||
ErrCmdStateNilListAreas = "Cannot list areas, internal plugin error (CmdState == nil)";
|
||||
ErrDBFailAddUsers = "Cannot add users, DB failure";
|
||||
ErrExpectedAreaID = "Parameter mismatch. Expected <AreaID>.";
|
||||
ErrExpectedAreaIDUserName = "Parameter mismatch. Expected <AreaID> <UserName>.";
|
||||
ErrExpectedAreaIDUsernames = "Not enough parameters. Expected <AreaID> and a list of usernames.";
|
||||
ErrExpectedCoordsUsernames = "Not enough parameters. Expected <x1> <z1> <x2> <z2> coords and a list of usernames.";
|
||||
ErrExpectedListOfUsernames = "Not enough parameters. Expected a list of usernames.";
|
||||
ErrExpectedUserName = "Parameter mismatch. Expected <UserName>.";
|
||||
ErrListNotWanded = "Cannot list areas, no query point has been selected. Use a ProtWand lclk / rclk to select a point first";
|
||||
ErrNoAreaWanded = "Cannot add area, no area has been selected. Use a ProtWand lclk / rclk to select area first";
|
||||
ErrNoSpaceForWand = "Cannot give wand, no space in your inventory";
|
||||
ErrNoSuchArea = "No such area: %s";
|
||||
ErrParseAreaID = "Cannot parse <AreaID>.";
|
||||
ErrParseCoords = "Cannot parse coords.";
|
||||
ErrParseCoordsListAreas = "Cannot list areas, cannot parse coords in params";
|
||||
ErrSyntaxErrorListAreas = "Cannot list areas, syntax error. Expected either no params or <x> <z>.";
|
||||
ListAreasFooter = "Area list finished";
|
||||
ListAreasHeader = "Listing protection areas intersecting block column {%d, %d}:";
|
||||
ListAreasRow = " %s, %s, created by %s";
|
||||