public byte[] makeClient_PacketInfo(Vector3 pos, int Player_Animator, float dirX, float dirZ, float horizontal, float vertical, Vector3 PlayerRotation, string nickName) { FlatBufferBuilder fbb = new FlatBufferBuilder(1); fbb.Clear(); // 클리어를 안해주고 시작하면 계속 누적해서 데이터가 들어간다. var fbbNickName = fbb.CreateString(nickName); // String 문자열이 있을경우 미리 생성해라. Client_info.StartClient_info(fbb); Client_info.AddAnimator(fbb, Player_Animator); Client_info.AddDirX(fbb, dirX); Client_info.AddDirZ(fbb, dirZ); Client_info.AddHorizontal(fbb, horizontal); Client_info.AddVertical(fbb, vertical); Client_info.AddName(fbb, fbbNickName); Client_info.AddPosition(fbb, Vec3.CreateVec3(fbb, pos.x, pos.y, pos.z)); Client_info.AddRotation(fbb, Vec3.CreateVec3(fbb, PlayerRotation.x, PlayerRotation.y, PlayerRotation.z)); var endOffset = Client_info.EndClient_info(fbb); fbb.Finish(endOffset.Value); byte[] packet = fbb.SizedByteArray(); // flatbuffers 실제 패킷 데이터 byte[] magic_packet = makePacketinfo(packet.Length, CS_INFO); byte[] real_packet = new byte[packet.Length + 8]; System.Buffer.BlockCopy(magic_packet, 0, real_packet, 0, magic_packet.Length); System.Buffer.BlockCopy(packet, 0, real_packet, 8, packet.Length); return(real_packet); }
/* * Metodo che riabilita l'interfaccia in caso di connessione non riuscita * Altrimenti crea la MultiMainWindow (se non seiste già) aggiungendo la tab con le varie informazioni */ private void requestConnection(IAsyncResult result) { Client_info info = result.AsyncState as Client_info; // Caso in cui la connessione non è andata a buon fine if ((info == null) || (!info.client.Connected)) { MessageBox.Show("Impossibile stabilire una connesione"); this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { // Riabilitazione dell'interfaccia ConnectionButton.IsEnabled = true; IPTextBox1.IsEnabled = IPTextBox2.IsEnabled = IPTextBox3.IsEnabled = IPTextBox4.IsEnabled = true; PortTextBox.IsEnabled = true; this.Cursor = Cursors.Arrow; })); return; } NetworkStream stream = info.client.GetStream(); stream.ReadTimeout = 5000; // Ricerca tra le finestre dell'applicazione di una MultiMainWindow. this.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { foreach (Window window in System.Windows.Application.Current.Windows) { if (window is MultiMainWindow) { // Se esiste gà una MultiMainWindow, viene aggiunta una nuova Tab MultiMainWindow w = window as MultiMainWindow; w.addTab(info.client, stream, info.indirizzo); w.connessioni_attive.Add(info.indirizzo); this.Close(); return; } } // Altrimenti viene creata la MultiMainWindow MultiMainWindow main = new MultiMainWindow(info.client, stream, info.indirizzo); main.connessioni_attive.Add(info.indirizzo); this.Close(); main.Show(); })); try { info.client.EndConnect(result); } catch (SocketException) { // In caso di errore sul socket la nuova Tab viene chiusa ExceptionHandler.IntroConnectionError(); } catch (ObjectDisposedException) { // In caso di socket chiuso la nuova Tab viene chiusa ExceptionHandler.IntroConnectionError(); } }
public void ProcessPacket(int size, int type, byte[] recvPacket) { if (type == Game.Protocol.Protocol.SC_ID) { ByteBuffer recv_buf = new ByteBuffer(recvPacket); var get_all_data = Init_Collection_IM.GetRootAsInit_Collection_IM(recv_buf); product_complete[0] = get_all_data.Complete1; product_complete[1] = get_all_data.Complete2; product_complete[2] = get_all_data.Complete3; product_complete[3] = get_all_data.Complete4; product_complete[4] = get_all_data.Complete5; for (int i = 0; i < get_all_data.ItemDataLength; ++i) { //데이터 접근 get_all_data.Data(i).Value.변수 int item_id = get_all_data.ItemData(i).Value.Id; int item_t = get_all_data.ItemData(i).Value.Type; Vector3 item_p = new Vector3(get_all_data.ItemData(i).Value.Position.Value.X, get_all_data.ItemData(i).Value.Position.Value.Y, get_all_data.ItemData(i).Value.Position.Value.Z); int d = get_all_data.ItemData(i).Value.Draw; if (item_data.ContainsKey(item_id)) { ItemClass iter = item_data[item_id]; iter.set_id(item_id); iter.set_type(item_t); iter.set_pos(item_p); if (d == 1) { iter.set_draw(true); } else { iter.set_draw(false); } } else { item_data.Add(item_id, new ItemClass(item_id, item_t, item_p)); if (d == 1) { item_data[item_id].set_draw(true); } else { item_data[item_id].set_draw(false); } } } for (int i = 0; i < get_all_data.MonsterDataLength; ++i) { int monster_id = get_all_data.MonsterData(i).Value.Id; int monster_hp = get_all_data.MonsterData(i).Value.Hp; Vector3 monster_p = new Vector3(get_all_data.MonsterData(i).Value.Position.Value.X, get_all_data.MonsterData(i).Value.Position.Value.Y, get_all_data.MonsterData(i).Value.Position.Value.Z); Vector3 monster_r = new Vector3(get_all_data.MonsterData(i).Value.Rotation.Value.X, get_all_data.MonsterData(i).Value.Rotation.Value.Y, get_all_data.MonsterData(i).Value.Rotation.Value.Z); int monster_target = get_all_data.MonsterData(i).Value.Target; float monster_x = get_all_data.MonsterData(i).Value.DirX; float monster_z = get_all_data.MonsterData(i).Value.DirZ; int monster_cal = get_all_data.MonsterData(i).Value.Calculate; int monster_ani = get_all_data.MonsterData(i).Value.Animator; if (monster_data.ContainsKey(monster_id)) { MonsterClass iter = monster_data[monster_id]; iter.set_id(monster_id); iter.set_hp(monster_hp); iter.set_pos(monster_p); iter.set_rot(monster_r); iter.set_chase_id(monster_target); iter.set_dirX(monster_x); iter.set_dirZ(monster_z); iter.set_calculate_id(monster_cal); iter.set_animator(monster_hp); iter.set_draw(true); } else { monster_data.Add(monster_id, new MonsterClass(monster_id, monster_hp, monster_hp, monster_x, monster_z, monster_p, monster_r, monster_target, monster_cal)); monster_data[monster_id].set_draw(true); //spawner.Spawn(id, p, monster_data[id]); } } Client_id = get_all_data.MyData.Value.Id; new_player_id = get_all_data.MyData.Value.Id; int id = get_all_data.MyData.Value.Id; string n = get_all_data.MyData.Value.Name; Vector3 p = new Vector3(get_all_data.MyData.Value.Position.Value.X, get_all_data.MyData.Value.Position.Value.Y, get_all_data.MyData.Value.Position.Value.Z); int hp = get_all_data.MyData.Value.Hp; int mhp = get_all_data.MyData.Value.MaxHp; int i1 = get_all_data.MyData.Value.Item1; int i2 = get_all_data.MyData.Value.Item2; int i3 = get_all_data.MyData.Value.Item3; int i4 = get_all_data.MyData.Value.Item4; int character = get_all_data.MyData.Value.Character; int ic1 = get_all_data.MyData.Value.Ic1; int ic2 = get_all_data.MyData.Value.Ic2; int ic3 = get_all_data.MyData.Value.Ic3; int ic4 = get_all_data.MyData.Value.IC4; if (client_data.ContainsKey(id)) { ClientClass iter = client_data[id]; iter.set_name(n); iter.set_pos(p); iter.set_hp(hp); iter.set_item(i1, 0); iter.set_item(i2, 1); iter.set_item(i3, 2); iter.set_item(i4, 3); iter.set_char(character); iter.set_item_count(ic1, 0); iter.set_item_count(ic2, 1); iter.set_item_count(ic3, 2); iter.set_item_count(ic4, 3); iter.set_draw(true); } else { client_data.Add(id, new ClientClass(id, n, p, hp, i1, i2, i3, i4, character, ic1, ic2, ic3, ic4)); client_data[id].set_draw(true); } SceneNum = 2; } else if (type == Game.Protocol.Protocol.SC_PUT_PLAYER) // 다른 클라가 접속했을 때 { ByteBuffer recv_buf = new ByteBuffer(recvPacket); Client_info get_data = Client_info.GetRootAsClient_info(recv_buf); new_player_id = get_data.Id; int id = get_data.Id; int character = get_data.Type; int hp = get_data.Hp; int ani = get_data.Animator; float x = get_data.DirX; float z = get_data.DirZ; float h = get_data.Horizontal; float v = get_data.Vertical; string n = get_data.Name; Vector3 p = new Vector3(get_data.Position.Value.X, get_data.Position.Value.Y, get_data.Position.Value.Z); Vector3 r = new Vector3(get_data.Rotation.Value.X, get_data.Rotation.Value.Y, get_data.Rotation.Value.Z); if (client_data.ContainsKey(id)) { ClientClass iter = client_data[id]; iter.set_char(character); iter.set_hp(hp); iter.set_pos(p); iter.set_rot(r); iter.set_vertical(v); iter.set_horizontal(h); iter.set_animator(ani); iter.set_dirX(x); iter.set_dirZ(z); iter.set_draw(true); } else { client_data.Add(id, new ClientClass(id, character, hp, ani, x, z, h, v, n, p, r)); client_data[id].set_draw(true); } Debug.Log("새로 접속한 아이디 : " + new_player_id); } else if (type == Game.Protocol.Protocol.SC_ALL_PLAYER_DATA) // 이 클라가 처음 접속했을 때 다른 모든 클라들의 데이터 { ByteBuffer recv_buf = new ByteBuffer(recvPacket); var get_all_data = Client_Collection.GetRootAsClient_Collection(recv_buf); for (int i = 0; i < get_all_data.DataLength; ++i) { //데이터 접근 get_all_data.Data(i).Value.변수 int id = get_all_data.Data(i).Value.Id; int character = get_all_data.Data(i).Value.Type; int hp = get_all_data.Data(i).Value.Hp; int ani = get_all_data.Data(i).Value.Animator; float x = get_all_data.Data(i).Value.DirX; float z = get_all_data.Data(i).Value.DirZ; float h = get_all_data.Data(i).Value.Horizontal; float v = get_all_data.Data(i).Value.Vertical; string n = get_all_data.Data(i).Value.Name; Vector3 p = new Vector3(get_all_data.Data(i).Value.Position.Value.X, get_all_data.Data(i).Value.Position.Value.Y, get_all_data.Data(i).Value.Position.Value.Z); Vector3 r = new Vector3(get_all_data.Data(i).Value.Rotation.Value.X, get_all_data.Data(i).Value.Rotation.Value.Y, get_all_data.Data(i).Value.Rotation.Value.Z); if (client_data.ContainsKey(id)) { ClientClass iter = client_data[id]; iter.set_hp(hp); iter.set_char(character); iter.set_pos(p); iter.set_rot(r); iter.set_vertical(v); iter.set_horizontal(h); iter.set_animator(ani); iter.set_dirX(x); iter.set_dirZ(z); iter.set_draw(true); } else { client_data.Add(id, new ClientClass(id, character, hp, ani, x, z, h, v, n, p, r)); client_data[id].set_draw(true); } } } else if (type == Game.Protocol.Protocol.SC_PLAYER_STATUS) // 클라가 움직였을때 그 클라 데이터 { ByteBuffer recv_buf = new ByteBuffer(recvPacket); Client_info get_data = Client_info.GetRootAsClient_info(recv_buf); int id = get_data.Id; int character = get_data.Type; int hp = get_data.Hp; int ani = get_data.Animator; float x = get_data.DirX; float z = get_data.DirZ; float h = get_data.Horizontal; float v = get_data.Vertical; string n = get_data.Name; Vector3 p = new Vector3(get_data.Position.Value.X, get_data.Position.Value.Y, get_data.Position.Value.Z); Vector3 r = new Vector3(get_data.Rotation.Value.X, get_data.Rotation.Value.Y, get_data.Rotation.Value.Z); if (client_data.ContainsKey(id)) { ClientClass iter = client_data[id]; iter.set_char(character); iter.set_hp(hp); iter.set_pos(p); iter.set_rot(r); iter.set_vertical(v); iter.set_horizontal(h); iter.set_animator(ani); iter.set_dirX(x); iter.set_dirZ(z); iter.set_draw(true); } else { client_data.Add(id, new ClientClass(id, character, hp, ani, x, z, h, v, n, p, r)); client_data[id].set_draw(true); } } else if (type == Game.Protocol.Protocol.SC_REMOVE_PLAYER) { int id = recvPacket[0]; client_data[id].set_draw(false); } else if (type == Game.Protocol.Protocol.SC_PUT_MONSTER) { //ByteBuffer recv_buf = new ByteBuffer(recvPacket); //Monster_info get_data = Monster_info.GetRootAsMonster_info(recv_buf); //int id = get_data.Id; //int hp = get_data.Hp; //int ani = get_data.Animator; //float x = get_data.DirX; //float z = get_data.DirZ; //Vector3 p = new Vector3(get_data.Position.Value.X, get_data.Position.Value.Y, get_data.Position.Value.Z); //Vector3 r = new Vector3(get_data.Rotation.Value.X, get_data.Rotation.Value.Y, get_data.Rotation.Value.Z); //if (monster_data.ContainsKey(id)) //{ // MonsterClass iter = monster_data[id]; // iter.set_hp(hp); // iter.set_pos(p); // iter.set_rot(r); // iter.set_animator(ani); // iter.set_dirX(x); // iter.set_dirZ(z); // iter.set_draw(true); //} //else //{ // monster_data.Add(id, new MonsterClass(id, hp, ani, x, z, p, r)); // monster_data[id].set_draw(true); //} //Debug.Log("몬스터 생성 아이디 : " + id); } else if (type == Game.Protocol.Protocol.SC_REMOVE_MONSTER) { int remove_monster = recvPacket[0]; monster_data[remove_monster].set_hp(0); monster_data[remove_monster].set_animator(0); //monster_data.Remove(remove_monster); } else if (type == Game.Protocol.Protocol.SC_PUT_ITEM) { ByteBuffer recv_buf = new ByteBuffer(recvPacket); var get_all_data = Item_Collection.GetRootAsItem_Collection(recv_buf); for (int i = 0; i < get_all_data.DataLength; ++i) { //데이터 접근 get_all_data.Data(i).Value.변수 int id = get_all_data.Data(i).Value.Id; int t = get_all_data.Data(i).Value.Type; Vector3 p = new Vector3(get_all_data.Data(i).Value.Position.Value.X, get_all_data.Data(i).Value.Position.Value.Y, get_all_data.Data(i).Value.Position.Value.Z); int d = get_all_data.Data(i).Value.Draw; if (item_data.ContainsKey(id)) { ItemClass iter = item_data[id]; iter.set_id(id); iter.set_type(t); iter.set_pos(p); if (d == 0) { iter.set_draw(false); } else if (d == 1) { iter.set_draw(true); } } else { item_data.Add(id, new ItemClass(id, t, p)); if (d == 0) { item_data[id].set_draw(false); } else if (d == 1) { item_data[id].set_draw(true); } } } } else if (type == Game.Protocol.Protocol.SC_REMOVE_ITEM) { int remove_item = recvPacket[0]; item_data[remove_item].set_draw(false); } else if (type == Game.Protocol.Protocol.SC_INIT_DATA) { ByteBuffer recv_buf = new ByteBuffer(recvPacket); var get_all_data = Init_Collection.GetRootAsInit_Collection(recv_buf); product_complete[0] = get_all_data.Complete1; product_complete[1] = get_all_data.Complete2; product_complete[2] = get_all_data.Complete3; product_complete[3] = get_all_data.Complete4; product_complete[4] = get_all_data.Complete5; for (int i = 0; i < get_all_data.ClientDataLength; ++i) { int c_id = get_all_data.ClientData(i).Value.Id; int c_hp = get_all_data.ClientData(i).Value.Hp; int c_ani = get_all_data.ClientData(i).Value.Animator; float c_x = get_all_data.ClientData(i).Value.DirX; float c_z = get_all_data.ClientData(i).Value.DirZ; float c_h = get_all_data.ClientData(i).Value.Horizontal; float c_v = get_all_data.ClientData(i).Value.Vertical; string c_n = get_all_data.ClientData(i).Value.Name; Vector3 c_p = new Vector3(get_all_data.ClientData(i).Value.Position.Value.X, get_all_data.ClientData(i).Value.Position.Value.Y, get_all_data.ClientData(i).Value.Position.Value.Z); Vector3 c_r = new Vector3(get_all_data.ClientData(i).Value.Rotation.Value.X, get_all_data.ClientData(i).Value.Rotation.Value.Y, get_all_data.ClientData(i).Value.Rotation.Value.Z); if (client_data.ContainsKey(c_id)) { ClientClass iter = client_data[c_id]; iter.set_char(get_all_data.ClientData(i).Value.Type); iter.set_hp(c_hp); iter.set_pos(c_p); iter.set_rot(c_r); iter.set_vertical(c_v); iter.set_horizontal(c_h); iter.set_animator(c_ani); iter.set_dirX(c_x); iter.set_dirZ(c_z); iter.set_draw(true); } else { client_data.Add(c_id, new ClientClass(c_id, get_all_data.ClientData(i).Value.Type, c_hp, c_ani, c_x, c_z, c_h, c_v, c_n, c_p, c_r)); ClientClass iter = client_data[c_id]; client_data[c_id].set_draw(true); } } for (int i = 0; i < get_all_data.ItemDataLength; ++i) { //데이터 접근 get_all_data.Data(i).Value.변수 int item_id = get_all_data.ItemData(i).Value.Id; int item_t = get_all_data.ItemData(i).Value.Type; Vector3 item_p = new Vector3(get_all_data.ItemData(i).Value.Position.Value.X, get_all_data.ItemData(i).Value.Position.Value.Y, get_all_data.ItemData(i).Value.Position.Value.Z); int d = get_all_data.ItemData(i).Value.Draw; if (item_data.ContainsKey(item_id)) { ItemClass iter = item_data[item_id]; iter.set_id(item_id); iter.set_type(item_t); iter.set_pos(item_p); if (d == 1) { iter.set_draw(true); } else { iter.set_draw(false); } } else { item_data.Add(item_id, new ItemClass(item_id, item_t, item_p)); if (d == 1) { item_data[item_id].set_draw(true); } else { item_data[item_id].set_draw(false); } } } for (int i = 0; i < get_all_data.MonsterDataLength; ++i) { int monster_id = get_all_data.MonsterData(i).Value.Id; int monster_hp = get_all_data.MonsterData(i).Value.Hp; Vector3 monster_p = new Vector3(get_all_data.MonsterData(i).Value.Position.Value.X, get_all_data.MonsterData(i).Value.Position.Value.Y, get_all_data.MonsterData(i).Value.Position.Value.Z); Vector3 monster_r = new Vector3(get_all_data.MonsterData(i).Value.Rotation.Value.X, get_all_data.MonsterData(i).Value.Rotation.Value.Y, get_all_data.MonsterData(i).Value.Rotation.Value.Z); int monster_target = get_all_data.MonsterData(i).Value.Target; float monster_x = get_all_data.MonsterData(i).Value.DirX; float monster_z = get_all_data.MonsterData(i).Value.DirZ; int monster_cal = get_all_data.MonsterData(i).Value.Calculate; int monster_ani = get_all_data.MonsterData(i).Value.Animator; if (monster_data.ContainsKey(monster_id)) { MonsterClass iter = monster_data[monster_id]; iter.set_id(monster_id); iter.set_hp(monster_hp); iter.set_pos(monster_p); iter.set_rot(monster_r); iter.set_chase_id(monster_target); iter.set_dirX(monster_x); iter.set_dirZ(monster_z); iter.set_calculate_id(monster_cal); iter.set_animator(monster_hp); iter.set_draw(true); } else { monster_data.Add(monster_id, new MonsterClass(monster_id, monster_hp, monster_hp, monster_x, monster_z, monster_p, monster_r, monster_target, monster_cal)); monster_data[monster_id].set_draw(true); //spawner.Spawn(id, p, monster_data[id]); } } Client_id = get_all_data.MyData.Value.Id; new_player_id = get_all_data.MyData.Value.Id; int id = get_all_data.MyData.Value.Id; string n = get_all_data.MyData.Value.Name; Vector3 p = new Vector3(get_all_data.MyData.Value.Position.Value.X, get_all_data.MyData.Value.Position.Value.Y, get_all_data.MyData.Value.Position.Value.Z); int hp = get_all_data.MyData.Value.Hp; int mhp = get_all_data.MyData.Value.MaxHp; int i1 = get_all_data.MyData.Value.Item1; int i2 = get_all_data.MyData.Value.Item2; int i3 = get_all_data.MyData.Value.Item3; int i4 = get_all_data.MyData.Value.Item4; int character = get_all_data.MyData.Value.Character; int ic1 = get_all_data.MyData.Value.Ic1; int ic2 = get_all_data.MyData.Value.Ic2; int ic3 = get_all_data.MyData.Value.Ic3; int ic4 = get_all_data.MyData.Value.IC4; if (client_data.ContainsKey(id)) { ClientClass iter = client_data[id]; iter.set_name(n); iter.set_pos(p); iter.set_hp(hp); iter.set_item(i1, 0); iter.set_item(i2, 1); iter.set_item(i3, 2); iter.set_item(i4, 3); iter.set_char(character); iter.set_item_count(ic1, 0); iter.set_item_count(ic2, 1); iter.set_item_count(ic3, 2); iter.set_item_count(ic4, 3); iter.set_draw(true); } else { client_data.Add(id, new ClientClass(id, n, p, hp, i1, i2, i3, i4, character, ic1, ic2, ic3, ic4)); client_data[id].set_draw(true); } SceneNum = 2; } else if (type == Game.Protocol.Protocol.SC_LOGIN_SUCCESS) { } else if (type == Game.Protocol.Protocol.SC_LOGIN_FAIL) { } else if (type == Game.Protocol.Protocol.SC_SIGNUP) { SceneNum = 1; } else if (type == Game.Protocol.Protocol.SC_REVIVE_MONSTER) { ByteBuffer recv_buf = new ByteBuffer(recvPacket); Monster_info get_all_data = Monster_info.GetRootAsMonster_info(recv_buf); int id = get_all_data.Id; int hp = get_all_data.Hp; Vector3 p = new Vector3(get_all_data.Position.Value.X, get_all_data.Position.Value.Y, get_all_data.Position.Value.Z); Vector3 r = new Vector3(get_all_data.Rotation.Value.X, get_all_data.Rotation.Value.Y, get_all_data.Rotation.Value.Z); int target = get_all_data.Target; float x = get_all_data.DirX; float z = get_all_data.DirZ; int cal = get_all_data.Calculate; int ani = get_all_data.Animator; if (monster_data.ContainsKey(id)) { MonsterClass iter = monster_data[id]; iter.set_id(id); iter.set_hp(hp); iter.set_pos(p); iter.set_rot(r); iter.set_chase_id(target); iter.set_dirX(x); iter.set_dirZ(z); iter.set_calculate_id(cal); iter.set_animator(ani); iter.set_draw(true); } else { monster_data.Add(id, new MonsterClass(id, hp, ani, x, z, p, r, target, cal)); monster_data[id].set_draw(true); //spawner.Spawn(id, p, monster_data[id]); } } else if (type == Game.Protocol.Protocol.SC_MONSTER_INFO) { ByteBuffer recv_buf = new ByteBuffer(recvPacket); Monster_info get_all_data = Monster_info.GetRootAsMonster_info(recv_buf); int id = get_all_data.Id; int hp = get_all_data.Hp; Vector3 p = new Vector3(get_all_data.Position.Value.X, get_all_data.Position.Value.Y, get_all_data.Position.Value.Z); Vector3 r = new Vector3(get_all_data.Rotation.Value.X, get_all_data.Rotation.Value.Y, get_all_data.Rotation.Value.Z); int target = get_all_data.Target; float x = get_all_data.DirX; float z = get_all_data.DirZ; int cal = get_all_data.Calculate; int ani = get_all_data.Animator; if (monster_data.ContainsKey(id)) { MonsterClass iter = monster_data[id]; iter.set_id(id); iter.set_hp(hp); iter.set_pos(p); iter.set_rot(r); iter.set_chase_id(target); iter.set_dirX(x); iter.set_dirZ(z); iter.set_calculate_id(cal); iter.set_animator(ani); iter.set_draw(true); } else { monster_data.Add(id, new MonsterClass(id, hp, ani, x, z, p, r, target, cal)); monster_data[id].set_draw(true); //spawner.Spawn(id, p, monster_data[id]); } } else if (type == Game.Protocol.Protocol.SC_MONSTER_TARGET) { ByteBuffer recv_buf = new ByteBuffer(recvPacket); Eat_Item get_data = Eat_Item.GetRootAsEat_Item(recv_buf); int monster_id = get_data.ItemID; int target = get_data.PlayerID; monster_data[monster_id].set_chase_id(target); } else if (type == Game.Protocol.Protocol.SC_MONSTER_CALCULATE) { ByteBuffer recv_buf = new ByteBuffer(recvPacket); Eat_Item get_data = Eat_Item.GetRootAsEat_Item(recv_buf); int monster_id = get_data.ItemID; int cal = get_data.PlayerID; monster_data[monster_id].set_calculate_id(cal); } else if (type == Game.Protocol.Protocol.SC_COMPLETE_MAKING) { int complete = recvPacket[0]; product_complete[complete] = 1; } else if (type == Game.Protocol.Protocol.SC_END_GAME) { SceneNum = 3; } }
/* * Metodo invocato dall'evento Click del pulsante * Conversione dei parametri e avvio del tentativo di connessione */ private void ConnectionClick(object sender, RoutedEventArgs e) { string indirizzo = IPTextBox1.Text + "." + IPTextBox2.Text + "." + IPTextBox3.Text + "." + IPTextBox4.Text; if (indirizzo == "0.0.0.0") { MessageBox.Show("Impossibile connettersi all'host specificato", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Information); return; } Int32 porta; try { porta = Convert.ToInt32(PortTextBox.Text); } catch (FormatException) { porta = 2000; } catch (OverflowException) { porta = 2000; } // Verifica dell'esistenza di una tab connessa allo stesso indirizzo foreach (Window window in System.Windows.Application.Current.Windows) { if (window is MultiMainWindow) { MultiMainWindow m = window as MultiMainWindow; if (m.connessioni_attive.Contains(indirizzo)) { MessageBox.Show("Connessione già effettuata verso " + indirizzo); return; } } } Console.WriteLine("Connessione verso: {0} - {1}", indirizzo, porta); try { client = new TcpClient(); Client_info info = new Client_info(); info.client = client; info.indirizzo = indirizzo; // Richiesta di connessione asincrona per non bloccare l'interfaccia this.connectionResult = client.BeginConnect(indirizzo, porta, new AsyncCallback(requestConnection), info); // Disabilitazione dell'interfaccia per evitare più richieste contemporanee ConnectionButton.IsEnabled = false; IPTextBox1.IsEnabled = IPTextBox2.IsEnabled = IPTextBox3.IsEnabled = IPTextBox4.IsEnabled = false; PortTextBox.IsEnabled = false; this.Cursor = Cursors.AppStarting; } catch (SecurityException) { MessageBox.Show("Accesso negato: permessi non sufficienti", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Exclamation); } catch (ObjectDisposedException) { MessageBox.Show("Errore di connessione", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Exclamation); } catch (ArgumentOutOfRangeException) { MessageBox.Show("Numero di porta non valido, valori ammessi: 1-65536", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Information); } catch (SocketException) { MessageBox.Show("Impossibile stabilire una connesione", "Attenzione", MessageBoxButton.OK, MessageBoxImage.Warning); } }