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 send_world_to_client(NetIncomingMessage p, Exilania g, Display d, World w) { /*System.Security.Cryptography.HashAlgorithm ha = System.Security.Cryptography.HashAlgorithm.Create(); * System.IO.FileStream fs = new System.IO.FileStream(@"worlds/" + w.name + ".wld",System.IO.FileMode.Open,System.IO.FileAccess.Read); * byte[] hash = ha.ComputeHash(fs); * fs.Close(); * Exilania.text_stream.WriteLine("Hash code before resaving: "+BitConverter.ToString(hash));*/ w.write_world(); /*fs = new System.IO.FileStream(@"worlds/" + w.name + ".wld", System.IO.FileMode.Open, System.IO.FileAccess.Read); * hash = ha.ComputeHash(fs); * fs.Close(); * Exilania.text_stream.WriteLine("Hash code after resaving: " + BitConverter.ToString(hash));*/ string file_name = "world" + w.world_number.ToString(); byte[] data_write = System.IO.File.ReadAllBytes(@"worlds/" + file_name + ".wld"); System.IO.FileStream fs = new System.IO.FileStream(@"worlds/network_game.wlz", System.IO.FileMode.Create, System.IO.FileAccess.Write); using (fs) { System.IO.Compression.GZipStream gzip = new System.IO.Compression.GZipStream(fs, System.IO.Compression.CompressionMode.Compress); gzip.Write(data_write, 0, (int)data_write.Length); } data_write = System.IO.File.ReadAllBytes(@"worlds/network_game.wlz"); System.IO.File.Delete(@"worlds/network_game.wlz"); NetOutgoingMessage i = udp_server.CreateMessage(); i.Write((byte)10); i.Write(file_name); i.Write(data_write.Length); i.Write(data_write); udp_server.SendMessage(i, p.SenderConnection, NetDeliveryMethod.ReliableOrdered, 6); }
public void receive_world(NetIncomingMessage p, Display d, ref World w, Exilania e) { string world_name = p.ReadString(); //world_name = "Received_World"; int num_bytes = p.ReadInt32(); Exilania.text_stream.WriteLine("Received a world entitled " + world_name + " filesize: " + num_bytes + " bytes."); byte[] bt_arr = new byte[num_bytes]; bt_arr = p.ReadBytes(num_bytes); System.IO.File.WriteAllBytes(@"worlds/network_client_game.wlz", bt_arr); using (System.IO.FileStream fs = new System.IO.FileStream(@"worlds/network_client_game.wld", System.IO.FileMode.Create, System.IO.FileAccess.Write)) using (System.IO.FileStream fd = new System.IO.FileStream(@"worlds/network_client_game.wlz", System.IO.FileMode.Open, System.IO.FileAccess.Read)) using (System.IO.Stream csStream = new System.IO.Compression.GZipStream(fd, System.IO.Compression.CompressionMode.Decompress)) { byte[] buffer = new byte[1024]; int nRead; while ((nRead = csStream.Read(buffer, 0, buffer.Length)) > 0) { fs.Write(buffer, 0, nRead); } } /*System.Security.Cryptography.HashAlgorithm ha = System.Security.Cryptography.HashAlgorithm.Create(); * System.IO.FileStream fs = new System.IO.FileStream(@"worlds/" + world_name + ".wld", System.IO.FileMode.Open, System.IO.FileAccess.Read); * byte[] hash = ha.ComputeHash(fs); * fs.Close(); * Exilania.text_stream.WriteLine("Hash code of received world: " + BitConverter.ToString(hash));*/ w = new World("network_client_game", e.GraphicsDevice); System.IO.File.Delete(@"worlds/network_client_game.wld"); System.IO.File.Delete(@"worlds/network_client_game.wlz"); }
public void connect(string host, int port, Exilania g) { udp_client.Start(); NetOutgoingMessage hail = udp_client.CreateMessage(); hail.Write("This is the hail message from "); udp_client.Connect(host, port, hail); }
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 update(Input input, Exilania e) { int prev_option = cur_option; if (input.mouse_cur_spot.X < Exilania.screen_size.X / 2 - 200 || input.mouse_cur_spot.X > Exilania.screen_size.X / 2 + 300) { cur_option = -2; return; } if (input.mouse_now.Y < Exilania.screen_size.Y * (.30f)) { if (input.mouse_now.Y > Exilania.screen_size.Y * (.25f)) { cur_option = -1; } else { cur_option = -2; } } else if (input.mouse_now.Y > Exilania.screen_size.Y * (.30f + (available_worlds.Count * .05))) { cur_option = -2; } else { float loc = (float)input.mouse_now.Y / (float)Exilania.screen_size.Y; loc -= .285f; cur_option = (int)(loc * 100f) / 5; } if (cur_option != prev_option) { Exilania.sounds.hit_block.Play(Exilania.sounds.master_volume, 0f, 0f); } if (input.left_clicked && input.mouse_now.X > -1 && input.mouse_now.Y > -1 && input.mouse_now.X <= Exilania.screen_size.X && input.mouse_now.Y <= Exilania.screen_size.Y && e.IsActive) { Exilania.sounds.finish_hit_block.Play(Exilania.sounds.master_volume, 0f, 0f); input.left_clicked = false; switch (cur_option) { case -2: //no option currently selected. break; case -1: //create new world Exilania.gstate = 91; Exilania.world_definition_manager.chosen_world_name = ""; Exilania.disable_chat = true; input.key_input = ""; break; default: e.start_world("world" + available_worlds[cur_option].world_number, e.GraphicsDevice); Exilania.gstate = 99; break; } } }
public void update_choose_name(Input input, Exilania e) { if (input.key_input.Length > 30) { input.key_input = input.key_input.Substring(0, 30); } chosen_world_name = input.key_input.Trim(); if (input.mouse_cur_spot.X < Exilania.screen_size.X / 2 - 200 || input.mouse_cur_spot.X > Exilania.screen_size.X / 2 + 100) { cur_hover = -1; return; } if (input.mouse_now.Y < Exilania.screen_size.Y * (.30f)) { cur_hover = -1; } else if (input.mouse_now.Y > Exilania.screen_size.Y - 100) { cur_hover = -2; } else { float loc = (float)input.mouse_now.Y / (float)Exilania.screen_size.Y; loc -= .285f; cur_hover = (int)(loc * 100f) / 5; } if (input.left_clicked && input.mouse_now.X > -1 && input.mouse_now.Y > -1 && input.mouse_now.X <= Exilania.screen_size.X && input.mouse_now.Y <= Exilania.screen_size.Y && e.IsActive) { input.left_clicked = false; switch (cur_hover) { case -2: //you have chosen to create the world... continue? if (Acc.sanitize_text_color(input.key_input.Trim()).Length >= 5 && cur_option > -1) { chosen_world_name = input.key_input.Trim(); input.key_input = ""; world_template = cur_option; making = new World(chosen_world_name, Exilania.seed_id, (int)(System.DateTime.Now.Ticks / 1000)); cur_info_text = "Initializing."; Exilania.gstate = 92; creation_state = -1; creation_fine_control = 0; Exilania.disable_chat = false; } break; default: //learn more about a world type. if (cur_hover > -1) { cur_option = cur_hover; } break; } } }
public void relay_chat(NetIncomingMessage p, Exilania g, Display d) { NetOutgoingMessage i = udp_server.CreateMessage(); i.Write((byte)2); i.Write(p.ReadByte()); string msg = p.ReadString(); i.Write(msg); udp_server.SendToAll(i, p.SenderConnection, NetDeliveryMethod.ReliableOrdered, 5); }
public void update_menu(Input input, Exilania e) { int prev_option = cur_option; if (input.mouse_cur_spot.X < Exilania.screen_size.X / 2 - 200 || input.mouse_cur_spot.X > Exilania.screen_size.X / 2 + 100) { cur_option = -1; return; } if (input.mouse_now.Y < Exilania.screen_size.Y * (.30f)) { cur_option = -1; } else if (input.mouse_now.Y > Exilania.screen_size.Y * (.30f + (options.Length * .05))) { cur_option = -1; } else { float loc = (float)input.mouse_now.Y / (float)Exilania.screen_size.Y; loc -= .285f; cur_option = (int)(loc * 100f) / 5; } if (cur_option != prev_option) { Exilania.sounds.hit_block.Play(Exilania.sounds.master_volume, 0f, 0f); } if (input.left_clicked && input.mouse_now.X > -1 && input.mouse_now.Y > -1 && input.mouse_now.X <= Exilania.screen_size.X && input.mouse_now.Y <= Exilania.screen_size.Y && e.IsActive) { Exilania.sounds.finish_hit_block.Play(Exilania.sounds.master_volume, 0f, 0f); input.left_clicked = false; switch (cur_option) { case 0: //singleplayer e.initialize_game(0); break; case 1: //multiplayer host e.initialize_game(1); break; case 2: //multiplayer join e.initialize_game(2); break; case 5: //quit game e.Exit(); break; } } }
/// <summary> /// this will be called upon first creation of a new player... it will send all data for all players and the players game_id /// </summary> /// <param name="p"></param> /// <param name="g"></param> /// <param name="d"></param> /// <param name="w"></param> public void initialize_player_world(byte player_id, NetIncomingMessage p, Exilania g, Display d, World w) { NetOutgoingMessage i = udp_server.CreateMessage(); i.Write((byte)3); i.WriteTime(false); i.Write(w.world_time); i.Write((byte)player_id); i.Write((byte)w.players.Count); for (int x = 0; x < w.players.Count; x++) { w.players[x].send_player(i); i.Write((Single)w.players[x].avatar.world_loc.X); i.Write((Single)w.players[x].avatar.world_loc.Y); } udp_server.SendMessage(i, p.SenderConnection, NetDeliveryMethod.ReliableOrdered, 6); }
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); }
public void update(Input input, Exilania e) { int prev_choice = cur_choice; if (input.mouse_now.Y < 230) { cur_choice = -1; } else if (input.mouse_now.Y >= 230 + (players.Count * 30)) { cur_choice = players.Count - 1; } else { int loc = input.mouse_now.Y; loc -= 230; cur_choice = (int)(loc / 30); } if (prev_choice != cur_choice) { Exilania.sounds.hit_block.Play(Exilania.sounds.master_volume, 0f, 0f); } if (input.left_clicked && input.mouse_now.X > -1 && input.mouse_now.Y > -1 && input.mouse_now.X <= Exilania.screen_size.X && input.mouse_now.Y <= Exilania.screen_size.Y && e.IsActive) { Exilania.sounds.finish_hit_block.Play(Exilania.sounds.master_volume, 0f, 0f); input.left_clicked = false; switch (cur_choice) { case -1: //create new character Exilania.gstate = 70; char_disp.name = ""; input.key_input = ""; Exilania.disable_chat = true; break; default: Exilania.cur_using_local_id = cur_choice; Exilania.gstate = 80; break; } } }
public void update_create_character(Input input, Exilania e) { char_disp.input.mouse_loc = new Point(input.mouse_now.X, input.mouse_now.Y); char_disp.update_static_body(6f); char_disp.light_actor(null); if (input.mouse_now.Y < 220) { cur_choice = 0; } else if (input.mouse_now.Y >= 220 + (choice_defs.Length * 30)) { if (input.mouse_now.Y < 320 + (choice_defs.Length * 30)) { cur_choice = choice_defs.Length - 1; } } else { int loc = input.mouse_now.Y; loc -= 220; cur_choice = (int)(loc / 30); } if (input.key_input.Length > 25) { input.key_input = input.key_input.Substring(0, 25); } char_disp.name = input.key_input; if (input.mouse_now.LeftButton == ButtonState.Pressed && input.mouse_now.X > -1 && input.mouse_now.Y > -1 && input.mouse_now.X <= Exilania.screen_size.X && input.mouse_now.Y <= Exilania.screen_size.Y && e.IsActive) { if (input.mouse_now.Y <= 220 + (choice_defs.Length * 30)) { clicked_choice = cur_choice; temp_col = set_colors[cur_choice]; } else if (input.mouse_now.Y > Exilania.screen_size.Y - 100 && char_disp.name.Length > 3) { //create the character. char_disp.body.Sort((y, x) => y.original_order.CompareTo(x.original_order)); char_disp.reset_colors(); char_disp.body.Sort((x, y) => y.draw_order.CompareTo(x.draw_order)); players.Add(new Player(char_disp, 1, 100, 0, 12)); save_players(); Exilania.gstate = 60; Exilania.disable_chat = false; } else { //Exilania.screen_size.X / 2, 320 + (choice_defs.Length * 30) bool color_changed = false; if (input.mouse_now.X >= Exilania.screen_size.X / 2 && input.mouse_now.X < Exilania.screen_size.X / 2 + 15 && input.mouse_now.Y >= 325 + (choice_defs.Length * 30) && input.mouse_now.Y < 350 + (choice_defs.Length * 30)) { if (temp_col.R > 0 && temp_col.R + temp_col.B + temp_col.G > 128) { color_changed = true; temp_col.R--; } } else if (input.mouse_now.X >= Exilania.screen_size.X / 2 + 15 && input.mouse_now.X < Exilania.screen_size.X / 2 + 35 && input.mouse_now.Y >= 325 + (choice_defs.Length * 30) && input.mouse_now.Y < 350 + (choice_defs.Length * 30)) { if (temp_col.R < 255) { color_changed = true; temp_col.R++; } } if (input.mouse_now.X >= Exilania.screen_size.X / 2 && input.mouse_now.X < Exilania.screen_size.X / 2 + 15 && input.mouse_now.Y >= 355 + (choice_defs.Length * 30) && input.mouse_now.Y < 380 + (choice_defs.Length * 30)) { if (temp_col.G > 0 && temp_col.R + temp_col.B + temp_col.G > 128) { color_changed = true; temp_col.G--; } } else if (input.mouse_now.X >= Exilania.screen_size.X / 2 + 15 && input.mouse_now.X < Exilania.screen_size.X / 2 + 35 && input.mouse_now.Y >= 355 + (choice_defs.Length * 30) && input.mouse_now.Y < 380 + (choice_defs.Length * 30)) { if (temp_col.G < 255) { color_changed = true; temp_col.G++; } } if (input.mouse_now.X >= Exilania.screen_size.X / 2 && input.mouse_now.X < Exilania.screen_size.X / 2 + 15 && input.mouse_now.Y >= 385 + (choice_defs.Length * 30) && input.mouse_now.Y < 410 + (choice_defs.Length * 30)) { if (temp_col.B > 0 && temp_col.R + temp_col.B + temp_col.G > 128) { color_changed = true; temp_col.B--; } } else if (input.mouse_now.X >= Exilania.screen_size.X / 2 + 15 && input.mouse_now.X < Exilania.screen_size.X / 2 + 35 && input.mouse_now.Y >= 385 + (choice_defs.Length * 30) && input.mouse_now.Y < 410 + (choice_defs.Length * 30)) { if (temp_col.B < 255) { color_changed = true; temp_col.B++; } } if (color_changed && temp_col.R + temp_col.B + temp_col.G >= 128) { set_colors[clicked_choice] = temp_col; apply_colors_to_character(char_disp); } } } }
public void get_input(float time, Input i, Display d, World w, Exilania e) { avatar.input.update_input(time, i, d, w, e, true); avatar.items.input(avatar, d, w.top_left); }
public void consume_message(NetIncomingMessage inc, Exilania g, Display d, ref World w, Exilania e) { byte type = inc.ReadByte(); switch (type) { case 1: //received confirmation that we have been logged in.. requesting player greet_server(inc, d, w); break; case 2: //receiving a chat receive_chat(inc, g, d, w); break; case 3: //receiving player list initialization receive_all_players_and_id(inc, d, w); break; case 4: //receiving new player receive_player(inc, d, w); break; case 5: // receiving individual position coordinates --- uses unreliable sequenced 1) receive_position_coordinates(inc, w); break; case 6: //receiving mouse and position of other players. receive_mouse_and_position_coordinates(inc, w); break; case 7: //receive input information receive_key_commands(inc, d, w); break; case 8: //receive block remove receive_remove_block(inc, d, w); break; case 9: //receive block place receive_place_block(inc, d, w); break; case 10: //receive world receive_world(inc, d, ref w, e); break; case 11: //receive run trugger receive_run_trigger(inc, d, w); break; case 12: //receive shoot bullet receive_shoot_bullet(inc, d, w); break; case 13: //receive place furniture receive_place_furniture(inc, d, w); break; case 14: //receive remove furniture receive_remove_furniture(inc, d, w); break; case 15: //receive furniture connection receive_furniture_connection(inc, d, w); break; case 16: //receive furniture disconnect receive_furniture_disconnect(inc, d, w); break; case 17: //receive attack plant receive_plant_attack(inc, d, w); break; case 18: //receive place plant break; case 19: //receive character switch item in hands receive_changed_item_in_hands(inc, d, w); break; case 20: //receive swing arms receive_swing_arms(inc, d, w); break; case 21: //receive time of day receive_world_time(inc, d, w); break; case 22: //receive death notice of some creature receive_death_notice(inc, w); break; case 23: //receive damage of some creature receive_damage_notice(inc, w); break; case 24: //receive changed chest receive_changed_chest(inc, w); break; case 25: //receive place plant receive_place_plant(inc, w); break; case 26: //receive grow plant receive_grow_plants(inc, w); break; case 64: //client has quit.. remove them! remove_client(inc, d, w); break; } }
public void connect(Exilania g) { udp_server.Start(); damages = new List <DamageMove>(); }
public void consume_message(NetIncomingMessage p, Exilania g, Display d, World w) { byte type = p.ReadByte(); switch (type) { case 1: //identify yourself response break; case 2: //message being broadcast relay_chat(p, g, d); break; case 3: //received new player_character add_new_player(p, g, d, w); break; case 5: //sending mouse coordinates. and position coordinates! relay_mouse_and_position_coordinates(p, d, w); break; case 7: //received input change from someone. relay_key_commands(p, d, w); break; case 8: //received block removal receive_block_remove(p, d, w); break; case 9: //received place block receive_block_place(p, d, w); break; case 10: //nothing... only server sends world data to clients. break; case 11: //running a trigger on furniture receive_run_trigger(p, d, w); break; case 12: //received client shoot bullet receive_shoot_bullet(p, d, w); break; case 13: //received client place furniture receive_place_furniture(p, d, w); break; case 14: //received client remove furniture receive_remove_furniture(p, d, w); break; case 15: //receive_furniture_connection receive_furniture_connection(p, d, w); break; case 16: //receive_furniture_disconnect receive_furniture_disconnect(p, d, w); break; case 17: //receive attack plant receive_attack_plant(p, d, w); break; case 18: //receive place plant break; case 19: //receive change item in hands receive_change_hands_item(p, d, w); break; case 20: //receive swing arms receive_swing_arms(p, d, w); break; case 23: //receive someone attacked someone else receive_damage_request(p, d, w); break; case 24: //receive someone changed a chest receive_changed_chest(p, w); break; case 25: //receive someone place a plant receive_place_plant(p, w); break; case 64: //client quitting remove_client(p, d, w); break; } }
public int process_input(Exilania e, int ms_elapsed) { if (!e.IsActive) { return(0); } mouse_previous = mouse_now; mouse_now = Mouse.GetState(); rocker_state = mouse_now.ScrollWheelValue; mouse_cur_spot = new Point(mouse_now.X, mouse_now.Y); if (mouse_now.LeftButton == ButtonState.Pressed && mouse_previous.LeftButton == ButtonState.Released && mouse_now.X > -1 && mouse_now.X < Exilania.screen_size.X && mouse_now.Y > -1 && mouse_now.Y < Exilania.screen_size.Y && e.IsActive) { left_clicked = true; left_clicked_spot = new Point(mouse_now.X, mouse_now.Y); } int code = 0; if (e.IsActive) { live_buttons_down(); } else { collection = ""; } dx_dy = new Point(0, 0); msec_now = (DateTime.Now.Ticks / 10000); msec_elapsed += (int)(msec_now - msec_last); msec_last = msec_now; keys_now = new List <Keys>(Keyboard.GetState().GetPressedKeys()); if (keys_now.Contains(Keys.LeftShift) || keys_now.Contains(Keys.RightShift)) { shift = true; } else { shift = false; } if (keys_now.Contains(Keys.LeftControl) || keys_now.Contains(Keys.RightControl)) { if (last_ctrl_press < 1000 && last_ctrl_press > 0) { //double hit the keyboard within 1 second ctrl_state = 0; last_ctrl_press = -1000; saved_delta = new Vector2(); } else if (last_ctrl_press > -1) { ctrl_state = 1; last_ctrl_press = 0; } ctrl = true; } else { last_ctrl_press += msec_elapsed; ctrl = false; } if (Exilania.gstate == 100 && ctrl == true && ctrl_state == 1) { Vector2 center = new Vector2(e.world.players[Exilania.game_my_user_id].avatar.world_loc.X, e.world.players[Exilania.game_my_user_id].avatar.world_loc.Y); saved_delta = new Vector2((int)center.X - ((int)(center.X + e.world.players[Exilania.game_my_user_id].avatar.input.mouse_loc.X) / 2), (int)center.Y - ((int)(center.Y + e.world.players[Exilania.game_my_user_id].avatar.input.mouse_loc.Y) / 2)); if (Math.Abs(saved_delta.X) > Exilania.screen_size.X / 2) { if (saved_delta.X < 0) { saved_delta.X = -Exilania.screen_size.X / 2; } else { saved_delta.X = Exilania.screen_size.X / 2; } } if (Math.Abs(saved_delta.Y) > Exilania.screen_size.Y / 2) { if (saved_delta.Y < 0) { saved_delta.Y = -Exilania.screen_size.Y / 2; } else { saved_delta.Y = Exilania.screen_size.Y / 2; } } } if (keys_now.Contains(Keys.LeftAlt) || keys_now.Contains(Keys.RightAlt)) { alt = true; } else { alt = false; } /* if (keys_now.Contains(Keys.Back)) * { * if (key_input.Length > 1) * { * key_input = key_input.Substring(0, key_input.Length - 1); * } * else if (key_input.Length == 1) * key_input = ""; * }*/ if (keys_now.Contains(Keys.Enter) && !keys_previous.Contains(Keys.Enter)) { enter = true; } bool cont_down = false; bool repeated = false; pressed = ""; foreach (Keys p in keys_now) { if (keys_previous.Contains(p)) { cont_down = true; } if (!keys_previous.Contains(p) || (keys_previous.Contains(p) && msec_elapsed > key_wait_time)) { if (p.ToString().Length < 2) { if ((shift && !caps_loc) || (!shift && caps_loc)) { pressed += p.ToString(); } else { pressed += p.ToString().ToLower(); } } repeated = true; switch (p) { case Keys.CapsLock: if (caps_loc) { caps_loc = false; } else { caps_loc = true; } break; case Keys.Escape: code = -1; break; case Keys.F12: code = -2; break; case Keys.F11: code = 1; break; case Keys.F10: code = 5; break; case Keys.F2: code = 2; break; case Keys.F3: code = 4; break; case Keys.M: code = 10; break; case Keys.F1: code = 20; break; case Keys.Up: dx_dy.Y = -1; break; case Keys.Down: dx_dy.Y = 1; break; case Keys.Left: dx_dy.X = -1; break; case Keys.Right: dx_dy.X = 1; break; case Keys.PageUp: dx_dy.X = 1; dx_dy.Y = -1; break; case Keys.PageDown: dx_dy.X = 1; dx_dy.Y = 1; break; case Keys.Home: dx_dy.X = -1; dx_dy.Y = -1; break; case Keys.End: dx_dy.X = -1; dx_dy.Y = 1; break; case Keys.Space: key_input += " "; break; case Keys.Enter: code = 3; break; case Keys.OemPeriod: if (shift) { key_input += ">"; } else { key_input += "."; } break; case Keys.OemComma: if (shift) { key_input += "<"; } else { key_input += ","; } break; case Keys.NumPad1: case Keys.D1: if (shift) { key_input += "!"; } else { key_input += "1"; } dx_dy.X = -1; dx_dy.Y = 1; break; case Keys.NumPad2: case Keys.D2: if (shift) { key_input += "@"; } else { key_input += "2"; } dx_dy.Y = 1; break; case Keys.NumPad3: case Keys.D3: if (shift) { key_input += "#"; } else { key_input += "3"; } dx_dy.X = 1; dx_dy.Y = 1; break; case Keys.D4: case Keys.NumPad4: if (shift) { key_input += "$"; } else { key_input += "4"; } dx_dy.X = -1; break; case Keys.NumPad5: case Keys.D5: if (shift) { key_input += "%"; } else { key_input += "5"; } break; case Keys.NumPad6: case Keys.D6: if (shift) { key_input += "^"; } else { key_input += "6"; } dx_dy.X = 1; break; case Keys.NumPad7: case Keys.D7: if (shift) { key_input += "&"; } else { key_input += "7"; } dx_dy.X = -1; dx_dy.Y = -1; break; case Keys.NumPad8: case Keys.D8: if (shift) { key_input += "*"; } else { key_input += "8"; } dx_dy.Y = -1; break; case Keys.NumPad9: case Keys.D9: if (shift) { key_input += "("; } else { key_input += "9"; } dx_dy.Y = -1; dx_dy.X = 1; break; case Keys.NumPad0: case Keys.D0: if (shift) { key_input += ")"; } else { key_input += "0"; } break; case Keys.OemPipe: if (shift) { key_input += "|"; } else { key_input += "\\"; } break; case Keys.OemOpenBrackets: if (shift) { key_input += "{"; } else { key_input += "["; } break; case Keys.OemCloseBrackets: if (shift) { key_input += "}"; } else { key_input += "]"; } break; case Keys.OemQuestion: if (shift) { key_input += "?"; } else { key_input += "/"; } break; case Keys.OemPlus: if (shift) { key_input += "+"; } else { key_input += "="; } break; case Keys.Add: key_input += "+"; break; case Keys.Subtract: key_input += "-"; break; case Keys.Divide: key_input += "/"; break; case Keys.Multiply: key_input += "*"; break; case Keys.Decimal: key_input += "."; break; case Keys.OemQuotes: if (shift) { key_input += "\""; } else { key_input += "'"; } break; case Keys.OemMinus: if (!shift) { key_input += "-"; } else { key_input += "_"; } break; case Keys.Back: if (key_input.Length > 1) { key_input = key_input.Substring(0, key_input.Length - 1); } else if (key_input.Length == 1) { key_input = ""; } break; case Keys.OemTilde: if (!shift) { key_input = ""; } else { key_input += "~"; } break; case Keys.OemSemicolon: if (shift) { key_input += ":"; } else { key_input += ";"; } break; default: break; } } } if (repeated) { key_input += pressed; msec_elapsed = 0; } if (cont_down) { key_wait_time--; if (key_wait_time < 150) { key_wait_time = 150; } } else { key_wait_time = init_key_wait_time; } return(code); }