/// <summary> /// Sends position, orientation, Throttle and UpdateTime of a SimObject. /// </summary> /// <param name="obj">Object to send</param> public void NotifyOnObjUpdate(SimObject obj) { Log.AddLog(LogType.FL_MSG2, "tx FLPACKET_COMMON_UPDATEOBJECT"); byte[] omsg = { 0x01, 0x01 }; FLMsgType.AddUInt8(ref omsg, 0xFF); // dunno FLMsgType.AddUInt32(ref omsg, obj.Objid); FLMsgType.AddFloat(ref omsg, (float)obj.Position.x); FLMsgType.AddFloat(ref omsg, (float)obj.Position.y); FLMsgType.AddFloat(ref omsg, (float)obj.Position.z); Quaternion q = Quaternion.MatrixToQuaternion(obj.Orientation); FLMsgType.AddInt8(ref omsg, (int)(q.I * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.J * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.K * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.W * 127)); FLMsgType.AddInt8(ref omsg, (int)(obj.Throttle * 127)); FLMsgType.AddFloat(ref omsg, (float)obj.UpdateTime); foreach (Player.Player player in Players.Values) { if (player.MonitoredObjs.ContainsKey(obj.Objid)) { player.SendMsgToClient(omsg); } } }
private byte[] BuildCreateCounterMeasure(CounterMeasure cm) { Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_CREATECOUNTER objid={0}", cm.Objid); byte[] omsg = { 0x2D, 0x02 }; FLMsgType.AddUInt32(ref omsg, cm.munition_arch.ArchetypeID); FLMsgType.AddUInt32(ref omsg, cm.Objid); FLMsgType.AddUInt32(ref omsg, 0); FLMsgType.AddUInt32(ref omsg, cm.owner_objid); FLMsgType.AddUInt16(ref omsg, cm.hpid); Quaternion q = Quaternion.MatrixToQuaternion(cm.Orientation); FLMsgType.AddFloat(ref omsg, (float)q.I); FLMsgType.AddFloat(ref omsg, (float)q.J); FLMsgType.AddFloat(ref omsg, (float)q.K); FLMsgType.AddFloat(ref omsg, (float)q.W); FLMsgType.AddFloat(ref omsg, (float)cm.Position.x); FLMsgType.AddFloat(ref omsg, (float)cm.Position.y); FLMsgType.AddFloat(ref omsg, (float)cm.Position.z); FLMsgType.AddFloat(ref omsg, (float)cm.velocity.x); FLMsgType.AddFloat(ref omsg, (float)cm.velocity.y); FLMsgType.AddFloat(ref omsg, (float)cm.velocity.z); FLMsgType.AddFloat(ref omsg, (float)cm.angular_velocity.x); FLMsgType.AddFloat(ref omsg, (float)cm.angular_velocity.y); FLMsgType.AddFloat(ref omsg, (float)cm.angular_velocity.z); return(omsg); }
public void NotifyOnSetHitPoints(uint objid, List <DamageListItem> dmg_items) { Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_DAMAGEOBJ objid={0}", objid); byte[] omsg = { 0x05, 0x02 }; FLMsgType.AddUInt32(ref omsg, objid); FLMsgType.AddUInt8(ref omsg, 0); // padding or dunno FLMsgType.AddUInt32(ref omsg, 0); // sender playerid FLMsgType.AddUInt32(ref omsg, 0); // sender objid FLMsgType.AddUInt16(ref omsg, (uint)dmg_items.Count); foreach (DamageListItem dmg_item in dmg_items) { FLMsgType.AddUInt16(ref omsg, dmg_item.hpid); FLMsgType.AddUInt8(ref omsg, dmg_item.destroyed ? 2u : 0u); FLMsgType.AddFloat(ref omsg, dmg_item.hit_pts); } foreach (Player.Player player in Players.Values) { if (player.MonitoredObjs.ContainsKey(objid)) { player.SendMsgToClient(omsg); } else if (player.Ship.Objid == objid) { player.SendMsgToClient(omsg); } } }
public void NotifyOnSetHitPoints(uint objid, uint hpid, float hitPts, bool destroyed) { Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_DAMAGEOBJ objid={0}", objid); byte[] omsg = { 0x05, 0x02 }; FLMsgType.AddUInt32(ref omsg, objid); FLMsgType.AddUInt8(ref omsg, 0); // padding or dunno FLMsgType.AddUInt32(ref omsg, 0); // sender playerid FLMsgType.AddUInt32(ref omsg, 0); // sender objid FLMsgType.AddUInt16(ref omsg, 1); // count FLMsgType.AddUInt16(ref omsg, hpid); FLMsgType.AddUInt8(ref omsg, destroyed ? 2u : 0u); // fixme: come back!! was 2u FLMsgType.AddFloat(ref omsg, hitPts); foreach (Player.Player player in Players.Values) { if (player.MonitoredObjs.ContainsKey(objid)) { player.SendMsgToClient(omsg); } else if (player.Ship.Objid == objid) { player.SendMsgToClient(omsg); } } }
private byte[] BuildCreateMissile(Missile missile) { Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_CREATEGUIDED objid={0}", missile.Objid); byte[] omsg = { 0x37, 0x02 }; FLMsgType.AddUInt16(ref omsg, missile.munition_arch.SmallID); FLMsgType.AddUInt32(ref omsg, missile.owner_objid); FLMsgType.AddUInt16(ref omsg, missile.hpid); FLMsgType.AddUInt32(ref omsg, missile.target_objid); // missile.target_objid FLMsgType.AddUInt16(ref omsg, missile.target_subobjid); // missile.target_subobjid FLMsgType.AddUInt32(ref omsg, missile.Objid); FLMsgType.AddFloat(ref omsg, (float)missile.Position.x); FLMsgType.AddFloat(ref omsg, (float)missile.Position.y); FLMsgType.AddFloat(ref omsg, (float)missile.Position.z); Quaternion q = Quaternion.MatrixToQuaternion(missile.Orientation); FLMsgType.AddInt8(ref omsg, (int)(q.I * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.J * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.K * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.W * 127)); return(omsg); }
/* public void NotifyOnServerLand(Ship ship, uint baseid, uint solarid) * { * log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_LAND objid={0} targetid={1} baseid={2}", ship.objid, solarid, baseid)); * * byte[] omsg = { 0x0B, 0x02 }; * FLMsgType.AddUInt32(ref omsg, ship.objid); * FLMsgType.AddUInt32(ref omsg, solarid); * FLMsgType.AddUInt32(ref omsg, baseid); * * foreach (Player player in players.Values) * { * if (player.monitored_objs.ContainsKey(ship.objid)) * { * player.SendMsgToClient(omsg); * } * } * } */ public void NotifyOnShipFiring(Ship.Ship ship, Vector targetPosition, List <uint> hpids) { byte[] omsg = { 0x02, 0x01 }; FLMsgType.AddUInt32(ref omsg, ship.Objid); FLMsgType.AddUInt8(ref omsg, 0); FLMsgType.AddFloat(ref omsg, (float)targetPosition.x); FLMsgType.AddFloat(ref omsg, (float)targetPosition.y); FLMsgType.AddFloat(ref omsg, (float)targetPosition.z); FLMsgType.AddUInt8(ref omsg, (uint)hpids.Count); foreach (var hpid in hpids) { FLMsgType.AddUInt16(ref omsg, hpid); } foreach (Player.Player player in Players.Values) { if (player.MonitoredObjs.ContainsKey(ship.Objid)) { player.SendMsgToClient(omsg); } } }
// FLPACKET_SERVER_CREATESHIP public byte[] BuildCreateShip(Ship.Ship ship) { Log.AddLog(LogType.FL_MSG, "tx FLPACKET_SERVER_CREATESHIP objid={0}", ship.Objid); byte[] omsg = { 0x04, 0x02 }; FLMsgType.AddUInt32(ref omsg, ship.Objid); FLMsgType.AddUInt16(ref omsg, ship.Arch.SmallID); FLMsgType.AddUInt32(ref omsg, 0); FLMsgType.AddUInt32(ref omsg, ship.player != null ? ship.player.FLPlayerID : 0); FLMsgType.AddUInt32(ref omsg, ship.com_body); FLMsgType.AddUInt32(ref omsg, ship.com_head); FLMsgType.AddUInt8(ref omsg, (uint)ship.Accessories.Count); foreach (uint accessory in ship.Accessories) { FLMsgType.AddUInt32(ref omsg, accessory); } FLMsgType.AddUInt32(ref omsg, ship.voiceid); FLMsgType.AddFloat(ref omsg, (float)ship.Position.x); FLMsgType.AddFloat(ref omsg, (float)ship.Position.y); FLMsgType.AddFloat(ref omsg, (float)ship.Position.z); Quaternion q = Quaternion.MatrixToQuaternion(ship.Orientation); FLMsgType.AddInt8(ref omsg, (int)(q.I * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.J * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.K * 127)); FLMsgType.AddInt8(ref omsg, (int)(q.W * 127)); FLMsgType.AddUInt8(ref omsg, (uint)(ship.Health * 255)); FLMsgType.AddUInt16(ref omsg, (uint)(ship.Items.Count)); foreach (ShipItem item in ship.Items.Values) { byte flag = 0; if (item.mounted) { flag |= 0x01; } if (item.mission) { flag |= 0x02; } if (item.count == 1) { flag |= 0x80; } else { flag |= 0x04; } if (item.health == 1.0f) { flag |= 0x40; } if (item.hpname.Length > 0) { flag |= 0x10; } else { flag |= 0x20; } FLMsgType.AddUInt8(ref omsg, flag); if (item.count != 1) { FLMsgType.AddUInt32(ref omsg, item.count); } if (item.health != 1.0f) { FLMsgType.AddUInt8(ref omsg, (uint)(item.health * 255)); } FLMsgType.AddUInt16(ref omsg, item.arch.SmallID); FLMsgType.AddUInt8(ref omsg, item.hpid); if (item.hpname.Length > 0) { FLMsgType.AddAsciiStringLen8(ref omsg, item.hpname + "\0"); } } FLMsgType.AddUInt8(ref omsg, (uint)(ship.cols.Count)); foreach (CollisionGroup col in ship.cols) { FLMsgType.AddUInt8(ref omsg, col.id); FLMsgType.AddUInt8(ref omsg, (uint)(col.health * col.max_hit_pts * 255)); } FLMsgType.AddUInt8(ref omsg, (ship.player != null) ? 4u : 0u); // flag FLMsgType.AddFloat(ref omsg, 0); // x FLMsgType.AddFloat(ref omsg, 0); // y FLMsgType.AddFloat(ref omsg, 0); // z FLMsgType.AddInt8(ref omsg, 0); FLMsgType.AddUInt16(ref omsg, 0); // dunno? FLMsgType.AddUInt8(ref omsg, ship.Rank); if (ship.player != null) { FLMsgType.AddUInt8(ref omsg, ship.player.FLPlayerID); FLMsgType.AddUInt16(ref omsg, 0); FLMsgType.AddUnicodeStringLen8(ref omsg, ship.player.Name); } else { var patrol_name = new FLFormatString(0x3f20); patrol_name.AddString(0x3016b); patrol_name.AddString(0x4074); patrol_name.AddString(0x30401); patrol_name.AddNumber(0x09); FLMsgType.AddArray(ref omsg, patrol_name.GetBytes()); var ship_name = new FLFormatString(0x3f21); ship_name.AddString(0x301a4); ship_name.AddString(0x37bac); ship_name.AddString(0x37c2b); FLMsgType.AddArray(ref omsg, ship_name.GetBytes()); } // The faction associated with the ship. For player ships this can be // -1 but for NPCs it needs to be set to a faction ID or the NPC will // not have a name shown in space or in the radar/scanner FLMsgType.AddUInt32(ref omsg, ship.faction.FactionID); // The reputation with reference to the faction..but it doesn't seem to // do much FLMsgType.AddInt8(ref omsg, -127); return(omsg); }