Commit 6ff5d90a authored by 神楽坂玲奈's avatar 神楽坂玲奈

12.2

parent 58ca63d1
......@@ -57,15 +57,33 @@ class Room
@watchers = []
Room.all.push this
@hostinfo =
lflist: 0
rule: 0
mode: 0
enable_priority: false
no_check_deck: false
no_shuffle_deck: false
start_lp: 8000
start_hand: 5
draw_count: 1
time_limit: 180
if name[0...2] == 'M#'
param = [0, 0, 0, 1, 'F', 'F', 'F', 8000, 5, 1]
@hostinfo.mode = 1
else if name[0...2] == 'T#'
param = [0, 0, 0, 2, 'F', 'F', 'F', 8000, 5, 1]
@hostinfo.mode = 2
else if (param = name.match /^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i)
param.shift()
param.unshift(0, 0)
else
param = [0, 0, 0, 0, 'F', 'F', 'F', 8000, 5, 1]
@hostinfo.rule = parseInt(param[1])
@hostinfo.mode = parseInt(param[2])
@hostinfo.enable_priority = param[3] == 'T'
@hostinfo.no_check_deck = param[4] == 'T'
@hostinfo.no_shuffle_deck = param[5] == 'T'
@hostinfo.start_lp = parseInt(param[6])
@hostinfo.start_hand = parseInt(param[7])
@hostinfo.draw_count = parseInt(param[8])
param = [0, @hostinfo.lflist, @hostinfo.rule, @hostinfo.mode, (if @hostinfo.enable_priority then 'T' else 'F'), (if @hostinfo.no_check_deck then 'T' else 'F'), (if @hostinfo.no_shuffle_deck then 'T' else 'F'), @hostinfo.start_lp, @hostinfo.start_hand, @hostinfo.draw_count]
@process = spawn './ygopro', param, cwd: 'ygocore'
@process.on 'exit', (code)=>
......@@ -112,6 +130,7 @@ class Room
return unless @ensure_finish()
match_winner = _.last(@duels).winner
return unless @dueling_players[0] and @dueling_players[1] #a WTF fix
User.findOne { name: @dueling_players[0].name }, (err, player0)=>
if(err)
log.error "error when find user", @dueling_players[0].name, err
......
......@@ -76,16 +76,33 @@
this.watcher_buffers = [];
this.watchers = [];
Room.all.push(this);
this.hostinfo = {
lflist: 0,
rule: 0,
mode: 0,
enable_priority: false,
no_check_deck: false,
no_shuffle_deck: false,
start_lp: 8000,
start_hand: 5,
draw_count: 1,
time_limit: 180
};
if (name.slice(0, 2) === 'M#') {
param = [0, 0, 0, 1, 'F', 'F', 'F', 8000, 5, 1];
this.hostinfo.mode = 1;
} else if (name.slice(0, 2) === 'T#') {
param = [0, 0, 0, 2, 'F', 'F', 'F', 8000, 5, 1];
this.hostinfo.mode = 2;
} else if ((param = name.match(/^(\d)(\d)(T|F)(T|F)(T|F)(\d+),(\d+),(\d+)/i))) {
param.shift();
param.unshift(0, 0);
} else {
param = [0, 0, 0, 0, 'F', 'F', 'F', 8000, 5, 1];
this.hostinfo.rule = parseInt(param[1]);
this.hostinfo.mode = parseInt(param[2]);
this.hostinfo.enable_priority = param[3] === 'T';
this.hostinfo.no_check_deck = param[4] === 'T';
this.hostinfo.no_shuffle_deck = param[5] === 'T';
this.hostinfo.start_lp = parseInt(param[6]);
this.hostinfo.start_hand = parseInt(param[7]);
this.hostinfo.draw_count = parseInt(param[8]);
}
param = [0, this.hostinfo.lflist, this.hostinfo.rule, this.hostinfo.mode, (this.hostinfo.enable_priority ? 'T' : 'F'), (this.hostinfo.no_check_deck ? 'T' : 'F'), (this.hostinfo.no_shuffle_deck ? 'T' : 'F'), this.hostinfo.start_lp, this.hostinfo.start_hand, this.hostinfo.draw_count];
this.process = spawn('./ygopro', param, {
cwd: 'ygocore'
});
......@@ -177,6 +194,9 @@
return;
}
match_winner = _.last(this.duels).winner;
if (!(this.dueling_players[0] && this.dueling_players[1])) {
return;
}
return User.findOne({
name: this.dueling_players[0].name
}, function(err, player0) {
......
This diff is collapsed.
function byteField(p, offset) {
this.length = 1;
this.get = function () {
return p.buf[offset];
}
this.set = function (val) {
p.buf[offset] = val;
}
}
function boolField(p, offset, length) {
this.length = length;
this.get = function () {
return (p.buf[offset] > 0 );
}
this.set = function (val) {
p.buf[offset] = val ? 1 : 0;
}
}
function intField(p, offset, length, le, signed) {
this.length = length;
function bec(cb) {
for (var i = 0; i < length; i++)
cb(i, length - i - 1);
}
function lec(cb) {
for (var i = 0; i < length; i++)
cb(i, i);
}
function getUVal(bor) {
var val = 0;
bor(function (i, o) {
val += Math.pow(256, o) * p.buf[offset + i];
})
return val;
}
function getSVal(bor) {
var val = getUVal(bor);
if ((p.buf[offset + ( le ? (length - 1) : 0)] & 0x80) == 0x80) {
val -= Math.pow(256, length);
}
return val;
}
function setVal(bor, val) {
bor(function (i, o) {
p.buf[offset + i] = Math.floor(val / Math.pow(256, o)) & 0xff;
});
}
this.get = function () {
var bor = le ? lec : bec;
return ( signed ? getSVal(bor) : getUVal(bor));
}
this.set = function (val) {
var bor = le ? lec : bec;
setVal(bor, val);
}
}
function charField(p, offset, length, encoding) {
this.length = length;
this.encoding = encoding;
this.get = function () {
var result = p.buf.toString(this.encoding, offset, offset + length);
var strlen = result.indexOf("\0");
if (strlen == -1) {
return result;
} else {
return result.slice(0, strlen);
}
}
this.set = function (val) {
val += "\0";
if (val.length > length)
val = val.substring(0, length);
p.buf.write(val, offset, this.encoding);
}
}
function structField(p, offset, struct) {
this.length = struct.length();
this.get = function () {
return struct;
}
this.set = function (val) {
struct.set(val);
}
this.allocate = function () {
struct._setBuff(p.buf.slice(offset, offset + struct.length()));
}
}
function arrayField(p, offset, len, type) {
var as = Struct();
var args = [].slice.call(arguments, 4);
args.unshift(0);
for (var i = 0; i < len; i++) {
if (type instanceof Struct) {
as.struct(i, type.clone());
} else if (type in as) {
args[0] = i;
as[type].apply(as, args);
}
}
this.length = as.length();
this.allocate = function () {
as._setBuff(p.buf.slice(offset, offset + as.length()));
}
this.get = function () {
return as;
}
this.set = function (val) {
as.set(val);
}
}
function Struct() {
if (!(this instanceof Struct))
return new Struct;
var priv = {
buf: {},
allocated: false,
len: 0,
fields: {},
closures: []
}, self = this;
function checkAllocated() {
if (priv.allocated)
throw new Error('Cant change struct after allocation');
}
this.word8 = function (key) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new byteField(p, p.len);
p.len++;
});
return this;
};
// Create handlers for various Bool Field Variants
[1, 2, 3, 4].forEach(function (n) {
self['bool' + (n == 1 ? '' : n)] = function (key) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new boolField(p, p.len, n);
p.len += n;
});
return this;
}
});
// Create handlers for various Integer Field Variants
[1, 2, 3, 4, 6, 8].forEach(function (n) {
[true, false].forEach(function (le) {
[true, false].forEach(function (signed) {
var name = 'word' + (n * 8) + ( signed ? 'S' : 'U') + ( le ? 'le' : 'be');
self[name] = function (key) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new intField(p, p.len, n, le, signed);
p.len += n;
});
return this;
};
});
});
});
this.chars = function (key, length, encoding) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new charField(p, p.len, length, encoding || 'ascii');
p.len += length;
});
return this;
}
this.struct = function (key, struct) {
checkAllocated();
priv.closures.push(function (p) {
p.fields[key] = new structField(p, p.len, struct.clone());
p.len += p.fields[key].length;
});
return this;
}
function construct(constructor, args) {
function F() {
return constructor.apply(this, args);
}
F.prototype = constructor.prototype;
return new F();
}
this.array = function (key, length, type) {
checkAllocated();
var args = [].slice.call(arguments, 1);
args.unshift(null);
args.unshift(null);
priv.closures.push(function (p) {
args[0] = p;
args[1] = p.len;
p.fields[key] = construct(arrayField, args);
p.len += p.fields[key].length;
});
return this;
}
var beenHere = false;
function applyClosures(p) {
if (beenHere)
return;
p.closures.forEach(function (el) {
el(p);
});
beenHere = true;
}
function allocateFields() {
for (var key in priv.fields) {
if ('allocate' in priv.fields[key])
priv.fields[key].allocate();
}
}
this._setBuff = function (buff) {
priv.buf = buff;
applyClosures(priv);
allocateFields();
priv.allocated = true;
}
this.allocate = function () {
applyClosures(priv);
priv.buf = new Buffer(priv.len);
allocateFields();
priv.allocated = true;
return this;
}
this._getPriv = function () {
return priv;
}
this.clone = function () {
var c = new Struct;
var p = c._getPriv();
p.closures = priv.closures;
return c;
}
this.length = function () {
applyClosures(priv);
return priv.len;
}
this.get = function (key) {
if (key in priv.fields) {
return priv.fields[key].get();
} else
throw new Error('Can not find field ' + key);
}
this.set = function (key, val) {
if (arguments.length == 2) {
if (key in priv.fields) {
priv.fields[key].set(val);
} else
throw new Error('Can not find field ' + key);
} else if (Buffer.isBuffer(key)) {
this._setBuff(key);
} else {
for (var k in key) {
this.set(k, key[k]);
}
}
}
this.buffer = function () {
return priv.buf;
}
function getFields() {
var fields = {};
Object.keys(priv.fields).forEach(function (key) {
Object.defineProperty(fields, key, {
get: function () {
var res = self.get(key);
if (res instanceof Struct) return res.fields;
else return res;
},
set: function (newVal) {
self.set(key, newVal);
},
enumerable: true
});
});
return fields;
};
var _fields;
Object.defineProperty(this, 'fields', {
get: function () {
if (_fields) return _fields;
return (_fields = getFields());
},
enumerable: true,
configurable: true
});
}
exports.Struct = Struct;
*.node
src/build
src/.lock-wscript
Copyright (c) 2010 Sam Shull http://www.google.com/profiles/brickysam26
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.
node-proxy is an implementation of Harmony Proxies http://wiki.ecmascript.org/doku.php?id=harmony:proxies
that allows the developer to create "catch-all" property handlers for an object or a function in node.js.
Author: Sam Shull
Repository: http://github.com/samshull/node-proxy
Issues: http://github.com/samshull/node-proxy/issues
*** This does not work appropriately in node versions 0.1.100 - 0.1.102. You will need to install node_version.h in $PREFIX/include/node
Methods:
Object create(ProxyHandler handler [, Object proto ] ) throws Error, TypeError
Function createFunction(ProxyHandler handler, Function callTrap [, Function constructTrap ] ) throws Error, TypeError
Boolean isTrapping(Object obj) throws Error
Additional Methods (for ECMAScript 5 compatibliity): @see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf
Boolean freeze(Object obj) throws Error, TypeError
Boolean seal(Object obj) throws Error, TypeError
Boolean preventExtensions(Object obj) throws Error, TypeError
Boolean isFrozen(Object obj) throws Error, TypeError
Boolean isSealed(Object obj) throws Error, TypeError
Boolean isExtensible(Object obj) throws Error, TypeError
PropertyDescriptor getOwnPropertyDescriptor(Object obj, String name) throws Error, TypeError
Boolean defineProperty(Object obj, String name, PropertyDescriptor pd) throws Error, TypeError
Boolean defineProperties(Object obj, Object descriptors) throws Error, TypeError
More methods:
Object hidden(Object obj, String name [, Object value ] ) throws Error
- Set or retrieve a hidden property on an Object
Object clone(Object obj) throws Error
- Create a shallow copy of an Object
Boolean isProxy(Object obj)
- determine if an object was created by Proxy
Boolean setPrototype(Object obj, Object obj) throws Error
-set the prototype of a given object to the second given object
{
'targets': [
{
'target_name': 'nodeproxy',
'sources': [
'src/node-proxy.cc',
],
}
]
}
/*
* This package exports one function: namespace
* in order to create a system of namespace loading
* from a given directory. Directories and files are
* loaded into a proxy object in order to provide a
* system for loading additional files and directories
* the namespace.
*
* This system does not proxy scalar values on an object
* because of the
*
*/
var Proxy = require("node-proxy"),
fs = require("fs"),
sys = require("sys"),
path = require("path"),
undef, extensions;
function isFunction(fn) {
return !!fn &&
Object.prototype.toString.call(fn) ==
"[object Function]";
}
function isScalar(fn) {
switch (typeof fn) {
case "string": return true;
case "number": return true;
}
return false;
}
function inPath(file) {
var i = 0, l = extensions.length;
for (;i<l;++i) {
if (path.existsSync(file + "." + extensions[i])) {
return true;
}
}
return false;
}
exports.namespace = function namespace(filePath, properties) {
properties = properties || {};
var scalar = isScalar(properties),
func = isFunction(filePath),
handlers = {
get: function(rec, name) {
if (name === "valueOf" || name === "toString") {
return function(){
return properties[name]();
};
}
if (!(name in properties)) {
if (func) {
handlers[name] = filePath(name, properties);
} else {
//sys.puts(name);
var file = path.join(filePath, name),
stat, obj;
if (inPath(file)) {
obj = require(file);
}
if (!obj) {
try{
// would work if it was a directory
stat = fs.statSync(file);
} catch(e) {}
}
if (stat || obj) {
properties[name] = obj ?
namespace(file, obj) :
// this allows you to use an
// object as a namespace as well
namespace(file);
} else {
return undef;
}
}
} else if (!isScalar(properties[name]) && !Proxy.isProxy(properties[name])) {
properties[name] = namespace(path.join(filePath, name), properties[name]);
}
//sys.puts("returning");
return properties[name];
},
has: function(name) {
return name === "valueOf" ||
name === "toString" ||
inPath(path.join(filePath, name));
},
set: function(rec, name, value) {
properties[name] = value;
},
"delete": function(name) {
return false;
},
enumerate: function() {
return Object.keys(properties);
},
fix: function() {
return undef;
}
};
return isFunction(properties) ?
Proxy.createFunction(handlers, function() {
return properties.apply(this, arguments);
}) :
Proxy.create(handlers, properties.constructor.prototype);
};
extensions = exports.namespace.extensions = ["js", "node"];
/*
* This is an example of creating an object that autoloads
* files and directories from a specified folder into an object
* in order to emulate a namespace loader.
*
* The preferred naming convention is property names
* of Objects begin lower case, while directory and file names
* should begin upper case in order to avoid naming conflicts
*
*/
var sys = require("sys"),
assert = require("assert"),
namespace = require(__dirname + "/autoload-namespace").namespace,
org = namespace(__dirname + "/org");
sys.puts("test 1");
assert.equal(typeof(org), "object", "org is not an object");
sys.puts("test 2");
assert.equal(typeof(org.w3c), "object", "org.w3c is not an object");
sys.puts("test 3");
assert.equal(typeof(org.w3c.DOM), "object", "org.w3c.DOM is not an object");
sys.puts("test 4");
assert.equal(typeof(org.w3c.DOM.Document), "object", "org.w3c.DOM.Document is not an object");
sys.puts("test 5");
assert.equal(typeof(org.w3c.DOM.Document.string), "string", "org.w3c.DOM.Document.string is not a string");
sys.puts("test 6");
assert.equal(org.w3c.DOM.Document.string.toString(), "String", "org.w3c.DOM.Document.string is not equal to 'String'");
sys.puts("test 7");
assert.equal(typeof(org.w3c.DOM.Document.String.Test), "object", "org.w3c.DOM.Document.String.Test is not an object");
sys.puts("test 8");
assert.equal(typeof(org.w3c.DOM.Document.String.Test.success), "string", "org.w3c.DOM.Document.String.Test.success is not an string");
sys.puts("test 9");
assert.equal(org.w3c.DOM.Document.String.Test.success, "success", "org.w3c.DOM.Document.String.Test.success is not equal to 'success'");
sys.puts(typeof(org.w3c.DOM.Document.create));
sys.puts(typeof(function(){}));
sys.puts(Object.prototype.toString.call(org.w3c.DOM.Document.create));
sys.puts(org.w3c.DOM.Document.create instanceof Function);
org.w3c.DOM.Document.create(sys);
\ No newline at end of file
exports.string = "String";
exports.object = {};
exports.regexp = /regex/;
exports.create = function(sys) {
sys.puts("A proxified function was called inside of Document.js")
};
\ No newline at end of file
module.exports = exports = require('../build/Release/nodeproxy.node');
\ No newline at end of file
{
"name": "node-proxy",
"version": "0.6.0",
"description": "A module for node implementing __noSuchMethod__-type handlers, such as object overloading, as part of the Harmony Catch-All Proxies specification found at http://wiki.ecmascript.org/doku.php?id=harmony:proxies",
"keywords": [
"interceptor",
"proxy",
"overload",
"__noSuchMethod__"
],
"contributors": [
{
"name": "Sam Shull",
"email": "http://www.google.com/profiles/brickysam26"
},
{
"name": "richardms",
"email": "https://github.com/richardms"
},
{
"name": "Andreas Botsikas",
"email": "http://webinos.org/bio-andreas-botsikas/"
}
],
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.html"
}
],
"bugs": {
"url": "http://github.com/samshull/node-proxy/issues"
},
"implements": [
"http://wiki.ecmascript.org/doku.php?id=harmony:proxies"
],
"engines": {
"node": ">=0.6",
"npm": ">= 1.1.17"
},
"repositories": [
{
"type": "git",
"url": "http://github.com/samshull/node-proxy"
}
],
"main": "./lib/node-proxy.js",
"scripts": {
"install": "node-gyp configure build",
"test": "node test/test.js"
},
"readme": "node-proxy is an implementation of Harmony Proxies http://wiki.ecmascript.org/doku.php?id=harmony:proxies\nthat allows the developer to create \"catch-all\" property handlers for an object or a function in node.js.\n\nAuthor: Sam Shull \nRepository: http://github.com/samshull/node-proxy \nIssues: http://github.com/samshull/node-proxy/issues \n\n*** This does not work appropriately in node versions 0.1.100 - 0.1.102. You will need to install node_version.h in $PREFIX/include/node\n\nMethods:\n\nObject create(ProxyHandler handler [, Object proto ] ) throws Error, TypeError\n\nFunction createFunction(ProxyHandler handler, Function callTrap [, Function constructTrap ] ) throws Error, TypeError\n\nBoolean isTrapping(Object obj) throws Error\n\n\nAdditional Methods (for ECMAScript 5 compatibliity): @see http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf\n\nBoolean freeze(Object obj) throws Error, TypeError\n\nBoolean seal(Object obj) throws Error, TypeError\n\nBoolean preventExtensions(Object obj) throws Error, TypeError\n\nBoolean isFrozen(Object obj) throws Error, TypeError\n\nBoolean isSealed(Object obj) throws Error, TypeError\n\nBoolean isExtensible(Object obj) throws Error, TypeError\n\nPropertyDescriptor getOwnPropertyDescriptor(Object obj, String name) throws Error, TypeError\n\nBoolean defineProperty(Object obj, String name, PropertyDescriptor pd) throws Error, TypeError\n\nBoolean defineProperties(Object obj, Object descriptors) throws Error, TypeError\n\n\nMore methods:\n\nObject hidden(Object obj, String name [, Object value ] ) throws Error\n- Set or retrieve a hidden property on an Object\n\nObject clone(Object obj) throws Error\n- Create a shallow copy of an Object\n\nBoolean isProxy(Object obj)\n- determine if an object was created by Proxy\n\nBoolean setPrototype(Object obj, Object obj) throws Error\n-set the prototype of a given object to the second given object\n",
"readmeFilename": "README.md",
"repository": {
"type": "git",
"url": "http://github.com/samshull/node-proxy"
},
"_id": "node-proxy@0.6.0",
"dist": {
"shasum": "cb44fdeb7efc10ad4e0fb4b6478da3b19bd9fa81"
},
"_from": "node-proxy@>=0.5.1",
"_resolved": "https://registry.npmjs.org/node-proxy/-/node-proxy-0.6.0.tgz"
}
This diff is collapsed.
/**
*
*
*
* @author Sam Shull <http://samshull.blogspot.com/>
* @version 0.1
*
* @copyright Copyright (c) 2009 Sam Shull <http://samshull.blogspot.com/>
* @license <http://www.opensource.org/licenses/mit-license.html>
*
* 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.
*
*
* CHANGES:
*/
#ifndef NODE_PROXY_H // NOLINT
#define NODE_PROXY_H
#include <v8.h>
#include <node.h>
#include <node_version.h>
#define THREXCW(str) ThrowException(Exception::Error(str))
#define THREXC(str) THREXCW(String::New(str))
#define THR_TYPE_ERROR(str) \
ThrowException(Exception::TypeError(String::New(str)))
#define PROXY_NODE_PSYMBOL(s) \
Persistent<String>::New(String::NewSymbol(s))
// had to redefine NODE_VERSION_AT_LEAST here because of missing parenthesis
#define PROXY_NODE_VERSION_AT_LEAST(major, minor, patch) \
(((major) < NODE_MAJOR_VERSION) \
|| ((major) == NODE_MAJOR_VERSION && (minor) < NODE_MINOR_VERSION) \
|| ((major) == NODE_MAJOR_VERSION && (minor) == NODE_MINOR_VERSION && \
(patch) <= NODE_PATCH_VERSION))
// using namespace v8;
namespace v8 {
class NodeProxy {
public:
// fundamental traps
static Persistent<String> getOwnPropertyDescriptor;
static Persistent<String> getPropertyDescriptor;
static Persistent<String> getOwnPropertyNames;
static Persistent<String> getPropertyNames;
static Persistent<String> defineProperty;
static Persistent<String> delete_;
static Persistent<String> fix;
// derived traps
static Persistent<String> has;
static Persistent<String> hasOwn;
static Persistent<String> get;
static Persistent<String> set;
static Persistent<String> enumerate;
static Persistent<String> keys;
// string identifiers
static Persistent<String> callTrap;
static Persistent<String> constructorTrap;
static Persistent<String> value;
static Persistent<String> writable;
static Persistent<String> enumerable;
static Persistent<String> configurable;
static Persistent<String> name;
static Persistent<String> trapping;
static Persistent<String> sealed;
static Persistent<String> frozen;
static Persistent<String> extensible;
static Persistent<String> seal;
static Persistent<String> freeze;
static Persistent<String> preventExtensions;
static Persistent<String> isTrapping;
static Persistent<String> isSealed;
static Persistent<String> isFrozen;
static Persistent<String> isExtensible;
static Persistent<String> isProxy;
static Persistent<String> hidden;
static Persistent<String> hiddenPrivate;
static Persistent<ObjectTemplate> ObjectCreator;
static Persistent<ObjectTemplate> FunctionCreator;
static void Init(Handle<Object> target);
protected:
NodeProxy();
~NodeProxy();
static Handle<Integer>
GetPropertyAttributeFromPropertyDescriptor(Local<Object> pd);
static Local<Value> CorrectPropertyDescriptor(Local<Object> pd);
static Handle<Value> ValidateProxyHandler(Local<Object> handler);
static Handle<Value> Clone(const Arguments& args);
static Handle<Value> Hidden(const Arguments& args);
static Handle<Value> Create(const Arguments& args);
static Handle<Value> SetPrototype(const Arguments& args);
static Handle<Value> CreateFunction(const Arguments& args);
static Handle<Value> Freeze(const Arguments& args);
static Handle<Value> IsLocked(const Arguments& args);
static Handle<Value> IsProxy(const Arguments& args);
static Handle<Value> GetOwnPropertyDescriptor(const Arguments& args);
static Handle<Value> DefineProperty(const Arguments& args);
static Handle<Value> DefineProperties(const Arguments& args);
static Handle<Value> New(const Arguments& args);
static Handle<Value>
GetNamedProperty(Local<String> name, const AccessorInfo &info);
static Handle<Value>
SetNamedProperty(Local<String> name,
Local<Value> value,
const AccessorInfo &info);
static Handle<Boolean>
QueryNamedProperty(Local<String> name,
const AccessorInfo &info);
static Handle<Integer>
QueryNamedPropertyInteger(Local<String> name,
const AccessorInfo &info);
static Handle<Boolean>
DeleteNamedProperty(Local<String> name,
const AccessorInfo &info);
static Handle<Array>
EnumerateNamedProperties(const AccessorInfo &info);
static Handle<Value>
GetIndexedProperty(uint32_t index,
const AccessorInfo &info);
static Handle<Value>
SetIndexedProperty(uint32_t index,
Local<Value> value,
const AccessorInfo &info);
static Handle<Boolean>
QueryIndexedProperty(uint32_t index,
const AccessorInfo &info);
static Handle<Integer>
QueryIndexedPropertyInteger(uint32_t index,
const AccessorInfo &info);
static Handle<Boolean>
DeleteIndexedProperty(uint32_t index,
const AccessorInfo &info);
static Local<Value> CallPropertyDescriptorGet(Local<Value> descriptor,
Handle<Object> context,
Local<Value> args[1]);
static Local<Value> CallPropertyDescriptorSet(Local<Value> descriptor,
Handle<Object> context,
Local<Value> name,
Local<Value> value);
};
}
extern "C" void init(v8::Handle<v8::Object> target);
#endif // NODE_CLASSTEMPLATE_H // NOLINT
This diff is collapsed.
......@@ -258,7 +258,10 @@ ygopro.stoc_follow 'JOIN_GAME', false, (buffer, info, client, server)->
watcher.on 'data', (data)->
client.room.watcher_buffers.push data
for w in client.room.watchers
w.write data
w.write data if w #a WTF fix
watcher.on 'error', (error)->
log.error "watcher error", error
#登场台词
if settings.modules.dialogues
......@@ -269,21 +272,67 @@ if settings.modules.dialogues
, (error, response, body)->
if _.isString body
log.warn "dialogues bad json", body
else if error or !body
log.warn 'dialogues error', error, response
else
log.info "dialogues loaded", _.size body
dialogues = body
ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
msg = buffer.readInt8(0)
#log.info 'MSG', ygopro.constants.MSG[msg]
if ygopro.constants.MSG[msg] == 'START'
playertype = buffer.readUInt8(1)
client.is_first = !(playertype & 0xf);
client.lp = client.room.hostinfo.start_lp
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.name} 初始LP #{client.lp}")
if ygopro.constants.MSG[msg] == 'WIN' and _.startsWith(client.room.name, 'M#') and client.is_host
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first or pos == 2
reason = buffer.readUInt8(2)
log.info {winner: pos, reason: reason}
client.room.duels.push {winner: pos, reason: reason}
#lp跟踪
if ygopro.constants.MSG[msg] == 'DAMAGE' and client.is_host
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
val = buffer.readInt32LE(2)
client.room.dueling_players[pos].lp -= val
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.room.dueling_players[pos].name} 受到伤害 #{val},现在的LP为 #{client.room.dueling_players[pos].lp}")
if 0 < client.room.dueling_players[pos].lp <= 100
ygopro.stoc_send_chat_to_room(client.room, "你的生命已经如风中残烛了!")
if ygopro.constants.MSG[msg] == 'RECOVER' and client.is_host
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
val = buffer.readInt32LE(2)
client.room.dueling_players[pos].lp += val
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.room.dueling_players[pos].name} 回复 #{val},现在的LP为 #{client.room.dueling_players[pos].lp}")
if ygopro.constants.MSG[msg] == 'LPUPDATE' and client.is_host
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
val = buffer.readInt32LE(2)
client.room.dueling_players[pos].lp = val
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.room.dueling_players[pos].name} 的LP变成 #{client.room.dueling_players[pos].lp}")
if ygopro.constants.MSG[msg] == 'PAY_LPCOST' and client.is_host
pos = buffer.readUInt8(1)
pos = 1 - pos unless client.is_first
val = buffer.readInt32LE(2)
client.room.dueling_players[pos].lp -= val
#ygopro.stoc_send_chat_to_room(client.room, "LP跟踪调试信息: #{client.room.dueling_players[pos].name} 支付 #{val},现在的LP为 #{client.room.dueling_players[pos].lp}")
if 0 < client.room.dueling_players[pos].lp <= 100
ygopro.stoc_send_chat_to_room(client.room, "背水一战!")
#登场台词
if settings.modules.dialogues
if ygopro.constants.MSG[msg] == 'SUMMONING' or ygopro.constants.MSG[msg] == 'SPSUMMONING'
......@@ -292,6 +341,12 @@ ygopro.stoc_follow 'GAME_MSG', false, (buffer, info, client, server)->
for line in _.lines dialogues[card][Math.floor(Math.random() * dialogues[card].length)]
ygopro.stoc_send_chat client, line
###
#房间管理
ygopro.stoc_follow 'HS_PLAYER_ENTER', false, (buffer, info, client, server)->
......@@ -334,7 +389,10 @@ ygopro.stoc_follow 'DUEL_START', false, (buffer, info, client, server)->
client.room.dueling_players = []
for player in client.room.players when player.pos != 7
client.room.dueling_players[player.pos] = player
player.deck = mycard.load_card_usages_from_cards(player.main, player.side)
if !player.main
log.error 'WTF', client
else
player.deck = mycard.load_card_usages_from_cards(player.main, player.side)
if !client.room.dueling_players[0] or !client.room.dueling_players[1]
log.error 'incomplete room', client.room.dueling_players, client.room.players
......
......@@ -316,17 +316,24 @@
});
return ygopro.ctos_send(watcher, 'HS_TOOBSERVER');
});
return watcher.on('data', function(data) {
watcher.on('data', function(data) {
var w, _i, _len, _ref, _results;
client.room.watcher_buffers.push(data);
_ref = client.room.watchers;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
w = _ref[_i];
_results.push(w.write(data));
if (w) {
_results.push(w.write(data));
} else {
_results.push(void 0);
}
}
return _results;
});
return watcher.on('error', function(error) {
return log.error("watcher error", error);
});
}
});
......@@ -338,6 +345,8 @@
}, function(error, response, body) {
if (_.isString(body)) {
return log.warn("dialogues bad json", body);
} else if (error || !body) {
return log.warn('dialogues error', error, response);
} else {
log.info("dialogues loaded", _.size(body));
return dialogues = body;
......@@ -346,11 +355,12 @@
}
ygopro.stoc_follow('GAME_MSG', false, function(buffer, info, client, server) {
var card, line, msg, playertype, pos, reason, _i, _len, _ref, _results;
var card, line, msg, playertype, pos, reason, val, _i, _len, _ref, _ref1, _ref2, _results;
msg = buffer.readInt8(0);
if (ygopro.constants.MSG[msg] === 'START') {
playertype = buffer.readUInt8(1);
client.is_first = !(playertype & 0xf);
client.lp = client.room.hostinfo.start_lp;
}
if (ygopro.constants.MSG[msg] === 'WIN' && _.startsWith(client.room.name, 'M#') && client.is_host) {
pos = buffer.readUInt8(1);
......@@ -367,14 +377,52 @@
reason: reason
});
}
if (ygopro.constants.MSG[msg] === 'DAMAGE' && client.is_host) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
}
val = buffer.readInt32LE(2);
client.room.dueling_players[pos].lp -= val;
if ((0 < (_ref = client.room.dueling_players[pos].lp) && _ref <= 100)) {
ygopro.stoc_send_chat_to_room(client.room, "你的生命已经如风中残烛了!");
}
}
if (ygopro.constants.MSG[msg] === 'RECOVER' && client.is_host) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
}
val = buffer.readInt32LE(2);
client.room.dueling_players[pos].lp += val;
}
if (ygopro.constants.MSG[msg] === 'LPUPDATE' && client.is_host) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
}
val = buffer.readInt32LE(2);
client.room.dueling_players[pos].lp = val;
}
if (ygopro.constants.MSG[msg] === 'PAY_LPCOST' && client.is_host) {
pos = buffer.readUInt8(1);
if (!client.is_first) {
pos = 1 - pos;
}
val = buffer.readInt32LE(2);
client.room.dueling_players[pos].lp -= val;
if ((0 < (_ref1 = client.room.dueling_players[pos].lp) && _ref1 <= 100)) {
ygopro.stoc_send_chat_to_room(client.room, "背水一战!");
}
}
if (settings.modules.dialogues) {
if (ygopro.constants.MSG[msg] === 'SUMMONING' || ygopro.constants.MSG[msg] === 'SPSUMMONING') {
card = buffer.readUInt32LE(1);
if (dialogues[card]) {
_ref = _.lines(dialogues[card][Math.floor(Math.random() * dialogues[card].length)]);
_ref2 = _.lines(dialogues[card][Math.floor(Math.random() * dialogues[card].length)]);
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
line = _ref[_i];
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
line = _ref2[_i];
_results.push(ygopro.stoc_send_chat(client, line));
}
return _results;
......@@ -437,7 +485,11 @@
continue;
}
client.room.dueling_players[player.pos] = player;
player.deck = mycard.load_card_usages_from_cards(player.main, player.side);
if (!player.main) {
log.error('WTF', client);
} else {
player.deck = mycard.load_card_usages_from_cards(player.main, player.side);
}
}
if (!client.room.dueling_players[0] || !client.room.dueling_players[1]) {
log.error('incomplete room', client.room.dueling_players, client.room.players);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment