public static void SerializeData(BinaryWriter br, CustomSyncMsg msg) { br.Write((short)msg.player_id); br.Write((char)msg.msg_type); if (msg.msg_type == (int)RequestType.ENTERAREA) { EnterAreaMessage enterArea = msg as EnterAreaMessage; // br.Write(enterArea.id); br.Write(enterArea.health);; br.Write(enterArea.position.x); br.Write(enterArea.position.y); br.Write(enterArea.position.z); br.Write(enterArea.direction.x); br.Write(enterArea.direction.y); br.Write(enterArea.direction.z); //br.Write(enterArea.rotation.x); //br.Write(enterArea.rotation.y); } else if (msg.msg_type == (int)RequestType.INPUT) { InputMessage input = msg as InputMessage; // br.Write(input.id); br.Write(input.moving.x); // br.Write(input.moving.y); br.Write(input.moving.z); } else if (msg.msg_type == (int)RequestType.LEAVEAREA) { LeaveAreaMessage leaveArea = msg as LeaveAreaMessage; //br.Write(leaveArea.id); } else if (msg.msg_type == (int)RequestType.ROTATE) { RotateMessage rotate = msg as RotateMessage; // br.Write(rotate.id); br.Write(rotate.delta.x); br.Write(rotate.delta.y); } else if (msg.msg_type == (int)RequestType.POSITION) { PositionMessage rotate = msg as PositionMessage; //br.Write(rotate.id); br.Write(rotate.delta.x); br.Write(rotate.delta.y); } else if (msg.msg_type == (int)RequestType.SPAWN) { SpawnMessage spawn = msg as SpawnMessage; //br.Write(spawn.id); br.Write(spawn.position.x); br.Write(spawn.position.y); br.Write(spawn.position.z); } }
void AreaCheck(Player TPlayer) { //Console.WriteLine("in gameID: " + gameID + "curplayer pos is: " + currentPlayer.get_position()); if (switchingArea) { if (TPlayer.get_area_id() == targetAreaID) { switchingArea = false; } } else { int newAreaID = areaManager.get_id_by_pos(TPlayer.get_position()); int currentAreaID = TPlayer.get_area_id(); if (newAreaID != currentAreaID) { // Console.WriteLine("area switch, newAreaID != currentAreaID: newAreaID " + newAreaID + " currentAreaID " + currentAreaID); if (newAreaID >= areaLength) { return; } switchingArea = true; var customSyncMsg = new LeaveAreaMessage(currentPlayer.get_id()); var syncFrame = new SyncFrame(0, currentAreaID); syncFrame.dump_actions(customSyncMsg); NetworkMsg networkMsg = new Frame(0, syncFrame); sendBuffer.Enqueue(networkMsg); targetAreaID = newAreaID; //Debug.Log ("area changed!"); var EnterAreaSyncMsg = new EnterAreaMessage(currentPlayer.get_id(), 100, currentPlayer.get_axis(), currentPlayer.get_direction(), currentPlayer.get_position()); syncFrame = new SyncFrame(0, newAreaID); syncFrame.dump_actions(EnterAreaSyncMsg); networkMsg = new Frame(0, syncFrame); sendBuffer.Enqueue(networkMsg); } else { } } }
public static void Buffer_SyncFrame_msg_list2(List <CustomSyncMsg> msg_list, List <DS_protocol.p_CustomSyncMsg> p_msg_list) { foreach (CustomSyncMsg msg in msg_list) { if (msg.msg_type == (int)RequestType.ENTERAREA) { EnterAreaMessage enterArea = msg as EnterAreaMessage; DS_protocol.p_EnterAreaMessage p_msg = new DS_protocol.p_EnterAreaMessage(); p_msg.id = enterArea.id; p_msg.health = enterArea.health;; p_msg.position_x = enterArea.position.x; p_msg.position_y = enterArea.position.y; p_msg.position_z = enterArea.position.z; p_msg.direction_x = enterArea.direction.x; p_msg.direction_y = enterArea.direction.y; p_msg.direction_z = enterArea.direction.z; p_msg.rotation_x = enterArea.rotation.x; p_msg.rotation_y = enterArea.rotation.y; //p_msg.area_id = enterArea.area_id; DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg(); p_basemsg.msg_type = enterArea.msg_type; p_basemsg.player_id = enterArea.player_id; p_basemsg.EnterArea = p_msg; p_msg_list.Add(p_basemsg); } if (msg.msg_type == (int)RequestType.INPUT) { InputMessage input = msg as InputMessage; DS_protocol.p_InputMessage p_msg = new DS_protocol.p_InputMessage(); p_msg.moving_x = input.moving.x; p_msg.moving_y = input.moving.y; p_msg.moving_z = input.moving.z; //p_msg.area_id = input.area_id; DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg(); p_basemsg.msg_type = input.msg_type; p_basemsg.player_id = input.player_id; p_basemsg.Input = p_msg; p_msg_list.Add(p_basemsg); } if (msg.msg_type == (int)RequestType.LEAVEAREA) { LeaveAreaMessage leaveArea = msg as LeaveAreaMessage; DS_protocol.p_LeaveAreaMessage p_msg = new DS_protocol.p_LeaveAreaMessage(); p_msg.id = leaveArea.id; //p_msg.area_id = leaveArea.area_id; DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg(); p_basemsg.msg_type = leaveArea.msg_type; p_basemsg.player_id = leaveArea.player_id; p_basemsg.LeaveArea = p_msg; p_msg_list.Add(p_basemsg); } if (msg.msg_type == (int)RequestType.ROTATE) { RotateMessage rotate = msg as RotateMessage; DS_protocol.p_RotateMessage p_msg = new DS_protocol.p_RotateMessage(); p_msg.delta_x = rotate.delta.x; p_msg.delta_y = rotate.delta.y; //p_msg.area_id = rotate.area_id; DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg(); p_basemsg.msg_type = rotate.msg_type; p_basemsg.player_id = rotate.player_id; p_basemsg.Rotate = p_msg; p_msg_list.Add(p_basemsg); } if (msg.msg_type == (int)RequestType.POSITION) { PositionMessage rotate = msg as PositionMessage; DS_protocol.p_PositionMessage p_msg = new DS_protocol.p_PositionMessage(); p_msg.delta_x = rotate.delta.x; p_msg.delta_y = rotate.delta.y; // p_msg.area_id = rotate.area_id; DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg(); p_basemsg.msg_type = rotate.msg_type; p_basemsg.player_id = rotate.player_id; p_basemsg.Position = p_msg; p_msg_list.Add(p_basemsg); } if (msg.msg_type == (int)RequestType.SPAWN) { SpawnMessage spawn = msg as SpawnMessage; DS_protocol.p_SpawnMessage p_msg = new DS_protocol.p_SpawnMessage(); p_msg.id = spawn.id; p_msg.position_x = spawn.position.x; p_msg.position_y = spawn.position.y; p_msg.position_z = spawn.position.z; //p_msg.area_id = spawn.area_id; DS_protocol.p_CustomSyncMsg p_basemsg = new DS_protocol.p_CustomSyncMsg(); p_basemsg.msg_type = spawn.msg_type; p_basemsg.player_id = spawn.player_id; p_basemsg.Spawn = p_msg; p_msg_list.Add(p_basemsg); } } }
public static List <p_AllMsg.p_CustomSyncMsg> Buffer_SyncFrame_msg_list(List <CustomSyncMsg> msg_list) { List <p_AllMsg.p_CustomSyncMsg> p_msg_list = new List <p_AllMsg.p_CustomSyncMsg>(); foreach (CustomSyncMsg msg in msg_list) { if (msg.msg_type == (int)RequestType.ENTERAREA) { EnterAreaMessage enterArea = msg as EnterAreaMessage; p_AllMsg.p_EnterAreaMessage p_msg = new p_AllMsg.p_EnterAreaMessage(); p_msg.id = enterArea.id; p_msg.health = enterArea.health;; p_msg.position_x = enterArea.position.x; p_msg.position_y = enterArea.position.y; p_msg.position_z = enterArea.position.z; p_msg.direction_x = enterArea.direction.x; p_msg.direction_y = enterArea.direction.y; p_msg.direction_z = enterArea.direction.z; p_msg.rotation_x = enterArea.rotation.x; p_msg.rotation_y = enterArea.rotation.y; p_msg.msg_type = enterArea.msg_type; p_msg.player_id = enterArea.player_id; p_msg.area_id = enterArea.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.INPUT) { InputMessage input = msg as InputMessage; p_AllMsg.p_InputMessage p_msg = new p_AllMsg.p_InputMessage(); p_msg.id = input.id; p_msg.moving_x = input.moving.x; p_msg.moving_y = input.moving.y; p_msg.moving_z = input.moving.z; p_msg.msg_type = input.msg_type; p_msg.player_id = input.player_id; p_msg.area_id = input.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.LEAVEAREA) { LeaveAreaMessage leaveArea = msg as LeaveAreaMessage; p_AllMsg.p_LeaveAreaMessage p_msg = new p_AllMsg.p_LeaveAreaMessage(); p_msg.id = leaveArea.id; p_msg.msg_type = leaveArea.msg_type; p_msg.player_id = leaveArea.player_id; p_msg.area_id = leaveArea.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.ROTATE) { RotateMessage rotate = msg as RotateMessage; p_AllMsg.p_RotateMessage p_msg = new p_AllMsg.p_RotateMessage(); p_msg.id = rotate.id; p_msg.delta_x = rotate.delta.x; p_msg.delta_y = rotate.delta.y; p_msg.msg_type = rotate.msg_type; p_msg.player_id = rotate.player_id; p_msg.area_id = rotate.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.SPAWN) { SpawnMessage spawn = msg as SpawnMessage; p_AllMsg.p_SpawnMessage p_msg = new p_AllMsg.p_SpawnMessage(); p_msg.id = spawn.id; p_msg.position_x = spawn.position.x; p_msg.position_y = spawn.position.y; p_msg.position_z = spawn.position.z; p_msg.msg_type = spawn.msg_type; p_msg.player_id = spawn.player_id; p_msg.area_id = spawn.area_id; p_msg_list.Add(p_msg); } if (msg.msg_type == (int)RequestType.SHOOT) { ShootMessage shoot = msg as ShootMessage; p_AllMsg.p_ShootMessage p_msg = new p_AllMsg.p_ShootMessage(); p_msg.direction_x = shoot.direction_x; p_msg.direction_y = shoot.direction_y; p_msg.direction_z = shoot.direction_z; p_msg.origin_x = shoot.origin_x; p_msg.origin_y = shoot.origin_y; p_msg.origin_z = shoot.origin_z; p_msg.player_id = shoot.player_id; p_msg.msg_type = shoot.msg_type; p_msg_list.Add(p_msg); } } return(p_msg_list); }
public static CustomSyncMsg DSerializeData(MemoryStream ms, BinaryReader br) { int player_id = br.ReadInt32(); int msg_type = br.ReadInt32(); if (msg_type == (int)RequestType.ENTERAREA) { int id = br.ReadInt32(); int health = br.ReadInt32(); float positionx = br.ReadSingle(); float positiony = br.ReadSingle(); float positionz = br.ReadSingle(); float directionx = br.ReadSingle(); float directiony = br.ReadSingle(); float directionz = br.ReadSingle(); float rotationx = br.ReadSingle(); float rotationy = br.ReadSingle(); var msg = new EnterAreaMessage(player_id, health, new Vector2(rotationx, rotationy), new Vector3(directionx, directiony, directionz), new Vector3(positionx, positiony, positionx)); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.INPUT) { int id = br.ReadInt32(); float x = br.ReadSingle(); float y = br.ReadSingle(); float z = br.ReadSingle(); var msg = new InputMessage(player_id, new Vector3(x, y, z)); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.LEAVEAREA) { int id = br.ReadInt32(); var msg = new LeaveAreaMessage(player_id); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.ROTATE) { int id = br.ReadInt32(); float x = br.ReadSingle(); float y = br.ReadSingle(); var msg = new RotateMessage(player_id, new Vector2(x, y)); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.POSITION) { int id = br.ReadInt32(); float x = br.ReadSingle(); float y = br.ReadSingle(); var msg = new PositionMessage(player_id, new Vector2(x, y)); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.SPAWN) { int id = br.ReadInt32(); float x = br.ReadSingle(); float y = br.ReadSingle(); float z = br.ReadSingle(); var msg = new SpawnMessage(player_id, new Vector3(x, y, z)); // msg.id = id; return(msg); } else { return(null); } }
public static List <CustomSyncMsg> extract_msg(List <DS_protocol.p_CustomSyncMsg> p_msg_list) { List <CustomSyncMsg> msg_list = new List <CustomSyncMsg>(); CustomSyncMsg msg; if (p_msg_list != null) { foreach (DS_protocol.p_CustomSyncMsg p_msg in p_msg_list) { if (p_msg.msg_type == (int)RequestType.INPUT) { DS_protocol.p_InputMessage i_msg = p_msg.Input; int player_id = p_msg.player_id; float moving_x = i_msg.moving_x; float moving_y = i_msg.moving_y; float moving_z = i_msg.moving_z; //Console.WriteLine("get input info: " + player_id +" " + moving_x+" " + moving_y + " " + moving_z); msg = new InputMessage(player_id, new Vector3(moving_x, moving_y, moving_z)); msg_list.Add(msg); } else if (p_msg.msg_type == (int)RequestType.ROTATE) { DS_protocol.p_RotateMessage r_msg = p_msg.Rotate; int player_id = p_msg.player_id; float rotation_x = r_msg.delta_x; float rotation_y = r_msg.delta_y; //Console.WriteLine("get rotate info: " + player_id + "rotation_x-- " + rotation_x + "rotation_y-- " + rotation_y); msg = new RotateMessage(player_id, new Vector2(rotation_x, rotation_y)); msg_list.Add(msg); } else if (p_msg.msg_type == (int)RequestType.SPAWN) { DS_protocol.p_SpawnMessage s_msg = p_msg.Spawn; int player_id = p_msg.player_id; float position_x = s_msg.position_x; float position_y = s_msg.position_y; float position_z = s_msg.position_z; //Console.WriteLine("get spawn info: " + player_id + "position_x-- " + position_x + "position_y-- " + position_y + "position_z--" + position_z); msg = new SpawnMessage(player_id, new Vector3(position_x, position_y, position_z)); msg_list.Add(msg); } else if (p_msg.msg_type == (int)RequestType.ENTERAREA) { DS_protocol.p_EnterAreaMessage e_msg = p_msg.EnterArea; int player_id = p_msg.player_id; int health = e_msg.health; float position_x = e_msg.position_x; float position_y = e_msg.position_y; float position_z = e_msg.position_z; float direction_x = e_msg.direction_x; float direction_y = e_msg.direction_y; float direction_z = e_msg.direction_z; float rotation_x = e_msg.rotation_x; float rotation_y = e_msg.rotation_y; //Console.WriteLine("get enterArea info: " + player_id + "position_x-- " + position_x + "position_y-- " + position_y + "position_z--" + position_z); msg = new EnterAreaMessage(player_id, health, new Vector2(rotation_x, rotation_y), new Vector3(direction_x, direction_y, direction_z), new Vector3(position_x, position_y, position_z)); msg_list.Add(msg); } else if (p_msg.msg_type == (int)RequestType.LEAVEAREA) { int player_id = p_msg.player_id; msg = new LeaveAreaMessage(player_id); msg_list.Add(msg); } } } return(msg_list); }
public static CustomSyncMsg DSerializeData(BinaryReader br, int areaid) { int player_id = br.ReadInt16(); int msg_type = br.ReadChar(); if (msg_type == (int)RequestType.ENTERAREA) { //int id = br.ReadInt32(); int health = br.ReadInt32(); float positionx = br.ReadSingle(); float positiony = br.ReadSingle(); float positionz = br.ReadSingle(); float directionx = br.ReadSingle(); float directiony = br.ReadSingle(); float directionz = br.ReadSingle(); // float rotationx = br.ReadSingle(); // float rotationy = br.ReadSingle(); var msg = new EnterAreaMessage(player_id, health, new Vector2(0, 0), new Vector3(directionx, directiony, directionz), new Vector3(positionx, positiony, positionz)); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.INPUT) { // int id = br.ReadInt32(); float x = br.ReadSingle(); // float y = br.ReadSingle(); float z = br.ReadSingle(); var msg = new InputMessage(player_id, new Vector3(x, 0, z)); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.LEAVEAREA) { //int id = br.ReadInt32(); var msg = new LeaveAreaMessage(player_id); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.ROTATE) { //int id = br.ReadInt32(); float x = br.ReadSingle(); float y = br.ReadSingle(); var msg = new RotateMessage(player_id, new Vector2(x, y)); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.POSITION) { float x = br.ReadSingle(); float y = br.ReadSingle(); var msg = new PositionMessage(player_id, new Vector2(x, y)); // msg.id = id; gameServer.SetPlayerPosition(player_id, areaid, new UnityEngine.Vector2(x, y)); return(msg); } else if (msg_type == (int)RequestType.SPAWN) { //int id = br.ReadInt32(); float x = br.ReadSingle(); float y = br.ReadSingle(); float z = br.ReadSingle(); var msg = new SpawnMessage(player_id, new Vector3(x, y, z)); // msg.id = id; return(msg); } else if (msg_type == (int)RequestType.SYNPOS) { int Count = br.ReadInt32(); for (int n = 0; n < Count; ++n) { int TPlayerid = br.ReadInt32(); float x = br.ReadSingle(); float y = br.ReadSingle(); gameServer.SetSYNPlayerPosition(player_id, TPlayerid, new UnityEngine.Vector2(x, y)); } // msg.id = id; return(null); } else { return(null); } }