diff --git a/docs/proto_main.txt b/docs/proto_main.txt index de51fad..6ddefc4 100644 --- a/docs/proto_main.txt +++ b/docs/proto_main.txt @@ -180,6 +180,12 @@ Iceball Base Mod: 0x10 pid x.fs y.fs z.fs ya.u8 xa.u8: (S->C) @ player spawn + + health is set to 100 + blocks is set to 25 + grenades is set to 2 + + ammo is set to full 0x11 team.s8 weapon.u8 name.z (C->S) @ offer player @@ -189,12 +195,12 @@ Iceball Base Mod: set item position these are hardcoded as follows: - 1 = blue tent - 2 = blue intel - 3 = green tent - 4 = green intel + 1 = blue intel + 2 = blue tent + 3 = green intel + 4 = green tent - 0x13 pid.u8 tpid.u8 type.u8 (C->S) + 0x13 tpid.u8 type.u8 (C->S) @ fire shot, hitting target player yes, do this EVERY shot. @@ -205,3 +211,46 @@ Iceball Base Mod: 1 = head 2 = body 3 = limb + + 0x14 pid.u8 newhealth.u8 (S->C) @ + set health due to damage + + if newhealth is 0, player is dead + + 0x15 (S->C) + tent restock + + health is set to 100 + blocks is set to 100 + grenades is set to 4 + + ammo is set to full + + 0x16 pid.u8 iid.u16 (S->C) + possess item + + if uid == 0, depossess instead + + these are hardcoded as follows: + 1 = blue intel + 2 = blue tent + 3 = green intel + 4 = green tent + + 0x17 pid.u8 tool.u8 @ + set tool + + TOOL_SPADE = 0 + TOOL_BLOCK = 1 + TOOL_GUN = 2 + TOOL_NADE = 3 + + 0x18 pid.u8 r.u8 g.u8 b.u8 @ + set block colour + + 0xE0 map.z (S->C) @ + name of map to fetch + + NOTE: will be deprecated eventually + this is just a simple hack to start with + while i procrastinate server.hook_file diff --git a/pkg/base/client_start.lua b/pkg/base/client_start.lua index 6fe5741..6cd0ea2 100644 --- a/pkg/base/client_start.lua +++ b/pkg/base/client_start.lua @@ -18,8 +18,26 @@ print("pkg/base/client_start.lua starting") print(...) +map_fname = nil + dofile("pkg/base/common.lua") +while true do + local pkt, sockfd, cid + pkt, sockfd = common.net_recv() + cid, pkt = common.net_unpack("B", pkt) + if cid == 0xE0 then + map_fname, pkt = common.net_unpack("z", pkt) + break + else + error("should not receive non-map-filename packets until map filename arrives!") + end +end + +if not map_fname then + error("server should have sent map name by now") +end + user_config = common.json_load("clsave/pub/user.json") print("json done!") print("name:", user_config.name) @@ -305,6 +323,7 @@ function h_tick_main(sec_current, sec_delta) squad = nil, team = tidx, weapon = wpn, + pid = pid, }) players[pid].score = score @@ -315,6 +334,8 @@ function h_tick_main(sec_current, sec_delta) players.current = pid elseif cid == 0x07 then local pid, pkt = common.net_unpack("B", pkt) + -- TODO fix crash bug + --players[pid].free() players[pid] = nil elseif cid == 0x0E then -- add to chat @@ -330,9 +351,39 @@ function h_tick_main(sec_current, sec_delta) local pid, x,y,z, ya,xa pid, x,y,z, ya,xa, pkt = common.net_unpack("Bfffbb", pkt) local plr = players[pid] + --print("client respawn!", players.current, pid, plr) if plr then plr.spawn_at(x,y,z,ya*math.pi/128,xa*math.pi/256) end + elseif cid == 0x14 then + local pid, amt + pid, amt, pkt = common.net_unpack("BB", pkt) + + local plr = players[pid] + --print("hit pkt", pid, amt) + if plr then + plr.set_health_damage(amt, nil, nil) + end + elseif cid == 0x17 then + local pid, tool + pid, tool, pkt = common.net_unpack("BB", pkt) + + local plr = players[pid] + + if plr then + plr.tool_switch(tool) + end + elseif cid == 0x18 then + local pid, cr,cg,cb + pid, cr,cg,cb, pkt = common.net_unpack("BBBB", pkt) + + local plr = players[pid] + + print("recol",cr,cg,cb) + if plr then + plr.blk_color = {cr,cg,cb} + plr.block_recolor() + end end end @@ -525,24 +576,36 @@ function h_key(key, state, modif) plr.blk_color_x = 7 end plr.blk_color = cpalette[plr.blk_color_x+plr.blk_color_y*8+1] + common.net_send(nil, common.net_pack("BBBBB", + 0x18, 0x00, + plr.blk_color[1],plr.blk_color[2],plr.blk_color[3])) elseif key == BTSK_COLORRIGHT then plr.blk_color_x = plr.blk_color_x + 1 if plr.blk_color_x > 7 then plr.blk_color_x = 0 end plr.blk_color = cpalette[plr.blk_color_x+plr.blk_color_y*8+1] + common.net_send(nil, common.net_pack("BBBBB", + 0x18, 0x00, + plr.blk_color[1],plr.blk_color[2],plr.blk_color[3])) elseif key == BTSK_COLORUP then plr.blk_color_y = plr.blk_color_y - 1 if plr.blk_color_y < 0 then plr.blk_color_y = 7 end plr.blk_color = cpalette[plr.blk_color_x+plr.blk_color_y*8+1] + common.net_send(nil, common.net_pack("BBBBB", + 0x18, 0x00, + plr.blk_color[1],plr.blk_color[2],plr.blk_color[3])) elseif key == BTSK_COLORDOWN then plr.blk_color_y = plr.blk_color_y + 1 if plr.blk_color_y > 7 then plr.blk_color_y = 0 end plr.blk_color = cpalette[plr.blk_color_x+plr.blk_color_y*8+1] + common.net_send(nil, common.net_pack("BBBBB", + 0x18, 0x00, + plr.blk_color[1],plr.blk_color[2],plr.blk_color[3])) end end end @@ -598,6 +661,9 @@ function h_mouse_button(button, state) local ct,cr,cg,cb ct,cr,cg,cb = map_block_pick(plr.blx3, plr.bly3, plr.blz3) plr.blk_color = {cr,cg,cb} + common.net_send(nil, common.net_pack("BBBBB", + 0x18, 0x00, + plr.blk_color[1],plr.blk_color[2],plr.blk_color[3])) elseif plr.tool == TOOL_SPADE and plr.blx2 then if plr.blx1 >= 0 and plr.blx1 < xlen and plr.blz1 >= 0 and plr.blz1 < zlen then if plr.bly2-1 <= ylen-3 then @@ -632,8 +698,6 @@ function h_mouse_motion(x, y, dx, dy) end -- load map -map_fname = ... -map_fname = map_fname or MAP_DEFAULT map_loaded = common.map_load(map_fname, "auto") common.map_set(map_loaded) diff --git a/pkg/base/common.lua b/pkg/base/common.lua index f287388..c414f1e 100644 --- a/pkg/base/common.lua +++ b/pkg/base/common.lua @@ -145,6 +145,7 @@ weapons = { -- see if there's anyone we can kill local hurt_idx = nil local hurt_part = nil + local hurt_part_idx = 0 local hurt_dist = d*d local i,j @@ -163,6 +164,7 @@ weapons = { if dot < 0.55 and dd < hurt_dist then hurt_idx = i hurt_dist = dd + hurt_part_idx = j hurt_part = ({"head","body","legs"})[j] break @@ -174,11 +176,23 @@ weapons = { if hurt_idx then -- TODO: ship this off to the server! - players[hurt_idx].gun_damage( - hurt_part, this.cfg.dmg[hurt_part], plr) - elseif cx2 then - -- TODO: block health rather than instant block removal - map_block_break(cx2,cy2,cz2) + if server then + players[hurt_idx].gun_damage( + hurt_part, this.cfg.dmg[hurt_part], plr) + else + common.net_send(nil, common.net_pack("BBB" + , 0x13, hurt_idx, hurt_part_idx)) + end + else + if client then + common.net_send(nil, common.net_pack("BBB" + , 0x13, 0, 0)) + end + + if cx2 then + -- TODO: block health rather than instant block removal + map_block_break(cx2,cy2,cz2) + end end -- TODO: fire a tracer diff --git a/pkg/base/main_server.lua b/pkg/base/main_server.lua index 43152d5..430ee4d 100644 --- a/pkg/base/main_server.lua +++ b/pkg/base/main_server.lua @@ -37,6 +37,7 @@ function slot_add(sockfd, tidx, wpn, name) squad = nil, team = tidx, -- 0 == blue, 1 == green weapon = WPN_RIFLE, + pid = i, }) return i end @@ -84,6 +85,8 @@ function server.hook_connect(sockfd, addrinfo) --[[net_broadcast(nil, common.net_pack("BIz", 0x0E, 0xFF800000, "Connected: player on sockfd "..ss))]] print("Connected: player on sockfd "..ss) + + common.net_send(sockfd, common.net_pack("Bz", 0xE0, map_fname)) end function server.hook_disconnect(sockfd, server_force, reason) @@ -111,6 +114,9 @@ function server.hook_disconnect(sockfd, server_force, reason) "* Player "..plr.name.." disconnected")) net_broadcast(sockfd, common.net_pack("BB", 0x07, plrid)) + + -- TODO fix crash bug + --plr.free() players[plrid] = nil end end @@ -201,6 +207,11 @@ function server.hook_tick(sec_current, sec_delta) 0x10, i, plr.x, plr.y, plr.z, plr.angy*128/math.pi, plr.angx*256/math.pi)) + common.net_send(sockfd, common.net_pack("BBB", + 0x17, i, plr.tool)) + common.net_send(sockfd, common.net_pack("BBBBB", + 0x18, i, + plr.blk_color[1],plr.blk_color[2],plr.blk_color[3])) end end @@ -222,10 +233,49 @@ function server.hook_tick(sec_current, sec_delta) net_broadcast(nil, common.net_pack("BIz", 0x0E, 0xFF800000, "* Player "..name.." has joined the "..teams[plr.team].name.." team")) end + elseif cid == 0x13 and plr then + local tpid, styp + tpid, styp, pkt = common.net_unpack("BB", pkt) + --print("hit", tpid, styp) + + local tplr = players[tpid] + if tplr and styp >= 1 and styp <= 3 then + if tplr.wpn then + local dmg = tplr.wpn.cfg.dmg[({"head","body","legs"})[styp]] + --print("dmg",dmg,tplr.wpn.cfg.dmg) + tplr.gun_damage(styp, dmg, plr) + end + end + elseif cid == 0x17 and plr then + local tpid, tool + tpid, tool, pkt = common.net_unpack("BB", pkt) + + if tool >= 0 and tool <= 3 then + net_broadcast(sockfd, common.net_pack("BBB" + , 0x17, cli.plrid, tool)) + end + elseif cid == 0x18 and plr then + local tpid, cr,cg,cb + tpid, cr,cg,cb, pkt = common.net_unpack("BBBB", pkt) + + net_broadcast(sockfd, common.net_pack("BBBBB" + , 0x18, cli.plrid, cr, cg, cb)) end -- TODO! end + local i + for i=1,players.max do + local plr = players[i] + if plr then + plr.tick(sec_current, sec_delta) + end + end + + for i=1,#intent do + intent[i].tick(sec_current, sec_delta) + end + return 0.005 end @@ -252,4 +302,9 @@ for i=1,players.max do end ]=] +intent[#intent+1] = new_intel({team = 0}) +intent[#intent+1] = new_tent({team = 0}) +intent[#intent+1] = new_intel({team = 1}) +intent[#intent+1] = new_tent({team = 1}) + print("pkg/base/main_server.lua loaded.") diff --git a/pkg/base/obj_intent.lua b/pkg/base/obj_intent.lua index 68715c2..fc2e576 100644 --- a/pkg/base/obj_intent.lua +++ b/pkg/base/obj_intent.lua @@ -29,9 +29,14 @@ function new_intel(settings) this.rotpos = sec_current*2 + if not this.spawned then return end + if this.player then -- anything to do here? else + + if not server then return end + -- set position local l = common.map_pillar_get( math.floor(this.x), @@ -114,6 +119,18 @@ function new_intel(settings) this.spawn() end + function this.prespawn() + this.alive = false + this.spawned = false + this.visible = false + end + + local function prv_spawn_cont1() + this.alive = true + this.spawned = true + this.visible = true + end + function this.spawn() local xlen,ylen,zlen xlen,ylen,zlen = common.map_get_dims() @@ -126,21 +143,39 @@ function new_intel(settings) if this.y < ylen-1 then break end end - this.alive = true - this.spawned = true - this.visible = true + prv_spawn_cont1() + end + + function this.spawn_at(x,y,z) + this.x = x + this.y = y + this.z = z + + prv_spawn_cont1() + end + + function this.get_pos() + return this.x, this.y, this.z + end + + function this.set_pos_recv(x,y,z) + this.x = x + this.y = y + this.z = z end local _ local l = teams[this.team].color_mdl local mbone,mname,mdata - this.mdl_intel = client.model_new(1) - this.mdl_intel, mbone = client.model_bone_new(this.mdl_intel,1) - mname,mdata = common.model_bone_get(mdl_intel, 0) - recolor_component(l[1],l[2],l[3],mdata) - common.model_bone_set(this.mdl_intel, 0, mname, mdata) + if client then + this.mdl_intel = client.model_new(1) + this.mdl_intel, mbone = client.model_bone_new(this.mdl_intel,1) + mname,mdata = common.model_bone_get(mdl_intel, 0) + recolor_component(l[1],l[2],l[3],mdata) + common.model_bone_set(this.mdl_intel, 0, mname, mdata) + end - this.spawn() + this.prespawn() return this end @@ -154,6 +189,10 @@ function new_tent(settings) function this.tick(sec_current, sec_delta) local i + if not server then return end + + if not this.spawned then return end + -- set position local l = common.map_pillar_get( math.floor(this.x), @@ -209,6 +248,18 @@ function new_tent(settings) 0, 0, 0, 3) end + function this.prespawn() + this.alive = false + this.spawned = false + this.visible = false + end + + local function prv_spawn_cont1() + this.alive = true + this.spawned = true + this.visible = true + end + function this.spawn() local xlen,ylen,zlen xlen,ylen,zlen = common.map_get_dims() @@ -221,21 +272,39 @@ function new_tent(settings) if this.y < ylen-1 then break end end - this.alive = true - this.spawned = true - this.visible = true + prv_spawn_cont1() + end + + function this.spawn_at(x,y,z) + this.x = x + this.y = y + this.z = z + + prv_spawn_cont1() + end + + function this.get_pos() + return this.x, this.y, this.z + end + + function this.set_pos_recv(x,y,z) + this.x = x + this.y = y + this.z = z end local _ local l = teams[this.team].color_mdl local mbone,mname,mdata - this.mdl_tent = client.model_new(1) - this.mdl_tent, mbone = client.model_bone_new(this.mdl_tent,1) - mname,mdata = common.model_bone_get(mdl_tent, 0) - recolor_component(l[1],l[2],l[3],mdata) - common.model_bone_set(this.mdl_tent, 0, mname, mdata) + if client then + this.mdl_tent = client.model_new(1) + this.mdl_tent, mbone = client.model_bone_new(this.mdl_tent,1) + mname,mdata = common.model_bone_get(mdl_tent, 0) + recolor_component(l[1],l[2],l[3],mdata) + common.model_bone_set(this.mdl_tent, 0, mname, mdata) + end - this.spawn() + this.prespawn() return this end diff --git a/pkg/base/obj_player.lua b/pkg/base/obj_player.lua index 61c999a..2dc32ba 100644 --- a/pkg/base/obj_player.lua +++ b/pkg/base/obj_player.lua @@ -21,6 +21,7 @@ function new_player(settings) this.team = settings.team or math.floor(math.random()*2) this.squad = settings.squad or nil this.weapon = settings.weapon or WPN_RIFLE + this.pid = settings.pid or error("pid must be set when creating player!") this.alive = false this.spawned = false this.zooming = false @@ -67,6 +68,10 @@ function new_player(settings) prv_recolor_team(r,g,b) end + function this.block_recolor() + prv_recolor_block(this.blk_color[1],this.blk_color[2],this.blk_color[3]) + end + function this.input_reset() this.ev_forward = false this.ev_back = false @@ -111,6 +116,7 @@ function new_player(settings) this.blx2, this.bly2, this.blz2 = nil, nil, nil this.blk_color = {0x7F,0x7F,0x7F} + this.block_recolor() this.blk_color_x = 3 this.blk_color_y = 0 @@ -130,7 +136,7 @@ function new_player(settings) this.has_intel = nil end - function prv_spawn_cont1() + local function prv_spawn_cont1() this.prespawn() this.alive = true @@ -183,6 +189,10 @@ function new_player(settings) this.arm_rest_right = 0 end this.t_switch = true + if client and this == players[players.current] and this.tool ~= tool then + common.net_send(nil, common.net_pack("BBB" + , 0x17, 0x00, tool)) + end this.tool = tool end @@ -246,14 +256,27 @@ function new_player(settings) this.angx = math.asin(yrec/ydist) end - function this.damage(amt, kcol, kmsg) - this.health = this.health - amt + function this.set_health_damage(amt, kcol, kmsg) + this.health = amt + if this.health <= 0 then this.intel_drop() - chat_add(chat_killfeed, nil, kmsg, kcol) + if server then + net_broadcast(nil, common.net_pack("BIz", 0x0F, kcol, kmsg)) + end + --chat_add(chat_killfeed, nil, kmsg, kcol) this.health = 0 this.alive = false end + + if server then + net_broadcast(nil, common.net_pack("BBB", 0x14, this.pid, this.health)) + end + end + + function this.damage(amt, kcol, kmsg) + return this.set_health_damage( + this.health - amt, kcol, kmsg) end function this.fall_damage(amt) @@ -269,6 +292,11 @@ function new_player(settings) function this.gun_damage(part, amt, enemy) --print("damage",this.name,part,amt) + + if not server then + return + end + local midmsg = " killed " if this.team == enemy.team then midmsg = " teamkilled " @@ -359,9 +387,14 @@ function new_player(settings) end if this.t_respawn then - if this.t_respawn <= sec_current then + if server and this.t_respawn <= sec_current then + --print("server respawn!") this.t_respawn = nil this.spawn() + net_broadcast(nil, common.net_pack("BBfffBB", + 0x10, this.pid, + this.x, this.y, this.z, + this.angy*128/math.pi, this.angx*256/math.pi)) else -- any last requests? end