/// <summary> /// corresponds to server send message 3 /// </summary> /// <param name="p"></param> /// <param name="d"></param> /// <param name="w"></param> public void receive_all_players_and_id(NetIncomingMessage p, Display d, World w) { double dtime = NetTime.Now - p.ReadTime(false); w.world_time = p.ReadSingle() + (float)dtime; Exilania.game_my_user_id = p.ReadByte(); if (!Exilania.game_server) { int num_players = p.ReadByte(); for (int x = 0; x < num_players; x++) { Player temp = new Player(p); temp.avatar.world_loc = new Vector2(p.ReadSingle(), p.ReadSingle()); w.players.Add(temp); /*w.minimap.map_pieces.Add(new MapMarker(new Point((int)temp.avatar.world_loc.X / 24, (int)temp.avatar.world_loc.Y / 24), MarkerType.OTHER_PLAYER, w.players.Count - 1)); * if (w.players.Count - 1 == Exilania.game_my_user_id) * { * w.minimap.map_pieces[w.minimap.map_pieces.Count - 1].type = MarkerType.PLAYER; * }*/ } } w.do_composition_lighting(); w.players[Exilania.game_my_user_id].avatar.input.hold_left_mouse_click = false; d.add_message("@05You (" + w.players[w.players.Count - 1].avatar.name + "@05) have joined the server."); d.add_message("@05There " + (Exilania.people_connected == 1 ? "is" : "are") + " now " + Exilania.people_connected + (Exilania.people_connected == 1 ? " person" : " people") + " in this game."); Exilania.gstate = 100; w.total_fps = new Timing("SPF"); }
public void receive_chat(NetIncomingMessage p, Exilania g, Display d, World w) { byte player_id = p.ReadByte(); string msg = p.ReadString(); if (player_id < w.players.Count) { if (msg[0] == '!' && Exilania.gstate == 100) { for (int i = 0; i < msg.Length; i++) { if (msg[i] == '!') { msg = msg.Substring(0, i) + msg.Substring(i + 1); break; } } d.fading_text.Add(new FadeText("@00" + msg, 3000, (int)w.players[player_id].avatar.world_loc.X, (int)w.players[player_id].avatar.world_loc.Y - 60, true, TargetType.Player, player_id, w)); } else { d.add_message("@05" + w.players[player_id].avatar.name + "@00: " + msg); } Exilania.text_stream.WriteLine("@05" + w.players[player_id].avatar.name + "@00: " + msg); } else { d.add_message("@05New Player@00: " + msg); Exilania.text_stream.WriteLine(Acc.sanitize_text_color("@05New Player@00: " + msg)); } }
public void server_messages(Exilania g, Display d, World w) { //Exilania.debug = udp_server.Statistics.ToString(); NetIncomingMessage inc; if (w != null && damages.Count > 0) { process_damage(w); } while ((inc = udp_server.ReadMessage()) != null) { switch (inc.MessageType) { case NetIncomingMessageType.Data: consume_message(inc, g, d, w); break; case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte(); string reason = inc.ReadString(); Exilania.text_stream.WriteLine("Server: Status changed: " + reason); if (status == NetConnectionStatus.Connected) { Player_Tag p; p.player_game_index_id = -1; if (Exilania.people_connected == 0) { p.host = true; } else { p.host = false; } if (Exilania.people_connected < 255 && Exilania.people_connected < Exilania.settings.max_users) { Exilania.people_connected++; inc.SenderConnection.Tag = p; NetOutgoingMessage m = udp_server.CreateMessage(); m.Write((byte)1); m.Write(Exilania.people_connected); m.Write(Exilania.settings.force_new_character); udp_server.SendMessage(m, inc.SenderConnection, NetDeliveryMethod.ReliableUnordered); d.add_message("Server: Received response from Client. Connected. " + reason); } else { d.add_message("Server: Too many users in-game already... cannot add any more."); inc.SenderConnection.Disconnect("Too many users in-game."); } } break; default: d.add_message("Server: Some sort of message received " + inc.MessageType); Exilania.text_stream.WriteLine("Server: Unhandled type: " + inc.MessageType + " " + inc.ReadString()); break; } udp_server.Recycle(inc); } }
public void client_messages(Exilania g, Display d, ref World w) { NetIncomingMessage inc; while ((inc = udp_client.ReadMessage()) != null) { switch (inc.MessageType) { case NetIncomingMessageType.Data: consume_message(inc, g, d, ref w, g); break; case NetIncomingMessageType.DiscoveryResponse: d.add_message("Client: Received response from Server. Connected."); udp_client.Connect(inc.SenderEndPoint); break; case NetIncomingMessageType.DebugMessage: case NetIncomingMessageType.ErrorMessage: case NetIncomingMessageType.WarningMessage: case NetIncomingMessageType.VerboseDebugMessage: Exilania.text_stream.WriteLine("Client: Unhandled type: " + inc.MessageType + " " + inc.ReadString()); break; case NetIncomingMessageType.StatusChanged: NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte(); string reason = inc.ReadString(); if (status == NetConnectionStatus.Connected) { d.add_message("Client: Received response from Server. Connected."); } else if (status == NetConnectionStatus.Disconnected) { d.add_message("Client: Connect refused.. " + reason); if (Exilania.game_my_user_id != -1) { Exilania.saved_players.players[Exilania.cur_using_local_id] = w.players[Exilania.game_my_user_id]; Exilania.saved_players.save_players(); if (Exilania.game_server) { w.write_world(); } } Exilania.gstate = 10; } Exilania.text_stream.WriteLine("Client: Status changed: " + reason); break; default: Exilania.text_stream.WriteLine("Client: Unhandled type: " + inc.MessageType + " " + inc.ReadString()); break; } udp_client.Recycle(inc); } }
public void receive_damage_request(NetIncomingMessage m, Display d, World w) { d.add_message("@05Attack message length: " + m.LengthBytes); int num_attack = m.ReadUInt16(); for (int i = 0; i < num_attack; i++) { DamageMove t = new DamageMove(m); Rectangle target_rect = new Rectangle(); if (t.target == TargetType.Player) { target_rect = new Rectangle((int)w.players[t.target_id].avatar.world_loc.X - w.players[t.target_id].avatar.bounding_box.Width / 2, (int)w.players[t.target_id].avatar.world_loc.Y - w.players[t.target_id].avatar.bounding_box.Height / 2, w.players[t.target_id].avatar.bounding_box.Width, w.players[t.target_id].avatar.bounding_box.Height); } else { target_rect = new Rectangle((int)w.npcs[t.target_id].world_loc.X - w.npcs[t.target_id].bounding_box.Width / 2, (int)w.npcs[t.target_id].world_loc.Y - w.npcs[t.target_id].bounding_box.Height / 2, w.npcs[t.target_id].bounding_box.Width, w.npcs[t.target_id].bounding_box.Height); } Circle c = new Circle(new Point((int)w.players[t.attacker_id].avatar.world_loc.X, (int)w.players[t.attacker_id].avatar.world_loc.Y), t.range); if (c.intersects_rectangle(target_rect)) { damages.Add(t); } } }
public void remove_client(NetIncomingMessage p, Display d, World w) { int player_id = p.ReadByte(); if (!Exilania.game_server && w != null && w.players.Count > player_id) { w.players[player_id].is_player_empty = true; d.add_message("@03" + w.players[player_id].avatar.name + " @03has quit."); } }
public void remove_client(NetIncomingMessage p, Display d, World w) { byte quitter_id = p.ReadByte(); if (quitter_id < w.players.Count && !w.players[quitter_id].is_player_empty) { w.players[quitter_id].is_player_empty = true; d.add_message("@03" + w.players[quitter_id].avatar.name + " @03has quit."); //w.players[quitter_id] = null; Exilania.people_connected--; NetOutgoingMessage i = udp_server.CreateMessage(); i.Write((byte)64); i.Write(quitter_id); udp_server.SendToAll(i, p.SenderConnection, NetDeliveryMethod.ReliableOrdered, 4); p.SenderConnection.Disconnect("You have been successfully logged off."); } //w.players[quitter_id] = null; }
public void receive_player(NetIncomingMessage p, Display d, World w) { if (!Exilania.game_server) { Player temp = new Player(p); byte player_id = p.ReadByte(); temp.avatar.world_loc = new Vector2(p.ReadSingle(), p.ReadSingle()); if (w.players.Count > player_id) { w.players[player_id] = temp; } else { w.players.Add(temp); } d.add_message("@05Player " + w.players[player_id].avatar.name + " has joined us."); d.temp_show_chat = true; } }
public void add_new_player(NetIncomingMessage p, Exilania g, Display d, World w) { //add the received character into the world and initialize them. Player new_player_char = new Player(p); d.add_message("@05Player " + new_player_char.avatar.name + " has joined us."); new_player_char.avatar.world_loc = new Vector2(w.world_spawn_loc.X, w.world_spawn_loc.Y);// w.spawn_actor(new_player_char.avatar.bounding_box); int player_id = -1; for (int x = 0; x < w.players.Count; x++) { if (w.players[x].is_player_empty) { player_id = x; x = w.players.Count; } } if (player_id != -1) { w.players[player_id] = new_player_char; } else { w.players.Add(new_player_char); player_id = w.players.Count - 1; } //send the received character out to everyone else NetOutgoingMessage i = udp_server.CreateMessage(); i.Write((byte)4); new_player_char.send_player(i); i.Write((byte)player_id); i.Write((Single)new_player_char.avatar.world_loc.X); i.Write((Single)new_player_char.avatar.world_loc.Y); udp_server.SendToAll(i, p.SenderConnection, NetDeliveryMethod.ReliableOrdered, 4); //if not the host, send the world to the player. if (w.players.Count > 1) { send_world_to_client(p, g, d, w); } //then initialize the player... these two run on the same reliable channel, so 1 can only happen after the other. initialize_player_world((byte)player_id, p, g, d, w); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { r = new System.IO.StreamReader("exilania.ini"); settings = new Settings(r); r.Close(); // TODO: Add your initialization logic here if (!settings.use_custom_dimensions) { graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height; graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width; screen_size = new Point(GraphicsDevice.DisplayMode.Width, GraphicsDevice.DisplayMode.Height); } else { try { graphics.PreferredBackBufferHeight = settings.custom_height; graphics.PreferredBackBufferWidth = settings.custom_width; screen_size = new Point(settings.custom_width, settings.custom_height); } catch { graphics.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height; graphics.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width; screen_size = new Point(GraphicsDevice.DisplayMode.Width, GraphicsDevice.DisplayMode.Height); } } graphics.ToggleFullScreen(); GraphicsDevice.SamplerStates[1] = SamplerState.LinearClamp; graphics.ApplyChanges(); screen_size = new Point(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height); try { System.IO.Directory.CreateDirectory(@"logs"); } catch { } text_stream = new System.IO.StreamWriter(@"logs/debug" + DateTime.Now.Ticks.ToString() + ".txt"); text_stream.AutoFlush = true; text_stream.WriteLine("Open the document"); block_types = new BlockManager(); BlockData.enum_blocks(); World.liquid_blocks = new int[] { 0, (int)block_types.get_block_by_name("Water") }; //BlockData.export_block_data(block_types.blocks); item_manager = new ItemManager(); furniture_manager = new FurnitureManager(); plant_manager = new PlantManager(); material_manager = new MaterialManager(); crafting_manager = new CraftManager(); world_manager = new WorldManager(); world_definition_manager = new WorldCreator(); particle_manager = new ParticleManager(); if (settings.use_seed) { rand = new Lidgren.Network.NetRandom(settings.seed_id); } else { rand = new Lidgren.Network.NetRandom((int)System.DateTime.Now.Ticks); } menu = new MainMenu(); body_templates = new List <BodyTemplate>(); r = new System.IO.StreamReader("bodies.txt"); while (!r.EndOfStream) { body_templates.Add(new BodyTemplate(r, body_templates.Count)); } r.Close(); saved_players = new SavedPlayers(); draw_debug = settings.debugging; seed_id = (int)DateTime.Now.Ticks; if (settings.use_seed) { seed_id = settings.seed_id; } display.add_message(Display.color_code + "00Welcome to Exilania. Seed ID: " + seed_id.ToString()); rand = new Lidgren.Network.NetRandom(seed_id); sounds = new Sounds(); //CubicSpline cs = new CubicSpline(new double[]{1,10,30,60,100},new double[]{1,2,5,9,13}); CubicSpline cs = new CubicSpline(new double[] { 0, 4, 10, 30, 100 }, new double[] { .05, .4, .7, 1, 1 }); int total_cost = 0; for (float i = 0; i < 100.1f; i += .5f) { total_cost += (int)cs.get_val_at(i); //Exilania.display.add_message("@05Cubic Spline[" + (i).ToString().PadLeft(3,'0') + "]:" + cs.get_val_at(i)); //text_stream.WriteLine(Acc.sanitize_text_color(display.messages[display.messages.Count - 1])); } //Exilania.display.add_message("@06To get to level 100, you would need " + total_cost + " points."); base.Initialize(); }