实现多个玩家联机战斗时的操作转发。
玩家先通过组队服务,组好队伍。队长点击开始攻击后,玩家获得本次战斗的token,再连接战斗转发服务。
战斗转发服务为每个队伍创建一个房间,并仅允许该队伍的玩家加入该房间。房间内的每个玩家是完全平等的,所以每个玩家都不能发送指示性指令,比如开始战斗,结束战斗之类的。
每个玩家根据协议发送自己的状态信息,由服务决定当前应处的状态。
local yield = coroutine.yield | |
local function loadlog(filename) | |
-- local log = {} | |
local f = assert(io.open(filename)) | |
for line in f:lines() do | |
if line == "=======" then | |
break | |
end | |
local ptr, osize, nsize, ret = line:match("([^ ]+) (%d+) (%d+) ([^ ]+)") |
local osprint = print | |
print = function(...) | |
local f = io.open('minifight', 'a+') | |
f:write(table.concat({...}, '\t') .. '\n') | |
f:close() | |
end |
/* | |
* Starting with the semicolon is in case whatever line of code above this example | |
* relied on automatic semicolon insertion (ASI). The browser could accidentally | |
* think this whole example continues from the previous line. The leading semicolon | |
* marks the beginning of our new line if the previous one was not empty or terminated. | |
* | |
* Let us also assume that MyGame is previously defined. | |
* | |
* MyGame.lastRender keeps track of the last provided requestAnimationFrame timestamp. | |
* MyGame.lastTick keeps track of the last update time. Always increments by tickLength. |
const net = require('net'); | |
const rpc = require('./rpc'); | |
var seconds = Math.floor(Date.now() / 1000); | |
const socket = net.connect(8290, '127.0.0.1'); | |
var data = { | |
data: { | |
string: 'asdfasdf aasdf喂你好吗?', | |
}, | |
cmd: 'hall.echo', |
// 图 | |
class Graph { | |
constructor(count, adj_list) { | |
this.count = count // 记录顶点的个数 | |
this.adj = new Array(count) // 邻接表 | |
// 初始化邻接表 | |
for (let i = 0; i < count; i++) { | |
this.adj[i] = new Array() | |
} | |
for (let j = 0, len = adj_list.length; j < len; j++) { |
var originSize = 0 | |
var newSize = 0 | |
var fs = require('fs') | |
var path = require('path') | |
var execSync = require('child_process').execSync | |
function walk(dir) { | |
console.log('dir = ', dir) | |
var dirList = fs.readdirSync(dir), temp |
var reg = /[^\w\d_]/ig; | |
var fileList = {}; | |
var wrongFile = []; | |
var wrongDir = []; | |
var bigFile = []; | |
var sameFile = []; | |
var totalFile = 0; | |
var fileSize = 0; | |
var fileType = {}; | |
var maxFileList = []; |
var redis = require('redis'); | |
var leveldb = require('level'); | |
var root = "./"; | |
var dbfile = root + "backup.db"; | |
var channel = [ | |
"__keyevent@0__:set", | |
"__keyevent@0__:hset", | |
"__keyevent@0__:hmset", | |
"__keyevent@0__:incrby" |