Beispiel #1
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;
            }
        }
Beispiel #2
0
 public bool UserExist(SessionInformation si)
 {
     return(clients.Exists(u => u.username == si.username && u.user_id == si.user_id));
 }
Beispiel #3
0
 private ServerUserInformation FindUser(SessionInformation si)
 {
     return(clients.Find(u => u.username == si.username && u.user_id == si.user_id));
 }