Example #1
0
        public void RUN()
        {
            this.Invoke(new MethodInvoker(delegate ()
            {
                this.m_Client = new TcpClient();
                try
                {
                    this.m_Client.Connect(this.ipText.Text, Int32.Parse(this.portText.Text));

                }
                catch
                {
                    MessageBox.Show("Cannot Access...");
                    return;
                }

                this.m_NetStream = this.m_Client.GetStream();
                int nRead = 0;
                bool whileFinish = true;
                int iterator = 0;

                while (whileFinish)
                {
                    try
                    {
                        nRead = 0;
                        nRead = this.m_NetStream.Read(this.readBuffer, 0, 1024 * 4);

                    }
                    catch
                    {
                        whileFinish = true;
                        this.m_NetStream = null;
                    }
                    object obj = Packets.Deserialize(this.readBuffer);
                    this.m_musicList = (MusicList)obj;
                    string[] listStr = new string[4];
                    listStr = m_musicList.list.Split('_');

                    ListViewItem listviewitem = new ListViewItem(listStr);
                    this.serverList.Items.Add(listviewitem);

                    iterator++;

                    if (iterator == this.m_musicList.Length)
                        whileFinish = false;
                }
            }));
           
        }
Example #2
0
        private void RunConnectedLoop()
        {
            while (connection.Connected)
            {
                try
                {
                    int packetId_ = stream.ReadByte();
                    if (packetId_ == -1)
                    {
                        break;
                    }
                    byte           packetId = (byte)packetId_;
                    Packets.Packet packet   = Packets.Deserialize(packetId, stream);
                    if (_DebugLogIncoming)
                    {
                        Console.WriteLine("0x" + ((byte)packet.PacketId).ToString("X2") + ' ' + packet.PacketId.ToString());
                        if (_PacketDumpIncoming)
                        {
                            packet.Dump();
                        }
                    }
                    switch (packet.PacketId)
                    {
                    case Packets.PacketId.KeepAlive:
                        OnPacket_KeepAlive((Packets.KeepAlive)packet);
                        break;

                    case Packets.PacketId.LoginRequest:
                        OnPacket_LoginRequest((Packets.LoginRequestIncoming)packet);
                        break;

                    case Packets.PacketId.Handshake:
                        OnPacket_Handshake((Packets.HandshakeIncoming)packet);
                        break;

                    case Packets.PacketId.ChatMessage:
                        OnPacket_ChatMessage((Packets.ChatMessage)packet);
                        break;

                    case Packets.PacketId.TimeUpdate:
                        OnPacket_TimeUpdate((Packets.TimeUpdate)packet);
                        break;

                    case Packets.PacketId.EntityEquipment:
                        OnPacket_EntityEquipment((Packets.EntityEquipment)packet);
                        break;

                    case Packets.PacketId.SpawnPosition:
                        OnPacket_SpawnPosition((Packets.SpawnPosition)packet);
                        break;

                    case Packets.PacketId.UseEntity:
                        OnPacket_UseEntity((Packets.UseEntity)packet);
                        break;

                    case Packets.PacketId.UpdateHealth:
                        OnPacket_UpdateHealth((Packets.UpdateHealth)packet);
                        break;

                    case Packets.PacketId.Respawn:
                        OnPacket_Respawn((Packets.Respawn)packet);
                        break;

                    case Packets.PacketId.Player:
                        OnPacket_Player((Packets.Player)packet);
                        break;

                    case Packets.PacketId.PlayerPosition:
                        OnPacket_PlayerPosition((Packets.PlayerPosition)packet);
                        break;

                    case Packets.PacketId.PlayerLook:
                        OnPacket_PlayerLook((Packets.PlayerLook)packet);
                        break;

                    case Packets.PacketId.PlayerPositionAndLook:
                        OnPacket_PlayerPositionAndLook((Packets.PlayerPositionAndLookIncoming)packet);
                        break;

                    case Packets.PacketId.PlayerDigging:
                        OnPacket_PlayerDigging((Packets.PlayerDigging)packet);
                        break;

                    case Packets.PacketId.PlayerBlockPlacement:
                        OnPacket_PlayerBlockPlacement((Packets.PlayerBlockPlacement)packet);
                        break;

                    case Packets.PacketId.HoldingChange:
                        OnPacket_HoldingChange((Packets.HoldingChange)packet);
                        break;

                    case Packets.PacketId.UseBed:
                        OnPacket_UseBed((Packets.UseBed)packet);
                        break;

                    case Packets.PacketId.Animation:
                        OnPacket_Animation((Packets.Animation)packet);
                        break;

                    case Packets.PacketId.EntityAction:
                        OnPacket_EntityAction((Packets.EntityAction)packet);
                        break;

                    case Packets.PacketId.NamedEntitySpawn:
                        OnPacket_NamedEntitySpawn((Packets.NamedEntitySpawn)packet);
                        break;

                    case Packets.PacketId.PickupSpawn:
                        OnPacket_PickupSpawn((Packets.PickupSpawn)packet);
                        break;

                    case Packets.PacketId.CollectItem:
                        OnPacket_CollectItem((Packets.CollectItem)packet);
                        break;

                    case Packets.PacketId.AddObjectVehicle:
                        OnPacket_AddObjectVehicle((Packets.AddObjectVehicle)packet);
                        break;

                    case Packets.PacketId.MobSpawn:
                        OnPacket_MobSpawn((Packets.MobSpawn)packet);
                        break;

                    case Packets.PacketId.EntityPainting:
                        OnPacket_EntityPainting((Packets.EntityPainting)packet);
                        break;

                    case Packets.PacketId.UNKNOWN_1B:
                        OnPacket_UNKNOWN_1B((Packets.UNKNOWN_1B)packet);
                        break;

                    case Packets.PacketId.EntityVelocity:
                        OnPacket_EntityVelocity((Packets.EntityVelocity)packet);
                        break;

                    case Packets.PacketId.DestroyEntity:
                        OnPacket_DestroyEntity((Packets.DestroyEntity)packet);
                        break;

                    case Packets.PacketId.Entity:
                        OnPacket_Entity((Packets.Entity)packet);
                        break;

                    case Packets.PacketId.EntityRelativeMove:
                        OnPacket_EntityRelativeMove((Packets.EntityRelativeMove)packet);
                        break;

                    case Packets.PacketId.EntityLook:
                        OnPacket_EntityLook((Packets.EntityLook)packet);
                        break;

                    case  Packets.PacketId.EntityLookAndRelativeMove:
                        OnPacket_EntityLookAndRelativeMove((Packets.EntityLookAndRelativeMove)packet);
                        break;

                    case Packets.PacketId.EntityTeleport:
                        OnPacket_EntityTeleport((Packets.EntityTeleport)packet);
                        break;

                    case Packets.PacketId.EntityStatus:
                        OnPacket_EntityStatus((Packets.EntityStatus)packet);
                        break;

                    case Packets.PacketId.AttachEntity:
                        OnPacket_AttachEntity((Packets.AttachEntity)packet);
                        break;

                    case Packets.PacketId.EntityMetadata:
                        OnPacket_EntityMetadata((Packets.EntityMetadata)packet);
                        break;

                    case Packets.PacketId.PreChunk:
                        OnPacket_PreChunk((Packets.PreChunk)packet);
                        break;

                    case Packets.PacketId.MapChunk:
                        OnPacket_MapChunk((Packets.MapChunk)packet);
                        break;

                    case Packets.PacketId.MultiBlockChange:
                        OnPacket_MultiBlockChange((Packets.MultiBlockChange)packet);
                        break;

                    case Packets.PacketId.BlockChange:
                        OnPacket_BlockChange((Packets.BlockChange)packet);
                        break;

                    case Packets.PacketId.PlayNoteBlock:
                        OnPacket_PlayNoteBlock((Packets.PlayNoteBlock)packet);
                        break;

                    case Packets.PacketId.Explosion:
                        OnPacket_Explosion((Packets.Explosion)packet);
                        break;

                    case Packets.PacketId.NewInvalidState:
                        OnPacket_NewInvalidState((Packets.NewInvalidState)packet);
                        break;

                    case Packets.PacketId.Thunderbolt:
                        OnPacket_Thunderbolt((Packets.Thunderbolt)packet);
                        break;

                    case Packets.PacketId.OpenWindow:
                        OnPacket_OpenWindow((Packets.OpenWindow)packet);
                        break;

                    case Packets.PacketId.CloseWindow:
                        OnPacket_CloseWindow((Packets.CloseWindow)packet);
                        break;

                    case Packets.PacketId.WindowClick:
                        OnPacket_WindowClick((Packets.WindowClick)packet);
                        break;

                    case Packets.PacketId.SetSlot:
                        OnPacket_SetSlot((Packets.SetSlot)packet);
                        break;

                    case Packets.PacketId.WindowItems:
                        OnPacket_WindowItems((Packets.WindowItems)packet);
                        break;

                    case Packets.PacketId.UpdateProgressBar:
                        OnPacket_UpdateProgressBar((Packets.UpdateProgressBar)packet);
                        break;

                    case Packets.PacketId.Transaction:
                        OnPacket_Transaction((Packets.Transaction)packet);
                        break;

                    case Packets.PacketId.UpdateSign:
                        OnPacket_UpdateSign((Packets.UpdateSign)packet);
                        break;

                    case Packets.PacketId.IncrementStatistic:
                        OnPacket_IncrementStatistic((Packets.IncrementStatistic)packet);
                        break;

                    case Packets.PacketId.DisconnectKick:
                        OnPacket_DisconnectKick((Packets.DisconnectKick)packet);
                        break;

                    default:
                        string message = "";
                        if (Enum.IsDefined(typeof(Packets.PacketId), packetId))
                        {
                            message = "Sambuca encountered unimplemented packet 0x" + packetId.ToString("X2") + " " + ((Packets.PacketId)packetId).ToString();
                        }
                        else
                        {
                            message = "Sambuca encountered unrecognised packet 0x" + packetId.ToString("X2");
                        }
                        SendPacket(new Packets.DisconnectKick(message));
                        Console.WriteLine(message);
                        connection.Close();     // DEBUG OPTION
                        break;
                    }
                }
                catch (Exception ex) { Console.WriteLine(ex.ToString()); }
            }
        }
Example #3
0
        private void addBtn_Click(object sender, EventArgs e)
        {
            if (pathText.Text == "")
            {
                MessageBox.Show("유효한 경로가 입력되지 않았습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // send request
            ListViewItem checkedItem = serverList.FocusedItem;
            this.requestNo = serverList.Items.IndexOf(checkedItem).ToString();
            int i = 0;
            while (true)
            {
                if(playList.Items.Count == 0)
                {
                    break;
                }
                string title = playList.Items[i].SubItems[0].Text;
                if (checkedItem.SubItems[0].Text.CompareTo(title) == 0)
                {
                    MessageBox.Show("이미 등록되었습니다.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }else if(i+1 == playList.Items.Count)
                {
                    break;
                }

                i++;
            }
            m_requestMusic = new RequestMusic();

            m_requestMusic.requestNo = requestNo;

            Packets.Serialize(m_requestMusic).CopyTo(sendBuffer, 0);

            this.Send();
            // send request end
            
            
            progressBar.Value = 0;
            

            // recieve file name
            try
            {
                int nRead = 0;
                nRead = this.m_NetStream.Read(this.readBuffer, 0, 1024 * 4);

            }
            catch
            {
                //this.m_NetStream = null;
            }
            object obj = Packets.Deserialize(this.readBuffer);
            this.m_fileName = (FileName)obj;
            string filename = m_fileName.fileName;
            int size = m_fileName.Length;
            // recieve file name end

            // recieve file
            byte[] b = new byte[1024 * 4];
            int totalLength = 0;
            string songname = pathText.Text + "\\\\" + filename;

            fs = new FileStream(songname, FileMode.Create, FileAccess.Write);
            BinaryWriter bw = new BinaryWriter(fs);

            while (totalLength < size)
            {
                int nRead = 0;
                try
                {
                    nRead = 0;
                    nRead = this.m_NetStream.Read(this.readBuffer, 0, 1024 * 4);

                }
                catch
                {
                    //this.m_NetStream = null;
                }

                int recieveLength = nRead;
                bw.Write(this.readBuffer, 0, recieveLength);
                totalLength += recieveLength;
                progressBar.PerformStep();
            }

            bw.Close();
            fs.Close();
            // recieve file end

            // add music list
            this.playList.Items.Add((ListViewItem)checkedItem.Clone());
            // add music list end

            // delete server list
            // this.serverList.Items.Remove(checkedItem);
            // delete server list end

            // append playerlist
            currentPlay = wmp.newMedia(@"" + pathText.Text + "\\" + filename);
            playerList.appendItem(currentPlay);
            // append playerlist end
        }