Exemplo n.º 1
0
 private void Redirect(UsernameList users, RedirectDelegate redirecter)
 {
     foreach (var u in users)
     {
         if (redirecter != null)
         {
             redirecter.Invoke(u);
         }
     }
 }
Exemplo n.º 2
0
        public void SendAuthCustom(Header h, Subheader sh, UserInformation i, UsernameList l, WriteCustom wc)
        {
            PacketWriter pw = new PacketWriter();

            pw.WriteInt((int)h);
            pw.WriteInt((int)sh);
            pw.WriteObject(i);
            pw.WriteObject(l);
            if (wc != null)
            {
                wc.Invoke(pw);
            }
            Send(pw.GetBytes(BUFFER_LENGTH));
        }
Exemplo n.º 3
0
        private void Message(Socket socket, Subheader sh, PacketReader pr)
        {
            //Header h = Header.Message;

            SessionInformation    session = pr.ReadObject <SessionInformation>(); // Reads Session Information from User Identity
            ServerUserInformation sUsers  = FindUser(session);                    //

            if (!UserExist(session))
            {
                SendError(socket, Subheader.SESSIONLOST, null);
                return;
            }

            var users = UsernameList.Deserialize(ref pr);


            switch (sh)
            {
            case Subheader.TEXTMSG:     // (Header,Subheader,SessionInformation,UsernameList,String)
                var text = pr.ReadString();
                Console.WriteLine(text);
                //Redirect(users, (user) => {RedirectPacket(h, sh, socket, sUsers.username, user, text); });
                break;

            /*
             * case Subheader.IMGMSG: // (Header,Subheader,SessionInformation,UsernameList,Image)
             * var img = pr.ReadImage();
             * Redirect(users, (user) => {
             *  RedirectPacket(h, sh, socket, sUsers.username, user, img); });
             * break;
             *
             * case Subheader.FILEMSG: // (Header,Subheader,SessionInformation,UsernameList,File)
             * var file = pr.ReadObject<File>();
             * Redirect(users, (user) => {
             *  RedirectPacket(h, sh, socket, sUsers.username, user, file);
             * });
             * break;
             */
            default:     // Invalid Subheader
                //Console.Write((int)sh);
                Dispose(socket);
                Console.WriteLine("Message disposal");
                SendError(socket, sh, (pw) => { pw.Write("server - Error with sending test message"); });
                break;
            }
        }