diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..4c8aba4 Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/Client/CMakeLists.txt b/Client/CMakeLists.txt new file mode 100644 index 0000000..f9aab60 --- /dev/null +++ b/Client/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.5) + +project(ChatWare VERSION 0.1 LANGUAGES CXX) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets) + +set(PROJECT_SOURCES + main.cpp + mainwindow.cpp + mainwindow.h + mainwindow.ui + encryption.h + encryption.cpp +) + +if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) + qt_add_executable(ChatWare + MANUAL_FINALIZATION + ${PROJECT_SOURCES} + ) +# Define target properties for Android with Qt 6 as: +# set_property(TARGET ChatWare APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR +# ${CMAKE_CURRENT_SOURCE_DIR}/android) +# For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation +else() + if(ANDROID) + add_library(ChatWare SHARED + ${PROJECT_SOURCES} + ) +# Define properties for Android with Qt 5 after find_package() calls as: +# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android") + else() + add_executable(ChatWare + ${PROJECT_SOURCES} + ) + endif() +endif() + +target_link_libraries(ChatWare PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) + +set_target_properties(ChatWare PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com + MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} + MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} + MACOSX_BUNDLE TRUE + WIN32_EXECUTABLE TRUE +) + +install(TARGETS ChatWare + BUNDLE DESTINATION . + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +if(QT_VERSION_MAJOR EQUAL 6) + qt_finalize_executable(ChatWare) +endif() diff --git a/Client/CMakeLists.txt.user b/Client/CMakeLists.txt.user new file mode 100644 index 0000000..70177ed --- /dev/null +++ b/Client/CMakeLists.txt.user @@ -0,0 +1,1369 @@ + + + + + + EnvironmentId + {5de9d785-ce81-488d-ae7f-5e50080fe87e} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Ios.Device.Type + Qt 6.4.2 for iOS + Qt 6.4.2 for iOS + {722e0762-6e5e-43c0-851a-406ef3011c78} + 0 + 0 + 0 + + -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM:STRING=YBCEJGBE4S + Debug + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=arm64 +-DCMAKE_OSX_SYSROOT:STRING=iphoneos +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + 0 + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS + + + + + ALL_BUILD + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM:STRING=YBCEJGBE4S + Release + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=arm64 +-DCMAKE_OSX_SYSROOT:STRING=iphoneos +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM:STRING=YBCEJGBE4S + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=arm64 +-DCMAKE_OSX_SYSROOT:STRING=iphoneos +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM:STRING=YBCEJGBE4S + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=arm64 +-DCMAKE_OSX_SYSROOT:STRING=iphoneos +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + 0 + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + CMakeProjectManager.CMakeBuildConfiguration + + + -DCMAKE_XCODE_ATTRIBUTE_DEVELOPMENT_TEAM:STRING=YBCEJGBE4S + MinSizeRel + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=arm64 +-DCMAKE_OSX_SYSROOT:STRING=iphoneos +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + + true + Deploy to Jafari’s iPad + Qt4ProjectManager.IosDeployStep + + 1 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + Qt4ProjectManager.IosDeployConfiguration + + 1 + + true + true + true + + + + + 0 + + Run ChatWareQT on Jafari’s iPad + Qt4ProjectManager.IosRunConfiguration:ChatWareQT + ChatWareQT + false + true + false + true + + 1 + + + + ProjectExplorer.Project.Target.1 + + Ios.Simulator.Type + Qt 6.4.2 for iOS Simulator + Qt 6.4.2 for iOS Simulator + {bf011fb2-a666-49c3-bd65-c6ab67667fbf} + 0 + 0 + 0 + + Debug + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 +-DCMAKE_OSX_SYSROOT:STRING=iphonesimulator +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + 0 + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS_Simulator + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 +-DCMAKE_OSX_SYSROOT:STRING=iphonesimulator +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS_Simulator + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 +-DCMAKE_OSX_SYSROOT:STRING=iphonesimulator +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS_Simulator + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 +-DCMAKE_OSX_SYSROOT:STRING=iphonesimulator +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + 0 + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS_Simulator + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + false + + -DCMAKE_GENERATOR:STRING=Xcode +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_OSX_ARCHITECTURES:STRING=x86_64 +-DCMAKE_OSX_SYSROOT:STRING=iphonesimulator +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{Ios:DevelopmentTeam:Flag} +%{Ios:ProvisioningProfile:Flag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_iOS_Simulator + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + + true + Deploy to iOS Simulator + Qt4ProjectManager.IosDeployStep + + 1 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + Qt4ProjectManager.IosDeployConfiguration + + 1 + + true + true + true + + 2 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + false + true + + 1 + + + + ProjectExplorer.Project.Target.2 + + Desktop + Qt 6.4.2 for macOS + Qt 6.4.2 for macOS + qt.qt6.642.clang_64_kit + 0 + 0 + 0 + + Debug + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{CMAKE_OSX_ARCHITECTURES:DefaultFlag} + 0 + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_macOS-Debug + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Release +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{CMAKE_OSX_ARCHITECTURES:DefaultFlag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_macOS-Release + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{CMAKE_OSX_ARCHITECTURES:DefaultFlag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_macOS-RelWithDebInfo + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{CMAKE_OSX_ARCHITECTURES:DefaultFlag} + 0 + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_macOS-Profile + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} +%{CMAKE_OSX_ARCHITECTURES:DefaultFlag} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-Qt_6_4_2_for_macOS-MinSizeRel + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + false + true + + 1 + + + + ProjectExplorer.Project.Target.3 + + WebAssemblyDeviceType + WebAssembly Qt 6.4.2 + WebAssembly Qt 6.4.2 + qt.qt6.642.wasm_32_kit + 0 + -1 + 0 + + Debug + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + 0 + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-WebAssembly_Qt_6_4_2-Debug + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=Release +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-WebAssembly_Qt_6_4_2-Release + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-WebAssembly_Qt_6_4_2-RelWithDebInfo + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + 0 + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-WebAssembly_Qt_6_4_2-Profile + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + false + + -DCMAKE_GENERATOR:STRING=Ninja +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:FILEPATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake +-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG} + /Users/chenhangjian/Desktop/ChatWareQT/../build-ChatWareQT-WebAssembly_Qt_6_4_2-MinSizeRel + + + + + all + + false + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + + clean + + false + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 5 + 0 + + true + true + true + + 2 + + ProjectExplorer.CustomExecutableRunConfiguration + + false + true + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 4 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Client/encryption.cpp b/Client/encryption.cpp new file mode 100644 index 0000000..a3a67c1 --- /dev/null +++ b/Client/encryption.cpp @@ -0,0 +1,6 @@ +#include "encryption.h" + +ECC::ECC() +{ + +} diff --git a/Client/encryption.h b/Client/encryption.h new file mode 100644 index 0000000..3680a0c --- /dev/null +++ b/Client/encryption.h @@ -0,0 +1,11 @@ +#ifndef ECC_H +#define ECC_H + + +class ECC +{ +public: + ECC(); +}; + +#endif // ECC_H diff --git a/Client/main.cpp b/Client/main.cpp new file mode 100644 index 0000000..fd3e533 --- /dev/null +++ b/Client/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/Client/mainwindow.cpp b/Client/mainwindow.cpp new file mode 100644 index 0000000..a06fc8e --- /dev/null +++ b/Client/mainwindow.cpp @@ -0,0 +1,15 @@ +#include "mainwindow.h" +#include "./ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) + , ui(new Ui::MainWindow) +{ + ui->setupUi(this); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + diff --git a/Client/mainwindow.h b/Client/mainwindow.h new file mode 100644 index 0000000..4643e32 --- /dev/null +++ b/Client/mainwindow.h @@ -0,0 +1,21 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class MainWindow; } +QT_END_NAMESPACE + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); + +private: + Ui::MainWindow *ui; +}; +#endif // MAINWINDOW_H diff --git a/Client/mainwindow.ui b/Client/mainwindow.ui new file mode 100644 index 0000000..b232854 --- /dev/null +++ b/Client/mainwindow.ui @@ -0,0 +1,22 @@ + + + MainWindow + + + + 0 + 0 + 800 + 600 + + + + MainWindow + + + + + + + + diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/b25d49c2-798d-4eac-91f9-1ae36a84252f.vsidx b/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/b25d49c2-798d-4eac-91f9-1ae36a84252f.vsidx new file mode 100644 index 0000000..d095085 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/b25d49c2-798d-4eac-91f9-1ae36a84252f.vsidx differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/d84fb4f6-6909-43fa-b0f2-6342b1d65446.vsidx b/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/d84fb4f6-6909-43fa-b0f2-6342b1d65446.vsidx new file mode 100644 index 0000000..b1942a9 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/d84fb4f6-6909-43fa-b0f2-6342b1d65446.vsidx differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/de6ba690-8044-4e15-b41d-9699783826da.vsidx b/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/de6ba690-8044-4e15-b41d-9699783826da.vsidx new file mode 100644 index 0000000..cffb985 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/de6ba690-8044-4e15-b41d-9699783826da.vsidx differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/read.lock b/Client_test_Console/Client_test_vs/.vs/Client_test/FileContentIndex/read.lock new file mode 100644 index 0000000..e69de29 diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/v17/.suo b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/.suo new file mode 100644 index 0000000..8a930e8 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/.suo differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/v17/Browse.VC.db b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/Browse.VC.db new file mode 100644 index 0000000..3123803 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/Browse.VC.db differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/b1ad3560e16e3e6a/MAIN.ipch b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/b1ad3560e16e3e6a/MAIN.ipch new file mode 100644 index 0000000..02fc1d6 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/b1ad3560e16e3e6a/MAIN.ipch differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/bff0244b5e635555/CLIENT_TEST.ipch b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/bff0244b5e635555/CLIENT_TEST.ipch new file mode 100644 index 0000000..64824a3 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/bff0244b5e635555/CLIENT_TEST.ipch differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/cc88bc757ff8b5c3/CLIENT_TEST.ipch b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/cc88bc757ff8b5c3/CLIENT_TEST.ipch new file mode 100644 index 0000000..28b51e7 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/cc88bc757ff8b5c3/CLIENT_TEST.ipch differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/f4859565c1210ea1/CHATWARESOCKET.ipch b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/f4859565c1210ea1/CHATWARESOCKET.ipch new file mode 100644 index 0000000..fcfbfa1 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test/v17/ipch/AutoPCH/f4859565c1210ea1/CHATWARESOCKET.ipch differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test_vs/FileContentIndex/0283f20b-582c-410b-b45c-1bf23bd44662.vsidx b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/FileContentIndex/0283f20b-582c-410b-b45c-1bf23bd44662.vsidx new file mode 100644 index 0000000..228d165 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/FileContentIndex/0283f20b-582c-410b-b45c-1bf23bd44662.vsidx differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test_vs/FileContentIndex/f85dc867-721e-4d26-94be-1af343c6c062.vsidx b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/FileContentIndex/f85dc867-721e-4d26-94be-1af343c6c062.vsidx new file mode 100644 index 0000000..c2bcfbc Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/FileContentIndex/f85dc867-721e-4d26-94be-1af343c6c062.vsidx differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test_vs/FileContentIndex/read.lock b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/FileContentIndex/read.lock new file mode 100644 index 0000000..e69de29 diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/.suo b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/.suo new file mode 100644 index 0000000..27bee76 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/.suo differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/Browse.VC.db b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/Browse.VC.db new file mode 100644 index 0000000..2d96e96 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/Browse.VC.db differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/ipch/AutoPCH/63cb40e87def1ef6/CLIENT_TEST.ipch b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/ipch/AutoPCH/63cb40e87def1ef6/CLIENT_TEST.ipch new file mode 100644 index 0000000..27e30d2 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/ipch/AutoPCH/63cb40e87def1ef6/CLIENT_TEST.ipch differ diff --git a/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/ipch/AutoPCH/e30d82a4a6b6f109/MAIN.ipch b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/ipch/AutoPCH/e30d82a4a6b6f109/MAIN.ipch new file mode 100644 index 0000000..a78d33a Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/Client_test_vs/v17/ipch/AutoPCH/e30d82a4a6b6f109/MAIN.ipch differ diff --git a/Client_test_Console/Client_test_vs/.vs/ProjectSettings.json b/Client_test_Console/Client_test_vs/.vs/ProjectSettings.json new file mode 100644 index 0000000..0cf5ea5 --- /dev/null +++ b/Client_test_Console/Client_test_vs/.vs/ProjectSettings.json @@ -0,0 +1,3 @@ +{ + "CurrentProjectSetting": "No Configurations" +} \ No newline at end of file diff --git a/Client_test_Console/Client_test_vs/.vs/VSWorkspaceState.json b/Client_test_Console/Client_test_vs/.vs/VSWorkspaceState.json new file mode 100644 index 0000000..c33fa42 --- /dev/null +++ b/Client_test_Console/Client_test_vs/.vs/VSWorkspaceState.json @@ -0,0 +1,8 @@ +{ + "ExpandedNodes": [ + "", + "\\Client_test" + ], + "SelectedNode": "\\Client_test\\main.cpp", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/Client_test_Console/Client_test_vs/.vs/slnx.sqlite b/Client_test_Console/Client_test_vs/.vs/slnx.sqlite new file mode 100644 index 0000000..8724ae2 Binary files /dev/null and b/Client_test_Console/Client_test_vs/.vs/slnx.sqlite differ diff --git a/Client_test_Console/Client_test_vs/Client_test.sln b/Client_test_Console/Client_test_vs/Client_test.sln new file mode 100644 index 0000000..d87e2c9 --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.2.32526.322 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Client_test", "Client_test\Client_test.vcxproj", "{94659AF7-53C6-4954-8827-6E9E09CEA9B7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {94659AF7-53C6-4954-8827-6E9E09CEA9B7}.Debug|x64.ActiveCfg = Debug|x64 + {94659AF7-53C6-4954-8827-6E9E09CEA9B7}.Debug|x64.Build.0 = Debug|x64 + {94659AF7-53C6-4954-8827-6E9E09CEA9B7}.Debug|x86.ActiveCfg = Debug|Win32 + {94659AF7-53C6-4954-8827-6E9E09CEA9B7}.Debug|x86.Build.0 = Debug|Win32 + {94659AF7-53C6-4954-8827-6E9E09CEA9B7}.Release|x64.ActiveCfg = Release|x64 + {94659AF7-53C6-4954-8827-6E9E09CEA9B7}.Release|x64.Build.0 = Release|x64 + {94659AF7-53C6-4954-8827-6E9E09CEA9B7}.Release|x86.ActiveCfg = Release|Win32 + {94659AF7-53C6-4954-8827-6E9E09CEA9B7}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7CD804AF-BCC2-48D7-BEA1-903229D224DE} + EndGlobalSection +EndGlobal diff --git a/Client_test_Console/Client_test_vs/Client_test/ChatWareSocket.cpp b/Client_test_Console/Client_test_vs/Client_test/ChatWareSocket.cpp new file mode 100644 index 0000000..89b85de --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/ChatWareSocket.cpp @@ -0,0 +1 @@ +#include "ChatWareSocket.h" diff --git a/Client_test_Console/Client_test_vs/Client_test/ChatWareSocket.h b/Client_test_Console/Client_test_vs/Client_test/ChatWareSocket.h new file mode 100644 index 0000000..15bf1fd --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/ChatWareSocket.h @@ -0,0 +1,44 @@ +#pragma once + + +#include +#include + +using namespace std; + +class ChatWareSocket +{ + //캯 + ChatWareSocket(); +}; + +//캯 +ChatWareSocket::ChatWareSocket() { + + +} + +void initialization() { + //ʼ׽ֿ + WORD w_req = MAKEWORD(2, 2);//汾 + WSADATA wsadata; + int err; + err = WSAStartup(w_req, &wsadata); + if (err != 0) { + cout << "ʼ׽ֿʧܣ" << endl; + } + else { + cout << "ʼ׽ֿɹ" << endl; + } + //汾 + if (LOBYTE(wsadata.wVersion) != 2 || HIBYTE(wsadata.wHighVersion) != 2) { + cout << "׽ֿ汾Ų" << endl; + WSACleanup(); + } + else { + cout << "׽ֿ汾ȷ" << endl; + } + //˵ַϢ + +} + diff --git a/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj b/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj new file mode 100644 index 0000000..2e4ed70 --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj @@ -0,0 +1,139 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {94659af7-53c6-4954-8827-6e9e09cea9b7} + Clienttest + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + true + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + \ No newline at end of file diff --git a/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj.filters b/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj.filters new file mode 100644 index 0000000..54f0bf7 --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj.filters @@ -0,0 +1,30 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + + + Header Files + + + \ No newline at end of file diff --git a/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj.user b/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/Client_test.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Client_test_Console/Client_test_vs/Client_test/main.cpp b/Client_test_Console/Client_test_vs/Client_test/main.cpp new file mode 100644 index 0000000..1647077 --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/main.cpp @@ -0,0 +1,20 @@ +// Client_test.cpp : This file contains the 'main' function. Program execution begins and ends there. +// + +#include + +int main() +{ + std::cout << "Hello World!\n"; +} + +// Run program: Ctrl + F5 or Debug > Start Without Debugging menu +// Debug program: F5 or Debug > Start Debugging menu + +// Tips for Getting Started: +// 1. Use the Solution Explorer window to add/manage files +// 2. Use the Team Explorer window to connect to source control +// 3. Use the Output window to see build output and other messages +// 4. Use the Error List window to view errors +// 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project +// 6. In the future, to open this project again, go to File > Open > Project and select the .sln file diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.exe.recipe b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.exe.recipe new file mode 100644 index 0000000..eb69620 --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.exe.recipe @@ -0,0 +1,11 @@ + + + + + C:\Users\Jafari Chen\Desktop\ChatWare\Client_test_Console\Client_test_vs\x64\Debug\Client_test.exe + + + + + + \ No newline at end of file diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.ilk b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.ilk new file mode 100644 index 0000000..0977d3b Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.ilk differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.log b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.log new file mode 100644 index 0000000..60cc420 --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.log @@ -0,0 +1,2 @@ + main.cpp + Client_test.vcxproj -> C:\Users\Jafari Chen\Desktop\ChatWare\Client_test_Console\Client_test_vs\x64\Debug\Client_test.exe diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.command.1.tlog b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.command.1.tlog new file mode 100644 index 0000000..21e9306 Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.command.1.tlog differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.read.1.tlog b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.read.1.tlog new file mode 100644 index 0000000..51a1bed Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.read.1.tlog differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.write.1.tlog b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.write.1.tlog new file mode 100644 index 0000000..cf8adb8 Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/CL.write.1.tlog differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/Client_test.lastbuildstate b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/Client_test.lastbuildstate new file mode 100644 index 0000000..e23e00b --- /dev/null +++ b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/Client_test.lastbuildstate @@ -0,0 +1,2 @@ +PlatformToolSet=v143:VCToolArchitecture=Native64Bit:VCToolsVersion=14.32.31326:TargetPlatformVersion=10.0.19041.0: +Debug|x64|C:\Users\Jafari Chen\Desktop\ChatWare\Client_test_Console\Client_test_vs\| diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.command.1.tlog b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.command.1.tlog new file mode 100644 index 0000000..85e3e76 Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.command.1.tlog differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.read.1.tlog b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.read.1.tlog new file mode 100644 index 0000000..00b122b Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.read.1.tlog differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.write.1.tlog b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.write.1.tlog new file mode 100644 index 0000000..aed910f Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/Client_test.tlog/link.write.1.tlog differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/main.obj b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/main.obj new file mode 100644 index 0000000..cee88d5 Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/main.obj differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/vc143.idb b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/vc143.idb new file mode 100644 index 0000000..6998b50 Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/vc143.idb differ diff --git a/Client_test_Console/Client_test_vs/Client_test/x64/Debug/vc143.pdb b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/vc143.pdb new file mode 100644 index 0000000..5aa8e3a Binary files /dev/null and b/Client_test_Console/Client_test_vs/Client_test/x64/Debug/vc143.pdb differ diff --git a/Client_test_Console/Client_test_vs/x64/Debug/Client_test.exe b/Client_test_Console/Client_test_vs/x64/Debug/Client_test.exe new file mode 100644 index 0000000..fd5e50c Binary files /dev/null and b/Client_test_Console/Client_test_vs/x64/Debug/Client_test.exe differ diff --git a/Client_test_Console/Client_test_vs/x64/Debug/Client_test.pdb b/Client_test_Console/Client_test_vs/x64/Debug/Client_test.pdb new file mode 100644 index 0000000..7250064 Binary files /dev/null and b/Client_test_Console/Client_test_vs/x64/Debug/Client_test.pdb differ diff --git a/Client_test_Console/qt/CMakeLists.txt b/Client_test_Console/qt/CMakeLists.txt new file mode 100644 index 0000000..71761bd --- /dev/null +++ b/Client_test_Console/qt/CMakeLists.txt @@ -0,0 +1,27 @@ +cmake_minimum_required(VERSION 3.14) + +project(Client_Test LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOUIC ON) +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) + +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED) +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) + +set(PROJECT_SOURCES + main.cpp + chatwaresocket.h + chatwaresocket.cpp +) + +add_executable(Client_Test + main.cpp +) + +target_link_libraries(Client_Test Qt${QT_VERSION_MAJOR}::Core) diff --git a/Client_test_Console/qt/CMakeLists.txt.user b/Client_test_Console/qt/CMakeLists.txt.user new file mode 100644 index 0000000..fd8fadf --- /dev/null +++ b/Client_test_Console/qt/CMakeLists.txt.user @@ -0,0 +1,755 @@ + + + + + + EnvironmentId + {1d41e3d4-7c21-43ed-8d33-3717b0e324b3} + + + ProjectExplorer.Project.ActiveTarget + 1 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + -fno-delayed-template-parsing + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 8 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop (x86-windows-msvc2022-pe-64bit) + Desktop (x86-windows-msvc2022-pe-64bit) + {76d26a33-aea9-4cc5-8c15-5177ac61f114} + 0 + 0 + 0 + + Debug + -GNinja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + C:\Users\Jafari Chen\Desktop\build-Client_Test-Desktop_x86_windows_msvc2022_pe_64bit-Debug + + + + all + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + -GNinja +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + C:\Users\Jafari Chen\Desktop\build-Client_Test-Desktop_x86_windows_msvc2022_pe_64bit-Release + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + -GNinja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + C:\Users\Jafari Chen\Desktop\build-Client_Test-Desktop_x86_windows_msvc2022_pe_64bit-RelWithDebInfo + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + -GNinja +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + C:\Users\Jafari Chen\Desktop\build-Client_Test-Desktop_x86_windows_msvc2022_pe_64bit-MinSizeRel + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Client_Test + CMakeProjectManager.CMakeRunConfiguration.Client_Test + Client_Test + false + true + true + false + true + C:/Users/Jafari Chen/Desktop/build-Client_Test-Desktop_x86_windows_msvc2022_pe_64bit-Debug + + 1 + + + + ProjectExplorer.Project.Target.1 + + Desktop + Desktop Qt 6.2.2 MSVC2019 64bit + Desktop Qt 6.2.2 MSVC2019 64bit + qt.qt6.622.win64_msvc2019_64_kit + 0 + 0 + 0 + + Debug + -GNinja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + C:\Users\Jafari Chen\Desktop\build-Client_Test-Desktop_Qt_6_2_2_MSVC2019_64bit-Debug + + + + all + + true + Build + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + Build + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + -GNinja +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + C:\Users\Jafari Chen\Desktop\build-Client_Test-Desktop_Qt_6_2_2_MSVC2019_64bit-Release + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + -GNinja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + C:\Users\Jafari Chen\Desktop\build-Client_Test-Desktop_Qt_6_2_2_MSVC2019_64bit-RelWithDebInfo + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + -GNinja +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} + C:\Users\Jafari Chen\Desktop\build-Client_Test-Desktop_Qt_6_2_2_MSVC2019_64bit-MinSizeRel + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Client_Test + CMakeProjectManager.CMakeRunConfiguration.Client_Test + Client_Test + false + true + true + false + true + C:/Users/Jafari Chen/Desktop/build-Client_Test-Desktop_Qt_6_2_2_MSVC2019_64bit-Debug + + 1 + + + + ProjectExplorer.Project.Target.2 + + WebAssemblyDeviceType + Qt 6.2.2 WebAssembly + Qt 6.2.2 WebAssembly + qt.qt6.622.wasm_32_kit + 0 + -1 + 0 + + Debug + -GNinja +-DCMAKE_BUILD_TYPE:STRING=Debug +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:PATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake + C:\Users\Jafari Chen\Desktop\build-Client_Test-Qt_6_2_2_WebAssembly-Debug + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + CMakeProjectManager.CMakeBuildConfiguration + + + Release + -GNinja +-DCMAKE_BUILD_TYPE:STRING=Release +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:PATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake + C:\Users\Jafari Chen\Desktop\build-Client_Test-Qt_6_2_2_WebAssembly-Release + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + CMakeProjectManager.CMakeBuildConfiguration + + + RelWithDebInfo + -GNinja +-DCMAKE_BUILD_TYPE:STRING=RelWithDebInfo +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:PATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake + C:\Users\Jafari Chen\Desktop\build-Client_Test-Qt_6_2_2_WebAssembly-RelWithDebInfo + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release with Debug Information + CMakeProjectManager.CMakeBuildConfiguration + + + MinSizeRel + -GNinja +-DCMAKE_BUILD_TYPE:STRING=MinSizeRel +-DCMAKE_PROJECT_INCLUDE_BEFORE:PATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake +-DQT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable} +-DCMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX} +-DCMAKE_C_COMPILER:STRING=%{Compiler:Executable:C} +-DCMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx} +-DCMAKE_TOOLCHAIN_FILE:PATH=%{Qt:QT_INSTALL_PREFIX}/lib/cmake/Qt6/qt.toolchain.cmake + C:\Users\Jafari Chen\Desktop\build-Client_Test-Qt_6_2_2_WebAssembly-MinSizeRel + + + + all + + true + CMakeProjectManager.MakeStep + + 1 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + + clean + + true + CMakeProjectManager.MakeStep + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Minimum Size Release + CMakeProjectManager.CMakeBuildConfiguration + + 4 + 0 + + true + true + true + + Launch with emrun + WebAssembly.RunConfiguration.Emrun + + false + true + false + true + + + 1 + + + + ProjectExplorer.Project.TargetCount + 3 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/Client_test_Console/qt/chatwaresocket.cpp b/Client_test_Console/qt/chatwaresocket.cpp new file mode 100644 index 0000000..8f3db97 --- /dev/null +++ b/Client_test_Console/qt/chatwaresocket.cpp @@ -0,0 +1,6 @@ +#include "chatwaresocket.h" + +ChatWareSocket::ChatWareSocket() +{ + +} diff --git a/Client_test_Console/qt/chatwaresocket.h b/Client_test_Console/qt/chatwaresocket.h new file mode 100644 index 0000000..a0b9ddb --- /dev/null +++ b/Client_test_Console/qt/chatwaresocket.h @@ -0,0 +1,11 @@ +#ifndef CHATWARESOCKET_H +#define CHATWARESOCKET_H + + +class ChatWareSocket +{ +public: + ChatWareSocket(); +}; + +#endif // CHATWARESOCKET_H diff --git a/Client_test_Console/qt/main.cpp b/Client_test_Console/qt/main.cpp new file mode 100644 index 0000000..470a030 --- /dev/null +++ b/Client_test_Console/qt/main.cpp @@ -0,0 +1,8 @@ +#include + +int main(int argc, char *argv[]) +{ + QCoreApplication a(argc, argv); + + return a.exec(); +} diff --git a/README.md b/README.md index ece0ca3..e2a0190 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# SealedLips -A end-to-end encrypted IM app that provides ultimate secrecy +# ChatWare +This a repository for an online chat project diff --git a/client-qt/Session.cpp b/client-qt/Session.cpp new file mode 100644 index 0000000..d0d08e0 --- /dev/null +++ b/client-qt/Session.cpp @@ -0,0 +1,119 @@ +#include "Session.h" +#include +Session::Session(QTcpSocket* socket) +{ + m_socket = socket; + m_type = RECV_HEAD; + m_head = NULL; + m_bufLen = 0; + m_readPos = 0; + m_body = NULL; + m_isFinish = false; + m_head = new char[sizeof(DeMessageHead)]; + m_bufLen = sizeof(DeMessageHead); +} + +Session::~Session(){ + if (m_head != NULL) + delete[] m_head; + if (m_body != NULL) + delete[] m_body; + if (m_socket != NULL){ + m_socket->close(); + m_socket = NULL; + } +}; + +int Session::readEvent() +{ + int ret = 0; + switch (m_type) + { + case RECV_HEAD: + ret = recvHead(); + break; + case RECV_BODY: + ret = recvBody(); + break; + default: + break; + } + if (ret == RET_AGAIN) + return readEvent(); + return ret; +} + +int Session::recvHead() +{ + if (m_head == NULL) + { + m_head = new char[sizeof(DeMessageHead)]; + assert(m_head != NULL); + m_bufLen = sizeof(DeMessageHead); + m_readPos = 0; + } + int len = m_socket->read(m_head + m_readPos, m_bufLen - m_readPos); + if (len < 0) + return RET_ERROR; + if (len == 0) + return RET_END; + m_readPos += len; + if (m_readPos == m_bufLen) + { + m_type = RECV_BODY; + int bufLen = ((DeMessageHead *)m_head)->length; + m_body = new char[bufLen]; + + assert(m_body != NULL); + m_bufLen = bufLen; + m_readPos = 0; //读取的位置置零 + return RET_AGAIN; + } + return 0; +} + +int Session::recvBody() +{ + /* 先判断读取的位置是否是 ((DeMessageHead*)m_head)->length 接收头指定的长度 */ + if (m_readPos == m_bufLen) + { + m_type = RECV_HEAD; + handleMsgBase(); + m_isFinish = true; + return RET_AGAIN; + } + /* 读取指定 Body 大小的数据 */ + int len = m_socket->read(m_body + m_readPos, m_bufLen - m_readPos); + + if (len < 0) + return RET_ERROR; + + m_readPos += len; + + /* 判断读取的位置是否是 ((DeMessageHead*)m_head)->length 接收头指定的长度 */ + if (m_readPos == m_bufLen) + { + m_type = RECV_HEAD; + handleMsgBase(); + m_bufLen = 0; + m_isFinish = true; + return RET_AGAIN; + } + return RET_OK; +} + +int Session::handleMsgBase(){ + recvMsg *rMsg = new recvMsg(); + rMsg->head = m_head; + rMsg->body = m_body; + rMsg->bodyLen = m_bufLen; + emit signal_handleMsg(rMsg); +// handleMsg(rMsg); + m_head = NULL; + m_body = NULL; + return RET_OK; +} + +void Session::cleanSession(){ + +} diff --git a/client-qt/Session.h b/client-qt/Session.h new file mode 100644 index 0000000..ecbd446 --- /dev/null +++ b/client-qt/Session.h @@ -0,0 +1,77 @@ +#ifndef SESSION_H +#define SESSION_H +#include "common.h" +#include +#include +#include + +//用于保存收到的MA的消息 +typedef struct _recvMsg +{ + _recvMsg() + { + head = NULL; + body = NULL; + bodyLen = 0; + } + ~_recvMsg() + { + if (head != NULL) + { + delete[] head; + head = NULL; + } + + if (body != NULL) + { + delete[] body; + body = NULL; + } + } + char *head; + char *body; + int bodyLen; +}recvMsg; + +typedef enum +{ + RECV_HEAD = 0, + RECV_BODY +}recvType; + + +class Session:public QObject +{ + Q_OBJECT +public: + Session(QTcpSocket* socket); + ~Session(); +public: + int readEvent(); + int recvHead(); + int recvBody(); + int handleMsgBase(); +// int handleMsg(recvMsg *rMsg); +// static void sendMsg(QTcpSocket* socket,void*buf,int bufLen,int type,int error=0); +signals: + void signal_handleMsg(recvMsg *rMsg); +public: +// static int handleRegiste(void*arg,void*msg); +// static int handleLogin(void*arg,void*msg); +// static int handleLogout(void*arg,void*msg); +// static int handleGroupChat(void*arg,void*msg); +// int getGroupList(void*msg); +// int getGroupInfo(void* msg); +private: + void cleanSession(); +private: + QTcpSocket* m_socket; + recvType m_type; //接收消息类型 + char *m_head; //接收到的头信息 + int m_bufLen; //需要接收消息的长度 + int m_readPos; //当前读取到的长度 + char *m_body; //接收到的body + bool m_isFinish; //接收消息,用来判断是否接收完全 +}; + +#endif // SESSION_H diff --git a/client-qt/addfrienddialog.cpp b/client-qt/addfrienddialog.cpp new file mode 100644 index 0000000..3a59045 --- /dev/null +++ b/client-qt/addfrienddialog.cpp @@ -0,0 +1,49 @@ +#include "addfrienddialog.h" +#include "ui_addfrienddialog.h" + +AddFriendDialog::AddFriendDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::AddFriendDialog) +{ + ui->setupUi(this); + this->setWindowTitle("WeChat 查找"); + ui->widget_friendInfo->hide(); + setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint); // 最小化按钮 + setWindowFlags(windowFlags() | Qt::WindowContextHelpButtonHint); // 帮助按钮 +} + +AddFriendDialog::~AddFriendDialog() +{ + delete ui; +} + +void AddFriendDialog::on_pushButton_find_clicked() +{ + ChatLogInfo()<<"on_pushButton_find_clicked in.."; + int account = ui->lineEdit_account->text().toInt(); + /** + * @brief 因为要维护一个大群(群号为0),所有用户在线都在里面,查找好友暂定在大群里面查找 + * 后期为了应对高并发会从服务器获取好友信息 + */ + GroupUserInfo* userInfo; + userInfo = ChatInfoManage::getInstance()->getUserInfo(account); + if(userInfo!= NULL){ + ui->widget_friendInfo->show(); + //找到该用户,显示用户信息 + m_addFriendInfoReq.m_friendAccount = userInfo->m_account; //保存账号 + m_addFriendInfoReq.m_senderAccount = -1; + ui->lineEdit_friendName->setText(QString(userInfo->m_userName)); + ui->lineEdit_friend_account->setText(QString::number(userInfo->m_account)); + } + else { + ui->widget_friendInfo->hide(); + } + ChatLogInfo()<<"on_pushButton_find_clicked out.."; +} + +void AddFriendDialog::on_pushButton_addFriend_clicked() +{ + memset(m_addFriendInfoReq.m_reqInfo,'\0',sizeof(m_addFriendInfoReq.m_reqInfo)); + strncpy(m_addFriendInfoReq.m_reqInfo,ui->textEdit_reqInfo->toPlainText().toStdString().c_str(),ui->textEdit_reqInfo->toPlainText().toStdString().size()); + return accept(); //Closes the dialog and emits the accepted() signal. +} diff --git a/client-qt/addfrienddialog.h b/client-qt/addfrienddialog.h new file mode 100644 index 0000000..86a66fa --- /dev/null +++ b/client-qt/addfrienddialog.h @@ -0,0 +1,34 @@ +#ifndef ADDFRIENDDIALOG_H +#define ADDFRIENDDIALOG_H + +#include "common.h" +#include "widget.h" +#include + +namespace Ui { +class AddFriendDialog; +} + +class AddFriendDialog : public QDialog +{ + Q_OBJECT + +public: + explicit AddFriendDialog(QWidget *parent = nullptr); + ~AddFriendDialog(); +public: + AddFriendInfoReq getAddFriendInfoReq(){ + return m_addFriendInfoReq; + } +private slots: + void on_pushButton_find_clicked(); + + void on_pushButton_addFriend_clicked(); +signals: + void signal_findUserInfo(int account); +private: + Ui::AddFriendDialog *ui; + AddFriendInfoReq m_addFriendInfoReq; +}; + +#endif // ADDFRIENDDIALOG_H diff --git a/client-qt/addfrienddialog.ui b/client-qt/addfrienddialog.ui new file mode 100644 index 0000000..b12dc12 --- /dev/null +++ b/client-qt/addfrienddialog.ui @@ -0,0 +1,190 @@ + + + AddFriendDialog + + + + 0 + 0 + 444 + 486 + + + + Dialog + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + 添加好友 + + + + + 20 + 90 + 361 + 341 + + + + + + 270 + 290 + 75 + 23 + + + + QPushButton{ + background-color: rgb(80, 156, 255); + + color: rgb(255, 255, 255); + border-style: solid; + border-radius: 5px; + +} + +QPushButton:hover{ + background-color: rgb(56,205,127); +} + +QPushButton:pressed { + background-color: rgb(7,193,96); +} + + + 添加好友 + + + + + + 20 + 20 + 331 + 264 + + + + + + + + + 昵称: + + + + + + + + + + + + + + 账号: + + + + + + + + + + + + + + 验证信息: + + + + + + + + + + + + + + + 40 + 30 + 311 + 31 + + + + + + + 账号: + + + + + + + + + + QPushButton{ + background-color: rgb(80, 156, 255); + + color: rgb(255, 255, 255); + border-style: solid; + border-radius: 5px; + +} + +QPushButton:hover{ + background-color: rgb(56,205,127); +} + +QPushButton:pressed { + background-color: rgb(7,193,96); +} + + + 查找 + + + + + + + + + + + + + diff --git a/client-qt/aesdecrypt.cpp b/client-qt/aesdecrypt.cpp new file mode 100644 index 0000000..a98ac4f --- /dev/null +++ b/client-qt/aesdecrypt.cpp @@ -0,0 +1,96 @@ +#if 0 + +#include + +#include +#include +#include + + +#include +#include + +using namespace std; + +byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE]; + +void initKV() +{ + memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH ); + memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE ); + + // 或者也可以 + /* + char tmpK[] = "1234567890123456"; + char tmpIV[] = "1234567890123456"; + for (int j = 0; j < CryptoPP::AES::DEFAULT_KEYLENGTH; ++j) + { + key[j] = tmpK[j]; + } + + for (int i = 0; i < CryptoPP::AES::BLOCKSIZE; ++i) + { + iv[i] = tmpIV[i]; + } + */ +} + +string decrypt(string cipherTextHex) +{ + string cipherText; + string decryptedText; + + int i = 0; + while(true) + { + char c; + int x; + stringstream ss; + ss<>x; + c = (char)x; + cipherText += c; + if(i >= cipherTextHex.length() - 2)break; + i += 2; + } + + // + CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH); + CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv ); + CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink( decryptedText )); + stfDecryptor.Put( reinterpret_cast( cipherText.c_str() ), cipherText.size()); + + stfDecryptor.MessageEnd(); + + return decryptedText; +} + +string readCipher() +{ + ifstream in("/tmp/cipher.data"); + + string line; + string decryptedText; + while(getline(in, line)) + { + if(line.length() > 1) + { + decryptedText += decrypt(line) + "\n"; + } + line.clear(); + } + + cout<<"readCipher finish "< + +#include +#include +#include + +#include +#include +#include + +using namespace std; + +byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE]; + +void initKV() +{ + memset( key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH ); + memset( iv, 0x00, CryptoPP::AES::BLOCKSIZE ); + + // 或者也可以 + /* + char tmpK[] = "1234567890123456"; + char tmpIV[] = "1234567890123456"; + for (int j = 0; j < CryptoPP::AES::DEFAULT_KEYLENGTH; ++j) + { + key[j] = tmpK[j]; + } + for (int i = 0; i < CryptoPP::AES::BLOCKSIZE; ++i) + { + iv[i] = tmpIV[i]; + } + */ +} + +string encrypt(string plainText) +{ + string cipherText; + + // + CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH); + CryptoPP::CBC_Mode_ExternalCipher::Encryption cbcEncryption( aesEncryption, iv ); + CryptoPP::StreamTransformationFilter stfEncryptor(cbcEncryption, new CryptoPP::StringSink( cipherText )); + stfEncryptor.Put( reinterpret_cast( plainText.c_str() ), plainText.length() + 1 ); + stfEncryptor.MessageEnd(); + + string cipherTextHex; + for( int i = 0; i < cipherText.size(); i++ ) + { + char ch[3] = {0}; + sprintf(ch, "%02x", static_cast(cipherText[i])); + cipherTextHex += ch; + } + + return cipherTextHex; +} + + + +void writeCipher(string output) +{ + ofstream out("/tmp/cipher.data"); + out.write(output.c_str(), output.length()); + out.close(); + + cout<<"writeCipher finish "< + + + + + EnvironmentId + {8d58143c-3cf3-4699-bc9b-6c3c945066cd} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 2 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.12.2 MinGW 64-bit + Desktop Qt 5.12.2 MinGW 64-bit + qt.qt5.5122.win64_mingw73_kit + 0 + 0 + 0 + + C:/Users/Lenovo/Desktop/chat_room-master/build-chat_room_client-Desktop_Qt_5_12_2_MinGW_64_bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/Lenovo/Desktop/chat_room-master/build-chat_room_client-Desktop_Qt_5_12_2_MinGW_64_bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/Lenovo/Desktop/chat_room-master/build-chat_room_client-Desktop_Qt_5_12_2_MinGW_64_bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + chat_room_client + chat_room_client2 + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Lenovo/Desktop/client-qt/chat_room_client.pro + chat_room_client.pro + + 3768 + false + true + true + false + false + true + + C:/Users/Lenovo/Desktop/chat_room-master/build-chat_room_client-Desktop_Qt_5_12_2_MinGW_64_bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 20 + + + Version + 20 + + diff --git a/client-qt/chat_room_client.pro.user.34b048d.22 b/client-qt/chat_room_client.pro.user.34b048d.22 new file mode 100644 index 0000000..9cbbb8a --- /dev/null +++ b/client-qt/chat_room_client.pro.user.34b048d.22 @@ -0,0 +1,267 @@ + + + + + + EnvironmentId + {34b048d5-4225-4036-8632-05e3e289a8a5} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + -fno-delayed-template-parsing + + true + Builtin.BuildSystem + + true + true + Builtin.DefaultTidyAndClazy + 4 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 5.15.2 MinGW 64-bit + Desktop Qt 5.15.2 MinGW 64-bit + qt.qt5.5152.win64_mingw81_kit + 1 + 0 + 0 + + 0 + C:\Users\wsy\Desktop\chat\build-chat_room_client-Desktop_Qt_5_15_2_MinGW_64_bit-Debug + C:/Users/wsy/Desktop/chat/build-chat_room_client-Desktop_Qt_5_15_2_MinGW_64_bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + C:\Users\wsy\Desktop\chat\build-chat_room_client-Desktop_Qt_5_15_2_MinGW_64_bit-Release + C:/Users/wsy/Desktop/chat/build-chat_room_client-Desktop_Qt_5_15_2_MinGW_64_bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + C:\Users\wsy\Desktop\chat\build-chat_room_client-Desktop_Qt_5_15_2_MinGW_64_bit-Profile + C:/Users/wsy/Desktop/chat/build-chat_room_client-Desktop_Qt_5_15_2_MinGW_64_bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + Build + Build + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + Clean + Clean + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + Deploy + Deploy + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/wsy/Desktop/chat/client-qt/chat_room_client.pro + C:/Users/wsy/Desktop/chat/client-qt/chat_room_client.pro + false + true + true + false + true + C:/Users/wsy/Desktop/chat/build-chat_room_client-Desktop_Qt_5_15_2_MinGW_64_bit-Release + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/client-qt/chat_room_client.pro.user.605aaa8.22 b/client-qt/chat_room_client.pro.user.605aaa8.22 new file mode 100644 index 0000000..c3266ae --- /dev/null +++ b/client-qt/chat_room_client.pro.user.605aaa8.22 @@ -0,0 +1,263 @@ + + + + + + EnvironmentId + {605aaa82-b623-4a6f-9ab0-0f749bc8e8e8} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + false + true + false + 0 + true + true + 0 + 8 + true + false + 1 + true + true + true + *.md, *.MD, Makefile + false + true + true + + + + ProjectExplorer.Project.PluginSettings + + + true + false + true + true + true + true + + + 0 + true + + true + true + Builtin.DefaultTidyAndClazy + 2 + + + + true + + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop Qt 6.4.3 GCC 64bit + Desktop Qt 6.4.3 GCC 64bit + qt.qt6.643.gcc_64_kit + 0 + 0 + 0 + + 0 + /home/ryan/1code/chat_room-master/build-chat_room_client-Desktop_Qt_6_4_3_GCC_64bit-Debug + /home/ryan/1code/chat_room-master/build-chat_room_client-Desktop_Qt_6_4_3_GCC_64bit-Debug + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + + + /home/ryan/1code/chat_room-master/build-chat_room_client-Desktop_Qt_6_4_3_GCC_64bit-Release + /home/ryan/1code/chat_room-master/build-chat_room_client-Desktop_Qt_6_4_3_GCC_64bit-Release + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + + + 0 + /home/ryan/1code/chat_room-master/build-chat_room_client-Desktop_Qt_6_4_3_GCC_64bit-Profile + /home/ryan/1code/chat_room-master/build-chat_room_client-Desktop_Qt_6_4_3_GCC_64bit-Profile + + + true + QtProjectManager.QMakeBuildStep + false + + + + true + Qt4ProjectManager.MakeStep + + 2 + 构建 + 构建 + ProjectExplorer.BuildSteps.Build + + + + true + Qt4ProjectManager.MakeStep + clean + + 1 + 清除 + 清除 + ProjectExplorer.BuildSteps.Clean + + 2 + false + + false + + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + 0 + 0 + + 3 + + + 0 + 部署 + 部署 + ProjectExplorer.BuildSteps.Deploy + + 1 + + false + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + true + + 2 + + Qt4ProjectManager.Qt4RunConfiguration:/home/ryan/1code/chat_room-master/client-qt/chat_room_client.pro + /home/ryan/1code/chat_room-master/client-qt/chat_room_client.pro + false + true + true + false + true + /home/ryan/1code/chat_room-master/build-chat_room_client-Desktop_Qt_6_4_3_GCC_64bit-Debug + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 22 + + + Version + 22 + + diff --git a/client-qt/chat_room_client.pro.user.8d58143.4.9-pre1 b/client-qt/chat_room_client.pro.user.8d58143.4.9-pre1 new file mode 100644 index 0000000..d5dc83f --- /dev/null +++ b/client-qt/chat_room_client.pro.user.8d58143.4.9-pre1 @@ -0,0 +1,328 @@ + + + + + + EnvironmentId + {8d58143c-3cf3-4699-bc9b-6c3c945066cd} + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + 80 + true + true + 1 + true + false + 0 + true + true + 0 + 8 + true + 2 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + -fno-delayed-template-parsing + + true + + + + ProjectExplorer.Project.Target.0 + + Desktop Qt 5.12.2 MinGW 64-bit + Desktop Qt 5.12.2 MinGW 64-bit + qt.qt5.5122.win64_mingw73_kit + 0 + 0 + 0 + + C:/Users/Lenovo/Desktop/chat_room-master/build-chat_room_client-Desktop_Qt_5_12_2_MinGW_64_bit-Debug + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + false + false + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + Debug + Qt4ProjectManager.Qt4BuildConfiguration + 2 + true + + + C:/Users/Lenovo/Desktop/chat_room-master/build-chat_room_client-Desktop_Qt_5_12_2_MinGW_64_bit-Release + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + + false + false + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + Release + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + + C:/Users/Lenovo/Desktop/chat_room-master/build-chat_room_client-Desktop_Qt_5_12_2_MinGW_64_bit-Profile + + + true + qmake + + QtProjectManager.QMakeBuildStep + true + + false + true + true + + + true + Make + + Qt4ProjectManager.MakeStep + + false + + + false + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + true + clean + + false + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Profile + Profile + Qt4ProjectManager.Qt4BuildConfiguration + 0 + true + + 3 + + + 0 + 部署 + + ProjectExplorer.BuildSteps.Deploy + + 1 + Deploy Configuration + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + + false + false + 1000 + + true + + false + false + false + false + true + 0.01 + 10 + true + 1 + 25 + + 1 + true + false + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + 2 + + chat_room_client + + Qt4ProjectManager.Qt4RunConfiguration:C:/Users/Lenovo/Desktop/chat_room-master/client-qt/chat_room_client.pro + chat_room_client.pro + + 3768 + false + true + true + false + false + true + + + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.FileVersion + 20 + + + Version + 20 + + diff --git a/client-qt/chatinfomanage.cpp b/client-qt/chatinfomanage.cpp new file mode 100644 index 0000000..cbbeaa4 --- /dev/null +++ b/client-qt/chatinfomanage.cpp @@ -0,0 +1,112 @@ +#include "chatinfomanage.h" + +ChatInfoManage* ChatInfoManage::m_pInstance = m_pInstance; + +ChatInfoManage::ChatInfoManage() +{ + +} + +GroupUserInfo *ChatInfoManage::getUserInfo(int account) +{ + GroupUserInfo* userInfo =NULL; + mapGroupInfo::iterator iter = g_GroupUserInfoMap.find(0); + if(iter!=g_GroupUserInfoMap.end()){ + mapGroupUserInfo::iterator ite = iter->second.find(account); + ChatLogInfo()<<"### size:"<second.size(); + if(ite!=iter->second.end()){ + userInfo = ite->second; + ChatLogInfo()<< "account:" << userInfo->m_account <<",username:" << QString(userInfo->m_userName); + return userInfo; + } + else{ + ChatLogInfo()<<"find UserInfo fail.."; + } + } + else { + ChatLogInfo()<<"not find group 0.."; + } + return userInfo; +} + +int ChatInfoManage::addGroupChatInfo(GroupChatInfo *pGroupChatInfo) +{ + std::pair InsertPair = g_GroupCharInfoMap.insert(std::make_pair(pGroupChatInfo->m_account,pGroupChatInfo)); + if(InsertPair.second == true) + return 0; + return -1; +} + +GroupChatInfo *ChatInfoManage::getGroupChatInfo(int groupAccount) +{ + GroupChatInfo* groupChatInfo = NULL; + mapGroupChatInfo::iterator iter = g_GroupCharInfoMap.find(groupAccount); + if(iter!=g_GroupCharInfoMap.end()){ + groupChatInfo = iter->second; + } + else { + ChatLogInfo()<<"not find chatgroup indo"; + return NULL; + } + return groupChatInfo; +} + +int ChatInfoManage::addGroupUserInfo(int groupAccount, GroupUserInfo *groupUserInfo) +{ + //将群用户信息添加到群里面 + mapGroupInfo::iterator iter = g_GroupUserInfoMap.find(groupAccount); + if(iter != g_GroupUserInfoMap.end()){ + std::pair InsertPair = iter->second.insert(std::make_pair(groupUserInfo->m_account,groupUserInfo)); + if(InsertPair.second == true) + return 0; + else { + ChatLogInfo()<<"insert groupAccount:"< insertPair = groupUserInfoMap.insert(std::make_pair(groupUserInfo->m_account,groupUserInfo)); + if(insertPair.second != true) + return -1; + std::pair InsertPair = g_GroupUserInfoMap.insert(std::make_pair(groupAccount,groupUserInfoMap)); + if(InsertPair.second == true) + return 0; + } + return -1; +} + +GroupUserInfo *ChatInfoManage::getGroupUserInfo(int groupAccount, int userAccount) +{ + GroupUserInfo* groupUserInfo =NULL; + mapGroupInfo::iterator iter = g_GroupUserInfoMap.find(groupAccount); + if(iter!=g_GroupUserInfoMap.end()){ + mapGroupUserInfo::iterator ite = iter->second.find(userAccount); + if(ite!=iter->second.end()){ + groupUserInfo = ite->second; + } + } + return groupUserInfo; +} + +int ChatInfoManage::addFriendInfo(FriendInfo *friendInfo) +{ + std::pair InsertPair = m_FriendInfoMap.insert(std::make_pair(friendInfo->m_account,friendInfo)); + if(InsertPair.second == true) + return 0; + return -1; +} + +FriendInfo *ChatInfoManage::getFriendInfo(int account) +{ + FriendInfo* friendInfo = NULL; + mapFriendInfo::iterator iter = m_FriendInfoMap.find(account); + if(iter!=m_FriendInfoMap.end()){ + friendInfo = iter->second; + } + else { + ChatLogInfo()<<"not find chatgroup indo"; + return NULL; + } + return friendInfo; +} diff --git a/client-qt/chatinfomanage.h b/client-qt/chatinfomanage.h new file mode 100644 index 0000000..3fd0088 --- /dev/null +++ b/client-qt/chatinfomanage.h @@ -0,0 +1,148 @@ +#ifndef CHATINFOMANAGE_H +#define CHATINFOMANAGE_H +#include "common.h" +#include +#include + +struct RegistInfoReq{ + char m_userName[32]; + char m_password[32]; +}; + +struct BaseInfo{ + int sessionId; //会话ID + char name[32]; //名称 + int socket; +}; + +/* 用来传递给 Login 界面的数据 */ +struct UserInfo{ + char m_userName[32]; + char m_password[32]; + int m_account; +}; + +struct RegistInfoResp{ + int m_account; +}; + +struct LoginInfoReq{ + int m_account; + char m_password[32]; +}; + +struct GroupChatInfo +{ + char m_groupName[32]; //群名称 + int m_account; //群账号 + int m_size; //群大小 +}; + +struct GetGroupListResp +{ + int m_size; //群数量大小 +}; + +struct GroupChatReq +{ + int m_UserAccount; //发送方 + int m_msgLen; + int m_type; //数据类型 0:文本,1:图片 ... + int m_GroupAccount; //发送群号 0:广播 +}; + +struct PrivateChatReq +{ + int m_UserAccount; //发送的账号 + int m_msgLen; + int m_type; //数据类型 0:文本,1:图片 ... + int m_FriendAccount; //发送好友账号 +}; + +struct GetGroupInfoReq +{ + int m_Group; //群号 0:广播 +}; + +struct GetGroupInfoResp +{ + char m_groupName[32]; //群名称 + int m_GroupAccount; //群号 0:广播 + int m_size; //群成员大小 +}; + +struct GroupUserInfo{ + char m_userName[32]; + int m_account; //账号 + int m_right; //权限 0:群成员 1:群管 2:群主 +}; + +/* 好友请求接口封装 */ +struct GetFriendInfoResp +{ + int m_size; //好友大小 +}; + +struct AddFriendInfoReq +{ + int m_friendAccount; //好友账号 + int m_senderAccount; //发送端账号 + char m_reqInfo[64]; //请求信息 例如我是xxx +}; + +struct AddFriendInfoResp +{ + int m_friendAccount; //好友账号 + int m_senderAccount; //发送端账号 + int status; //同意0,不同意-1 +}; + +struct FriendInfo{ + char m_userName[32];//好友用户名 + int m_account; //账号 + int m_status; //是否添加成功 0:等待添加 1:同意 +}; + +//好友信息表,属于Session会话对象,即每个客户端一个好友信息表 +typedef std::map mapFriendInfo; //好友信息表 + +// 用户账号 + 群用户信息 +typedef std::map mapGroupUserInfo; +// 群号 + 群成员表 +typedef std::map mapGroupInfo; +// 群号 + 群聊信息 +typedef std::map mapGroupChatInfo; + +class ChatInfoManage +{ +public: + ChatInfoManage(); +public: + static ChatInfoManage* getInstance(){ + if(NULL == m_pInstance) + { + m_pInstance = new ChatInfoManage(); + } + return m_pInstance; + } +public: + //获取在线用户信息 + GroupUserInfo* getUserInfo(int account); + //群聊信息操作 + int addGroupChatInfo(GroupChatInfo* pGroupChatInfo); + GroupChatInfo* getGroupChatInfo(int groupAccount); + //群成员信息操作 + int addGroupUserInfo(int groupAccount,GroupUserInfo* groupUserInfo); + //获取群成员信息 当群为 0 的时候相当于获取在线用户信息 + GroupUserInfo* getGroupUserInfo(int groupAccount,int userAccount); + //添加好友信息 + int addFriendInfo(FriendInfo* friendInfo); + FriendInfo* getFriendInfo(int account); +private: + static ChatInfoManage* m_pInstance; + mapFriendInfo m_FriendInfoMap; //好友信息表 + /*static */mapGroupInfo g_GroupUserInfoMap; //群成员信息表 + /*static */mapGroupChatInfo g_GroupCharInfoMap; //群信息表 +}; + +#endif // CHATINFOMANAGE_H diff --git a/client-qt/common.h b/client-qt/common.h new file mode 100644 index 0000000..2b329f4 --- /dev/null +++ b/client-qt/common.h @@ -0,0 +1,135 @@ +#ifndef COMMON_H +#define COMMON_H + +#include "Session.h" +#include "chatinfomanage.h" +#include +#include +#include + +#include +#include +using namespace std; + +#define RET_OK 0 +#define RET_ERROR -1 +#define RET_AGAIN -2 //重新读取 +#define RET_EXIT -3 //客户端退出 +#define RET_END -4 //读取结束 + +#define MAX_SEND_LENGTH 6144 + +#ifndef FILENAME +#define FILENAME (__FILE__) +#endif + +#ifndef FILEFUNCTION +#define FILEFUNCTION (__FUNCTION__) +#endif + +#ifndef FILELINE +#define FILELINE (__LINE__) +#endif + +#define ChatLog qDebug().noquote()<>" format, QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss zzz").toStdString().c_str()\ + , FILENAME,FILELINE, FILEFUNCTION ,##__VA_ARGS__); \ + } +/** + * 暂时用宏定义代替,后续通过读取配置文件获取 + */ +#define SERVER_ADDR "82.157.169.88" //这是我的服务器地址,需要修改为你启动服务器的地址 +#define SERVER_PORT 8000 + +//De 协议包头 +struct DeMessageHead{ + char mark[2]; // "DE" 认证deroy的协议 + char version; + char encoded; //0 不加密,1 加密 + int length; +}; + +struct DeMessagePacket +{ + /* data */ + int mode; //1 请求,2 应答,3 消息通知 + int error; //0 成功,非0,对应的错误码 + + int sequence; //序列号 + int command; //命令号 +}; + +#define CMD_CHAT_GET(intCmd, stringCmd) \ + case intCmd: \ + return stringCmd; + +#define DA_PROTOBUFCMD_MAP(CHATCMD) \ + CHATCMD(CommandEnum_Registe, "UserRegiste") \ + CHATCMD(CommandEnum_Login, "UserLogin") \ + CHATCMD(CommandEnum_Logout, "UserLogout") \ + CHATCMD(CommandEnum_GroupChat, "GroupChat") \ + CHATCMD(CommandEnum_AddFriend, "AddFriend") \ + CHATCMD(CommandEnum_delFriend, "delFriend") \ + CHATCMD(CommandEnum_PrivateChat, "PrivateChat") \ + CHATCMD(CommandEnum_CreateGroup, "CreateGroup") \ + CHATCMD(CommandEnum_GetGroupList, "GetGroupList") \ + CHATCMD(CommandEnum_GetGroupInfo, "GetGroupInfo") \ + CHATCMD(CommandEnum_GetFriendInfo, "GetFriendInfo") \ + +enum{ + CommandEnum_Registe, + CommandEnum_Login, + CommandEnum_Logout, + CommandEnum_GroupChat, + CommandEnum_AddFriend, + CommandEnum_delFriend, + CommandEnum_PrivateChat, + CommandEnum_CreateGroup, + CommandEnum_GetGroupList, + CommandEnum_GetGroupInfo, + CommandEnum_GetFriendInfo +}; + +static const char *getChatCmdString(int cmd) +{ + switch (cmd) + { + DA_PROTOBUFCMD_MAP(CMD_CHAT_GET) + default: + return "no define cmd"; + } +} + +typedef enum Menu +{ + Exit, Registe, Login, GroupChat, PrivateChat, GroupManage, FriendManage +}MENU; + +static int getSeqNum() +{ + static int num = 0; + if (num++ >= 0xEFFFFFFF - 1) + { + num = 0; + } + return num; +} + +static int getAccountNum() +{ + static int account = 10000; + if (account++ >= 0xEFFFFFFF - 1) + { + account = 10000; + } + return account; +} + +#endif // COMMON_H diff --git a/client-qt/logindlg.cpp b/client-qt/logindlg.cpp new file mode 100644 index 0000000..50e9651 --- /dev/null +++ b/client-qt/logindlg.cpp @@ -0,0 +1,122 @@ +#include "logindlg.h" +#include "ui_logindlg.h" + +#include +#include +#include + +LoginDlg::LoginDlg(QWidget *parent) : + QDialog(parent), + ui(new Ui::LoginDlg) +{ + ui->setupUi(this); + Init(); +} + +LoginDlg::~LoginDlg() +{ + delete ui; +} + +void LoginDlg::Init() +{ + this->setWindowTitle("WeChat 登录"); + setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint); // 最小化按钮 + setWindowFlags(windowFlags() | Qt::WindowContextHelpButtonHint); // 帮助按钮 + +#if 0 + QWidget *container; + container=new QWidget(this); + container->setGeometry(5,5,width,height); + container->setStyleSheet("QWidget{border-radius:4px;background:rgba(255,255,255,1);}"); + + this->setWindowFlags(Qt::FramelessWindowHint); //去掉标题栏无边框 + this->setAttribute(Qt::WA_TranslucentBackground,true); + //实例阴影shadow + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + //设置阴影距离 + shadow->setOffset(0, 0); + //设置阴影颜色 + shadow->setColor(QColor(39,40,43,100)); + //设置阴影圆角 + shadow->setBlurRadius(10); + //给嵌套QWidget设置阴影 + container->setGraphicsEffect(shadow); +#else + int width = this->width()-10; + int height = this->height()-10; + ui->centerWidget->setGeometry(5,5,width,height); + ui->centerWidget->setStyleSheet("QWidget{border-radius:4px;background:rgba(255,255,255,1);}"); //设置圆角 + + this->setWindowFlags(Qt::FramelessWindowHint); //去掉标题栏无边框 + this->setAttribute(Qt::WA_TranslucentBackground,true); + //实例阴影shadow + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + //设置阴影距离 + shadow->setOffset(0, 0); + //设置阴影颜色 + shadow->setColor(QColor(39,40,43,100)); + //设置阴影圆角 + shadow->setBlurRadius(10); + //给嵌套QWidget设置阴影 + ui->centerWidget->setGraphicsEffect(shadow); +#endif + + + memset(&m_userInfo,'\0',sizeof(m_userInfo)); +} + +void LoginDlg::mousePressEvent(QMouseEvent *event) +{ + mouseWindowTopLeft = event->pos(); +} + +void LoginDlg::mouseMoveEvent(QMouseEvent *event) +{ + //窗口移动 + if (event->buttons() & Qt::LeftButton) + { + mouseDeskTopLeft = event->globalPos(); + windowDeskTopLeft = mouseDeskTopLeft - mouseWindowTopLeft; //矢量计算 + this->move(windowDeskTopLeft); //移动到目的地 + } +} + + + +void LoginDlg::on_pushbtn_regist_clicked() +{ + RegistDlg registDlg; + registDlg.show(); + if(registDlg.exec() == QDialog::Accepted) + { + if(registDlg.getStatus()){ + UserInfo info = registDlg.getUserInfo(); + ui->lineEdit_account->setText(QString::number(info.m_account)); + strncpy(m_userInfo.m_userName,info.m_userName,sizeof(info.m_userName)); + ChatLogInfo()<<"注册成功,账号:"<lineEdit_account->text().toInt(); + strncpy(m_userInfo.m_password,ui->lineEdit_password->text().toStdString().c_str(),ui->lineEdit_password->text().size()); + ChatLogInfo()<<"get account:"<lineEdit_password->text(); + + return accept(); //Closes the dialog and emits the accepted() signal. +} + +void LoginDlg::on_pushBtn_hide_clicked() +{ + QWidget* pWindow = this->window(); + if(pWindow->isTopLevel()) + pWindow->showMinimized(); +} + +void LoginDlg::on_pushBtn_close_clicked() +{ + this->close(); +} diff --git a/client-qt/logindlg.h b/client-qt/logindlg.h new file mode 100644 index 0000000..69dc2fe --- /dev/null +++ b/client-qt/logindlg.h @@ -0,0 +1,47 @@ +#ifndef LOGINDLG_H +#define LOGINDLG_H + +#include +#include +#include "registdlg.h" + +namespace Ui { +class LoginDlg; +} + +class LoginDlg : public QDialog +{ + Q_OBJECT + +public: + explicit LoginDlg(QWidget *parent = nullptr); + ~LoginDlg(); +public: + UserInfo* getUserInfo(){ + return &m_userInfo; + } +private: + void Init(); +protected: + // Event handlers + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event); +public: + QPoint mouseWindowTopLeft; //鼠标相对窗口左上角的坐标 在mousePressEvent 得到 + QPoint mouseDeskTopLeft; //鼠标相对于桌面左上角坐标 在mouseMoveEvent实时获取 + QPoint windowDeskTopLeft; //窗口左上角相对于桌面左上角坐标 在mouseMoveEvent实时计算(矢量)获得 +private slots: + void on_pushbtn_regist_clicked(); + + void on_pushButton_login_clicked(); + + void on_pushBtn_hide_clicked(); + + void on_pushBtn_close_clicked(); + +private: + Ui::LoginDlg *ui; + UserInfo m_userInfo; +}; + +#endif // LOGINDLG_H diff --git a/client-qt/logindlg.ui b/client-qt/logindlg.ui new file mode 100644 index 0000000..794728c --- /dev/null +++ b/client-qt/logindlg.ui @@ -0,0 +1,295 @@ + + + LoginDlg + + + + 0 + 0 + 412 + 534 + + + + + 350 + 330 + + + + + 16777215 + 16777215 + + + + Dialog + + + + + + + + + + 350 + 330 + + + + + 430 + 330 + + + + + + 70 + 210 + 101 + 41 + + + + ArrowCursor + + + 注册 + + + QPushButton{ + background-color: rgb(80, 156, 255); + + color: rgb(255, 255, 255); + border-style: solid; + border-radius: 5px; + +} + +QPushButton:hover{ + background-color: rgb(56,205,127); +} + +QPushButton:pressed { + background-color: rgb(7,193,96); +} + + + 注册账号 + + + + + + 300 + 10 + 77 + 42 + + + + + + + QPushButton { + border: none; /* no border for a flat push button */ + image: url(:/src/min.png); /* 最小化 */ + min-width: 34px; + max-width: 34px; + min-height: 40px; + max-height: 40px; +} +QPushButton::hover { + background-color: rgba(166,166,166, 50); +} + + + + + + + + + + QPushButton { + border: none; /* no border for a flat push button */ + image: url(:/src/close.png); /* 最小化 */ + min-width: 34px; + max-width: 34px; + min-height: 40px; + max-height: 40px; +} +QPushButton::hover { + background-color: #f57575; +} + + + + + + + + + + + + 190 + 210 + 101 + 41 + + + + QPushButton{ + background-color: rgb(80, 156, 255); + + color: rgb(255, 255, 255); + border-style: solid; + border-radius: 5px; + +} + +QPushButton:hover{ + background-color: rgb(56,205,127); +} + +QPushButton:pressed { + background-color: rgb(7,193,96); +} + + + 登录 + + + + + + 100 + 120 + 171 + 30 + + + + QLineEdit{ + color: rgb(0, 0, 0); + border-style: none; + border-radius: 5px; + border-right:1px solid #3498db; + border-top:1px solid #3498db; + border-left:1px solid #3498db; + border-bottom:1px solid #3498db; + min-height: 20px; +} +QLineEdit:focus { + border: 2px solid #3498db; +} + + + 10000 + + + + + + 10 + 120 + 51 + 21 + + + + + 12 + + + + Qt::LeftToRight + + + 账号: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 0 + 160 + 61 + 21 + + + + + 12 + + + + 密码: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 100 + 160 + 171 + 30 + + + + QLineEdit{ + color: rgb(0, 0, 0); + border-style: none; + border-radius: 5px; + border-right:1px solid #3498db; + border-top:1px solid #3498db; + border-left:1px solid #3498db; + border-bottom:1px solid #3498db; + min-height: 20px; +} +QLineEdit:focus { + border: 2px solid #3498db; +} + + + 123456 + + + + + + 10 + 10 + 101 + 21 + + + + + Consolas + 12 + + + + color: rgb(166,166,166); + + + Chatware + + + + + + + + + diff --git a/client-qt/main.cpp b/client-qt/main.cpp new file mode 100644 index 0000000..0cf1ffa --- /dev/null +++ b/client-qt/main.cpp @@ -0,0 +1,14 @@ +#include "widget.h" +#include "common.h" +#include + + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + if(w.getLoginStatus() == false) + return 0; + w.show(); + return a.exec(); +} diff --git a/client-qt/registdlg.cpp b/client-qt/registdlg.cpp new file mode 100644 index 0000000..bdc3b35 --- /dev/null +++ b/client-qt/registdlg.cpp @@ -0,0 +1,158 @@ +#include "registdlg.h" +#include "ui_registdlg.h" + +#include + +RegistDlg::RegistDlg(QWidget *parent) : + QDialog(parent), + ui(new Ui::RegistDlg) +{ + ui->setupUi(this); + Init(); +} + +RegistDlg::~RegistDlg() +{ + delete ui; +} + +void RegistDlg::mousePressEvent(QMouseEvent *event) +{ + mouseWindowTopLeft = event->pos(); +} + +void RegistDlg::mouseMoveEvent(QMouseEvent *event) +{ + + //窗口移动 + if (event->buttons() & Qt::LeftButton) + { + mouseDeskTopLeft = event->globalPos(); + windowDeskTopLeft = mouseDeskTopLeft - mouseWindowTopLeft; //矢量计算 + this->move(windowDeskTopLeft); //移动到目的地 + } +} + +void RegistDlg::disconnectedSlot() +{ + ChatLogInfo()<<"close socket..."; +} + +void RegistDlg::readyReadSlot() +{ + DeMessageHead header; + /*接收注册响应*/ + memset(&header,'\0',sizeof(DeMessageHead)); + int len = socket->read((char*)&header,sizeof(DeMessageHead)); + ChatLogInfo()<<"readLen:"<read((char*)pPacket,header.length); + + if(pPacket->error == 0){ + m_status = true; + } + + RegistInfoResp* resp = (RegistInfoResp*)(p+sizeof(DeMessagePacket)); + ChatLogInfo()<<"account:"<m_account; + + userInfo.m_account = resp->m_account; + strncpy(userInfo.m_userName,ui->lineEdit_username->text().toStdString().c_str(),ui->lineEdit_username->text().toStdString().size()); + strncpy(userInfo.m_password,ui->lineEdit_password->text().toStdString().c_str(),ui->lineEdit_password->text().size()); + + free(p); + return accept(); //Closes the dialog and emits the accepted() signal. +} + +void RegistDlg::Init() +{ + this->setWindowTitle("WeChat 注册"); + memset(&userInfo,'\0',sizeof (userInfo)); + m_status = false; + setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint); // 最小化按钮 + setWindowFlags(windowFlags() | Qt::WindowContextHelpButtonHint); // 帮助按钮 + + int width = this->width()-10; + int height = this->height()-10; + ui->centerWidget->setGeometry(5,5,width,height); + ui->centerWidget->setStyleSheet("QWidget{border-radius:4px;background:rgba(255,255,255,1);}"); //设置圆角 + + this->setWindowFlags(Qt::FramelessWindowHint); //去掉标题栏无边框 + this->setAttribute(Qt::WA_TranslucentBackground,true); + //实例阴影shadow + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + //设置阴影距离 + shadow->setOffset(0, 0); + //设置阴影颜色 + shadow->setColor(QColor(39,40,43,100)); + //设置阴影圆角 + shadow->setBlurRadius(10); + //给嵌套QWidget设置阴影 + ui->centerWidget->setGraphicsEffect(shadow); +} + +void RegistDlg::on_pushBtn_regist_clicked() +{ + socket = new QTcpSocket; + QString ipAddressStr = SERVER_ADDR; + quint16 port = SERVER_PORT; + + socket->connectToHost(ipAddressStr, port); + if(socket->waitForConnected(3000)) + { + ChatLogInfo() << "Connect Server success"; + } + else + { + ChatLogInfo() << socket->errorString(); + return; + } + + connect(socket, SIGNAL(disconnected()),this, SLOT(disconnectedSlot())); //客户端断开连接 + connect(socket, SIGNAL(readyRead()),this, SLOT(readyReadSlot())); //接收消息 + + RegistInfoReq info; + memset(&info,'\0',sizeof(RegistInfoReq)); + strncpy(info.m_userName,ui->lineEdit_username->text().toStdString().c_str(),ui->lineEdit_username->text().toStdString().size()); + strncpy(info.m_password,ui->lineEdit_password->text().toStdString().c_str(),ui->lineEdit_password->text().size()); + writeMsg(&info,sizeof(RegistInfoReq),CommandEnum_Registe); +} + +void RegistDlg::writeMsg(void *buf, int bufLen, int type) +{ + DeMessageHead header; + memcpy(header.mark, "DE", sizeof(header.mark)); + header.encoded = '0'; + header.version = '0'; + header.length = sizeof(DeMessagePacket) + bufLen; + + char *p = (char *)malloc(header.length); + DeMessagePacket *pPacket = (DeMessagePacket *)p; + pPacket->mode = 2; + pPacket->sequence = getSeqNum(); + pPacket->command = type; + pPacket->error = 0; + if(buf) + memcpy(p + sizeof(DeMessagePacket), buf, bufLen); + + char *sendMsg = new char[sizeof(DeMessageHead) + header.length]; + memset(sendMsg, 0, sizeof(DeMessageHead) + header.length); + memcpy(sendMsg, &header, sizeof(DeMessageHead)); + memcpy(sendMsg + sizeof(DeMessageHead), p, header.length); + free(p); + socket->write(sendMsg, sizeof(DeMessageHead) + header.length); + delete[] sendMsg; +} + +void RegistDlg::on_pushBtn_hide_clicked() +{ + QWidget* pWindow = this->window(); + if(pWindow->isTopLevel()) + pWindow->showMinimized(); +} + +void RegistDlg::on_pushBtn_close_clicked() +{ + this->close(); +} diff --git a/client-qt/registdlg.h b/client-qt/registdlg.h new file mode 100644 index 0000000..ed822e9 --- /dev/null +++ b/client-qt/registdlg.h @@ -0,0 +1,56 @@ +#ifndef REGISTDLG_H +#define REGISTDLG_H + +#include +#include +#include "common.h" +namespace Ui { +class RegistDlg; +} + +class RegistDlg : public QDialog +{ + Q_OBJECT + +public: + explicit RegistDlg(QWidget *parent = nullptr); + ~RegistDlg(); + +protected: + // Event handlers + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event); +public: + QPoint mouseWindowTopLeft; //鼠标相对窗口左上角的坐标 在mousePressEvent 得到 + QPoint mouseDeskTopLeft; //鼠标相对于桌面左上角坐标 在mouseMoveEvent实时获取 + QPoint windowDeskTopLeft; //窗口左上角相对于桌面左上角坐标 在mouseMoveEvent实时计算(矢量)获得 + +public: + UserInfo getUserInfo(){ + return userInfo; + } + bool getStatus(){ + return m_status; + } + +private slots: + void disconnectedSlot(); + void readyReadSlot(); +private slots: + void on_pushBtn_regist_clicked(); + + void on_pushBtn_hide_clicked(); + + void on_pushBtn_close_clicked(); + +private: + void Init(); + void writeMsg(void*buf,int bufLen,int type); +private: + Ui::RegistDlg *ui; + QTcpSocket *socket; + UserInfo userInfo; + bool m_status; //注册成功或者失败 +}; + +#endif // REGISTDLG_H diff --git a/client-qt/registdlg.ui b/client-qt/registdlg.ui new file mode 100644 index 0000000..202a625 --- /dev/null +++ b/client-qt/registdlg.ui @@ -0,0 +1,285 @@ + + + RegistDlg + + + + 0 + 0 + 466 + 603 + + + + + 430 + 330 + + + + + 16777215 + 16777215 + + + + Dialog + + + + + + + 430 + 330 + + + + + 430 + 330 + + + + + + 90 + 254 + 235 + 61 + + + + + 235 + 35 + + + + QPushButton{ + background-color: rgb(80, 156, 255); + + color: rgb(255, 255, 255); + border-style: solid; + border-radius: 5px; + +} + +QPushButton:hover{ + background-color: rgb(56,205,127); +} + +QPushButton:pressed { + background-color: rgb(7,193,96); +} + + + 注册 + + + + + + 120 + 100 + 240 + 30 + + + + + 240 + 22 + + + + + 240 + 30 + + + + QLineEdit{ + color: rgb(0, 0, 0); + border-style: none; + border-radius: 5px; + border-right:1px solid #3498db; + border-top:1px solid #3498db; + border-left:1px solid #3498db; + border-bottom:1px solid #3498db; + min-height: 20px; +} +QLineEdit:focus { + border: 2px solid #3498db; +} + + + I_love_ruangong + + + + + + 120 + 160 + 240 + 30 + + + + + 240 + 22 + + + + + 240 + 30 + + + + QLineEdit{ + color: rgb(0, 0, 0); + border-style: none; + border-radius: 5px; + border-right:1px solid #3498db; + border-top:1px solid #3498db; + border-left:1px solid #3498db; + border-bottom:1px solid #3498db; + min-height: 20px; +} +QLineEdit:focus { + border: 2px solid #3498db; +} + + + 123456 + + + + + + 40 + 100 + 71 + 21 + + + + + 12 + + + + Qt::LeftToRight + + + 用户名: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 50 + 160 + 61 + 21 + + + + + 12 + + + + 密 码: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 20 + 10 + 61 + 21 + + + + + Consolas + 12 + + + + color: rgb(166,166,166); + + + 注册 + + + + + + 350 + 0 + 77 + 42 + + + + + + + QPushButton { + border: none; /* no border for a flat push button */ + image: url(:/src/min.png); /* 最小化 */ + min-width: 34px; + max-width: 34px; + min-height: 40px; + max-height: 40px; +} +QPushButton::hover { + background-color: rgba(166,166,166, 50); +} + + + + + + + + + + QPushButton { + border: none; /* no border for a flat push button */ + image: url(:/src/close.png); /* 最小化 */ + min-width: 34px; + max-width: 34px; + min-height: 40px; + max-height: 40px; +} +QPushButton::hover { + background-color: #f57575; +} + + + + + + + + + + + + + + + diff --git a/client-qt/src.qrc b/client-qt/src.qrc new file mode 100644 index 0000000..b2a600b --- /dev/null +++ b/client-qt/src.qrc @@ -0,0 +1,26 @@ + + + src/login_bk.jpg + src/shut.png + src/zxh.png + src/chat.png + src/more2.png + src/wxx.png + src/close.png + src/min.png + src/max.png + src/emoj.png + src/emoj2.png + src/tianjia.png + src/tianjia2.png + src/file.png + src/file2.png + src/screenshot.png + src/screenshot2.png + src/chat2.png + src/more.png + src/wechat.png + src/wechat2.png + src/wechat3.png + + diff --git a/client-qt/src/12333.jpg b/client-qt/src/12333.jpg new file mode 100644 index 0000000..36d37ad Binary files /dev/null and b/client-qt/src/12333.jpg differ diff --git a/client-qt/src/WeCloudIcon.png b/client-qt/src/WeCloudIcon.png new file mode 100644 index 0000000..3c9d9bb Binary files /dev/null and b/client-qt/src/WeCloudIcon.png differ diff --git a/client-qt/src/addfriend.png b/client-qt/src/addfriend.png new file mode 100644 index 0000000..8022820 Binary files /dev/null and b/client-qt/src/addfriend.png differ diff --git a/client-qt/src/chat.png b/client-qt/src/chat.png new file mode 100644 index 0000000..05e6cec Binary files /dev/null and b/client-qt/src/chat.png differ diff --git a/client-qt/src/chat2.png b/client-qt/src/chat2.png new file mode 100644 index 0000000..3d8b91e Binary files /dev/null and b/client-qt/src/chat2.png differ diff --git a/client-qt/src/close.png b/client-qt/src/close.png new file mode 100644 index 0000000..4ee25ce Binary files /dev/null and b/client-qt/src/close.png differ diff --git a/client-qt/src/dongtai.png b/client-qt/src/dongtai.png new file mode 100644 index 0000000..1fee8d2 Binary files /dev/null and b/client-qt/src/dongtai.png differ diff --git a/client-qt/src/emoj.png b/client-qt/src/emoj.png new file mode 100644 index 0000000..4b46b8b Binary files /dev/null and b/client-qt/src/emoj.png differ diff --git a/client-qt/src/emoj2.png b/client-qt/src/emoj2.png new file mode 100644 index 0000000..83b38a5 Binary files /dev/null and b/client-qt/src/emoj2.png differ diff --git a/client-qt/src/file.png b/client-qt/src/file.png new file mode 100644 index 0000000..4aa7bc4 Binary files /dev/null and b/client-qt/src/file.png differ diff --git a/client-qt/src/file2.png b/client-qt/src/file2.png new file mode 100644 index 0000000..425c333 Binary files /dev/null and b/client-qt/src/file2.png differ diff --git a/client-qt/src/haoyou.png b/client-qt/src/haoyou.png new file mode 100644 index 0000000..dbe3663 Binary files /dev/null and b/client-qt/src/haoyou.png differ diff --git a/client-qt/src/head.jpg b/client-qt/src/head.jpg new file mode 100644 index 0000000..36d37ad Binary files /dev/null and b/client-qt/src/head.jpg differ diff --git a/client-qt/src/login_bk.jpg b/client-qt/src/login_bk.jpg new file mode 100644 index 0000000..bc6f284 Binary files /dev/null and b/client-qt/src/login_bk.jpg differ diff --git a/client-qt/src/max.png b/client-qt/src/max.png new file mode 100644 index 0000000..528d750 Binary files /dev/null and b/client-qt/src/max.png differ diff --git a/client-qt/src/min.png b/client-qt/src/min.png new file mode 100644 index 0000000..a233b4f Binary files /dev/null and b/client-qt/src/min.png differ diff --git a/client-qt/src/more.png b/client-qt/src/more.png new file mode 100644 index 0000000..d244041 Binary files /dev/null and b/client-qt/src/more.png differ diff --git a/client-qt/src/more2.png b/client-qt/src/more2.png new file mode 100644 index 0000000..b14e12a Binary files /dev/null and b/client-qt/src/more2.png differ diff --git a/client-qt/src/screenshot.png b/client-qt/src/screenshot.png new file mode 100644 index 0000000..dda83db Binary files /dev/null and b/client-qt/src/screenshot.png differ diff --git a/client-qt/src/screenshot2.png b/client-qt/src/screenshot2.png new file mode 100644 index 0000000..cbc6eab Binary files /dev/null and b/client-qt/src/screenshot2.png differ diff --git a/client-qt/src/shezhi.png b/client-qt/src/shezhi.png new file mode 100644 index 0000000..dbb6977 Binary files /dev/null and b/client-qt/src/shezhi.png differ diff --git a/client-qt/src/shut.png b/client-qt/src/shut.png new file mode 100644 index 0000000..2192636 Binary files /dev/null and b/client-qt/src/shut.png differ diff --git a/client-qt/src/tianjia.png b/client-qt/src/tianjia.png new file mode 100644 index 0000000..3cd1ce0 Binary files /dev/null and b/client-qt/src/tianjia.png differ diff --git a/client-qt/src/tianjia2.png b/client-qt/src/tianjia2.png new file mode 100644 index 0000000..01c64a8 Binary files /dev/null and b/client-qt/src/tianjia2.png differ diff --git a/client-qt/src/wechat.png b/client-qt/src/wechat.png new file mode 100644 index 0000000..f1f34e6 Binary files /dev/null and b/client-qt/src/wechat.png differ diff --git a/client-qt/src/wechat2.png b/client-qt/src/wechat2.png new file mode 100644 index 0000000..1b0e395 Binary files /dev/null and b/client-qt/src/wechat2.png differ diff --git a/client-qt/src/wechat3.png b/client-qt/src/wechat3.png new file mode 100644 index 0000000..f277b75 Binary files /dev/null and b/client-qt/src/wechat3.png differ diff --git a/client-qt/src/weichat.png b/client-qt/src/weichat.png new file mode 100644 index 0000000..8e6590f Binary files /dev/null and b/client-qt/src/weichat.png differ diff --git a/client-qt/src/wenjian.png b/client-qt/src/wenjian.png new file mode 100644 index 0000000..734e51c Binary files /dev/null and b/client-qt/src/wenjian.png differ diff --git a/client-qt/src/wxx.png b/client-qt/src/wxx.png new file mode 100644 index 0000000..28a609f Binary files /dev/null and b/client-qt/src/wxx.png differ diff --git a/client-qt/src/zxh.png b/client-qt/src/zxh.png new file mode 100644 index 0000000..fa689e6 Binary files /dev/null and b/client-qt/src/zxh.png differ diff --git a/client-qt/wechat.ico b/client-qt/wechat.ico new file mode 100644 index 0000000..8d22d51 Binary files /dev/null and b/client-qt/wechat.ico differ diff --git a/client-qt/widget.cpp b/client-qt/widget.cpp new file mode 100644 index 0000000..e23e000 --- /dev/null +++ b/client-qt/widget.cpp @@ -0,0 +1,743 @@ +#include "widget.h" +#include "ui_widget.h" +#include +#include +#include +#include +#include + +Widget::Widget(QWidget *parent) + : QWidget(parent) + , ui(new Ui::Widget) +{ + ui->setupUi(this); + InitUI(); + Init(); +} + +Widget::~Widget() +{ + delete ui; +} + +void Widget::mousePressEvent(QMouseEvent *event) +{ + mouseWindowTopLeft = event->pos(); +} + +void Widget::mouseMoveEvent(QMouseEvent *event) +{ + //窗口移动 + if (event->buttons() & Qt::LeftButton) + { + mouseDeskTopLeft = event->globalPos(); + windowDeskTopLeft = mouseDeskTopLeft - mouseWindowTopLeft; //矢量计算 + this->move(windowDeskTopLeft); //移动到目的地 + } +} + +void Widget::mouseDoubleClickEvent(QMouseEvent *event) +{ + Q_UNUSED(event) + if(m_isfull){ + //取消全屏 + m_isfull = false; + ui->centerWidget->setGeometry(m_rect); + + ui->centerWidget->move(QApplication::desktop()->screen()->rect().center() - ui->centerWidget->rect().center()); + } + else { + m_isfull = true; + m_rect = ui->centerWidget->rect(); + setGeometry(QGuiApplication::primaryScreen()->availableGeometry()); // 不包含windows任务栏区域 + ui->centerWidget->setGeometry(this->rect()); + } +} + + +void Widget::on_pushBtn_max_clicked() +{ +// this->showFullScreen(); //全屏 + if(m_isfull){ + //取消全屏 + m_isfull = false; + ui->centerWidget->setGeometry(640,480,m_rect.width(),m_rect.height()); + ui->centerWidget->move(QApplication::desktop()->screen()->rect().center() - ui->centerWidget->rect().center()); + } + else { + m_isfull = true; + m_rect = ui->centerWidget->rect(); + setGeometry(QGuiApplication::primaryScreen()->availableGeometry()); // 不包含windows任务栏区域 + ui->centerWidget->setGeometry(this->rect()); + } +// ui->centerWidget->showMaximized(); +// this->showMaximized(); +} + +void Widget::disconnectedSlot() +{ + ChatLogInfo()<<"Socket close"; +} + +void Widget::readyReadSlot() +{ + if(m_session->readEvent()!=RET_END){ + ChatLogInfo()<<"读取出错了"; + } +} + +void Widget::InitUI() +{ + this->setWindowTitle("WeChat"); +// int width = this->width()-10; +// int height = this->height()-10; +// ui->centerWidget->setGeometry(5,5,width,height); + ui->centerWidget->setStyleSheet("QWidget#centerWidget{ border-radius:4px; background:rgba(255,255,255,1); }"); + + this->setWindowFlags(Qt::FramelessWindowHint); //去掉标题栏无边框 + this->setAttribute(Qt::WA_TranslucentBackground,true); + //实例阴影shadow + QGraphicsDropShadowEffect *shadow = new QGraphicsDropShadowEffect(this); + //设置阴影距离 + shadow->setOffset(0, 0); + //设置阴影颜色 + shadow->setColor(QColor(39,40,43,100)); + //设置阴影圆角 + shadow->setBlurRadius(10); + //给嵌套QWidget设置阴影 + ui->centerWidget->setGraphicsEffect(shadow); + + + m_isfull = false; +} + +void Widget::Init() +{ + socket = new QTcpSocket; + socketState = false; + m_isLogin = false; + + QString ipAddressStr = SERVER_ADDR; + quint16 port = SERVER_PORT; + + if(!socketState) + { + socket->connectToHost(ipAddressStr, port); + if(socket->waitForConnected(3000)) + { + ChatLogInfo() << "Connect2Server OK"; + socketState = true; + } + else + { + ChatLogInfo() << socket->errorString(); + return; + } + } + else + { + socket->close(); //触发disconnected()信号 + socketState = false; + } + + m_session = new Session(socket); + connect(m_session,SIGNAL(signal_handleMsg(recvMsg *)),this,SLOT(handleMsg(recvMsg *))); + + LoginDlg loginDlg; //这个loginDlog必须是父窗口 + do{ + loginDlg.show(); + int status = loginDlg.exec(); + if(status == QDialog::Accepted) + { + ChatLogInfo()<<"will loadin.."; + UserInfo* userInfo = loginDlg.getUserInfo(); + memmove(&m_userInfo,userInfo,sizeof(UserInfo)); + ChatLogInfo()<<"get account:"<m_isLogin = false; + return; + } + }while(this->m_isLogin == false); + + connect(socket, SIGNAL(disconnected()),this, SLOT(disconnectedSlot())); //客户端断开连接 + connect(socket, SIGNAL(readyRead()),this, SLOT(readyReadSlot())); //接收消息 + + getGroupList(); + getFriendList(); +} + + +int Widget::login() +{ + //登录 + LoginInfoReq loginInfo; + memset(&loginInfo,'\0',sizeof(LoginInfoReq)); + loginInfo.m_account = m_userInfo.m_account; + ChatLogInfo()<<"m_account:"<socket->waitForReadyRead()==false){ + return -1; + } + + DeMessageHead header; + memset(&header,'\0',sizeof(DeMessageHead)); + int len = socket->read((char*)&header,sizeof(DeMessageHead)); + char *p = (char*)malloc(header.length); + DeMessagePacket* pPacket = (DeMessagePacket *)p; + socket->read((char*)pPacket,header.length); + if(pPacket->error == 0){ + ChatLogInfo()<<"登录成功.."; + m_isLogin = true; + } + free(p); + return true; +} + +static int stackWidgetIndex = 0; + +void Widget::Init_Group_Info(GroupChatInfo* groupInfo) +{ + ui->listWidget_info->addItem(QString("[群][%1]").arg(groupInfo->m_groupName)); + + ui->stackedWidget_Msg->setCurrentIndex(stackWidgetIndex++); + if(stackWidgetIndex >=ui->stackedWidget_Msg->count()) + { + QWidget* page = new QWidget(); + page->setObjectName(QString("page%1").arg(stackWidgetIndex)); + ui->stackedWidget_Msg->addWidget(page); + ChatLogInfo()<<"stackedWidget_Msg account:"<stackedWidget_Msg->count()<<",stackWidgetIndex:"<stackedWidget_Msg->currentWidget()->setLayout(mainLayout); + listWidget->setStyleSheet("QListWidget{"\ + "background-color: rgb(247,247,247);"\ + "border-style: none;"\ + "}"); + mainLayout->addWidget(listWidget); + mainLayout->setMargin(0); //设置外边距 + mainLayout->setSpacing(0);//设置内边距 + + m_chatWigetMap.insert(std::make_pair(groupInfo->m_account,listWidget)); + chatWidgetInfo* chatInfo = new chatWidgetInfo; + chatInfo->m_account = groupInfo->m_account; + chatInfo->m_type = TYPE_GROUP_CHAT; + + m_chatWidgetInfoList.push_back(chatInfo); + + ui->listWidget_info->setCurrentRow(stackWidgetIndex - 1); +} + +void Widget::Init_Friend_Info(FriendInfo *friendInfo) +{ + ui->listWidget_info->addItem(QString("[好友][%1]").arg(friendInfo->m_userName)); + + ui->stackedWidget_Msg->setCurrentIndex(stackWidgetIndex++); + if(stackWidgetIndex >=ui->stackedWidget_Msg->count()) + { + QWidget* page = new QWidget(); + page->setObjectName(QString("page%1").arg(stackWidgetIndex)); + ui->stackedWidget_Msg->addWidget(page); + ChatLogInfo()<<"stackedWidget_Msg account:"<stackedWidget_Msg->count()<<",stackWidgetIndex:"<stackedWidget_Msg->currentWidget()->setLayout(mainLayout); + listWidget->setStyleSheet("QListWidget{"\ + "background-color: rgb(247,247,247);"\ + "border-style: none;"\ + "border-top:1px solid #D6D6D6;"\ + "}"); + mainLayout->addWidget(listWidget); + mainLayout->setMargin(0); //设置外边距 + mainLayout->setSpacing(0);//设置内边距 + + m_chatWigetMap.insert(std::make_pair(friendInfo->m_account,listWidget)); + chatWidgetInfo* chatInfo = new chatWidgetInfo; + chatInfo->m_account = friendInfo->m_account; + chatInfo->m_type = TYPE_PRIVATE_CHAT; + + m_chatWidgetInfoList.push_back(chatInfo); + ui->listWidget_info->setCurrentRow(stackWidgetIndex - 1); +} + +void Widget::writeMsg(void *buf, int bufLen, int type, int error,int mode) +{ + DeMessageHead header; + memcpy(header.mark, "DE", sizeof(header.mark)); + header.encoded = '0'; + header.version = '0'; + header.length = sizeof(DeMessagePacket) + bufLen; + + char *p = (char *)malloc(header.length); + DeMessagePacket *pPacket = (DeMessagePacket *)p; + pPacket->mode = mode; + pPacket->sequence = getSeqNum(); + pPacket->command = type; + pPacket->error = error; + if(buf) + memcpy(p + sizeof(DeMessagePacket), buf, bufLen); + + char *sendMsg = new char[sizeof(DeMessageHead) + header.length]; + memset(sendMsg, 0, sizeof(DeMessageHead) + header.length); + memcpy(sendMsg, &header, sizeof(DeMessageHead)); + memcpy(sendMsg + sizeof(DeMessageHead), p, header.length); + if(p!=NULL){ + free(p); + p = NULL; + } + if (socket->isWritable()) { + socket->write(sendMsg, sizeof(DeMessageHead) + header.length); + } + else { + ChatLogInfo()<<"socket is unWritable"; + } + if(sendMsg!=NULL){ + delete[] sendMsg; + sendMsg = NULL; + } +} + +/** + * @brief 发送请求 + */ +void Widget::getGroupList() +{ + /*获取群聊列表*/ + writeMsg(NULL,0,CommandEnum_GetGroupList); + /*获取群成员信息*/ + GetGroupInfoReq getGroupInfoReq; + getGroupInfoReq.m_Group = 0; + writeMsg(&getGroupInfoReq,sizeof(GetGroupInfoReq),CommandEnum_GetGroupInfo); +} + +void Widget::getFriendList() +{ + writeMsg(NULL,0,CommandEnum_GetFriendInfo); +} + + +int Widget::handleRegiste(void *msg) +{ + RegistInfoReq* registInfo = (RegistInfoReq*)msg; + printf("username:%s,password:%s\n",registInfo->m_userName,registInfo->m_password); + return 0; +} + +int Widget::handleLogin(void *msg) +{ + GroupUserInfo* loginInfo = (GroupUserInfo*)msg; + ChatLogInfo()<<"account:"<m_account<<",userName:"<m_userName; + + GroupUserInfo* newGroupUserInfo = (GroupUserInfo*)malloc(sizeof(GroupUserInfo)); + memmove(newGroupUserInfo,msg,sizeof(GroupUserInfo)); + + int ret = ChatInfoManage::getInstance()->addGroupUserInfo(0,newGroupUserInfo); + if(ret == 0){ + ChatLogInfo()<<"新用户上线了,保存用户信息.."; + } + else { + ChatLogInfo()<<"Insert new userInfo fail"; + } + return 0; +} + +int Widget::handleLogout(void *msg) +{ + Q_UNUSED(msg) + return 0; +} + +int Widget::handleGroupChat(void *msg) +{ + GroupChatReq* groupChatReq = (GroupChatReq*)msg; + ChatLogInfo()<<"群聊账号:"<m_GroupAccount<<"msg size:"<m_msgLen; + //获取聊天群信息 + GroupChatInfo* groupChatInfo =ChatInfoManage::getInstance()->getGroupChatInfo(groupChatReq->m_GroupAccount); + if(groupChatInfo == NULL) + { + ChatLogInfo()<<"not find chatgroup indo"; + } + if(groupChatReq->m_msgLen <= 0){ + ChatLogInfo()<<"msgLen:"<m_msgLen; + return 0; + } + //从群用户信息总表中获取用户信息 + char*buf = (char*)malloc(groupChatReq->m_msgLen + 1); + memmove(buf,(char*)msg + sizeof(GroupChatReq),groupChatReq->m_msgLen); + buf[groupChatReq->m_msgLen] = '\0'; + + GroupUserInfo* userInfo = ChatInfoManage::getInstance()->getGroupUserInfo(groupChatReq->m_GroupAccount,groupChatReq->m_UserAccount); + if(groupChatInfo!=NULL&& userInfo!=NULL) + { + mapChatWidget::iterator iter = m_chatWigetMap.find(groupChatReq->m_GroupAccount); + if(iter!=m_chatWigetMap.end()){ + QListWidget* chatWidget = iter->second; + QListWidgetItem* item = new QListWidgetItem; + //这里转码,中文名称显示乱码 + item->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") + " " + QString("[%1][%2]:%3").arg(userInfo->m_account) + .arg(QString(userInfo->m_userName)).arg(buf)); + item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); + chatWidget->addItem(item); + ChatLogInfo()<<"["<m_groupName<<"]"<<"["<m_userName<<"]"<getFriendInfo(privateChatReq->m_UserAccount); + if(friendInfo==NULL){ + printf("not find friend\n"); + } + + if(privateChatReq->m_msgLen <= 0){ + ChatLogInfo()<<"msgLen:"<m_msgLen; + return 0; + } + + char*buf = (char*)malloc(privateChatReq->m_msgLen + 1); + memset(buf,'\0',privateChatReq->m_msgLen + 1); + memmove(buf,(char*)msg + sizeof(PrivateChatReq),privateChatReq->m_msgLen); + + //从群用户信息总表中获取用户信息 + GroupUserInfo* userInfo = ChatInfoManage::getInstance()->getUserInfo(privateChatReq->m_UserAccount); + if(userInfo!=NULL){ + + mapChatWidget::iterator iter = m_chatWigetMap.find(userInfo->m_account); + if(iter!=m_chatWigetMap.end()){ + QListWidget* chatWidget = iter->second; + QListWidgetItem* item = new QListWidgetItem; + //这里转码,中文名称显示乱码 + item->setText(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") + " " + QString("[%1][%2]:%3").arg(friendInfo->m_account) + .arg(QString(friendInfo->m_userName)).arg(buf)); + item->setTextAlignment(Qt::AlignLeft | Qt::AlignVCenter); + chatWidget->addItem(item); + ChatLogInfo()<<"["<m_userName<<"]"<m_size; + for(int i=0,index = 0; im_size; i++,index++){ + GroupChatInfo* curGroupChatInfo =(GroupChatInfo *)((char*)msg + sizeof(GetGroupListResp) + sizeof(GroupChatInfo) * index); + //添加群信息到群管理 + GroupChatInfo* groupChatInfo = (GroupChatInfo*)malloc(sizeof(GroupChatInfo)); + groupChatInfo->m_account = curGroupChatInfo->m_account; + groupChatInfo->m_size = curGroupChatInfo->m_size; + strncpy(groupChatInfo->m_groupName,curGroupChatInfo->m_groupName,sizeof(curGroupChatInfo->m_groupName)); + Init_Group_Info(groupChatInfo); + ChatLogInfo()<<"group:"<m_account<<"name:"<m_groupName<<",size:"<m_size; + ret = ChatInfoManage::getInstance()->addGroupChatInfo(groupChatInfo); + if(ret == 0){ + ChatLogInfo()<<"addGroupChatInfo success..."; + } + } + return 0; +} + +int Widget::getGroupInfo(void *msg) +{ + int ret = -1; + GetGroupInfoResp* pResp = (GetGroupInfoResp*)msg; + mapGroupUserInfo groupUserInfoMap; + //添加群成员信息到群成员管理 + ChatLogInfo()<<"group:"<m_GroupAccount<<",size:"<m_size; + for(int i=0;im_size;i++){ + GroupUserInfo* pUserInfo = (GroupUserInfo*)((char*)msg + sizeof(GetGroupInfoResp) + sizeof(GroupUserInfo)*i); + GroupUserInfo* pNewUserInfo = (GroupUserInfo*)malloc(sizeof(GroupUserInfo)); + memmove(pNewUserInfo,pUserInfo,(sizeof(GroupUserInfo))); + + if(pNewUserInfo->m_account == m_userInfo.m_account){ + strncpy(m_userInfo.m_userName,pNewUserInfo->m_userName,sizeof(pNewUserInfo->m_userName)); + } + + ret = ChatInfoManage::getInstance()->addGroupUserInfo(pResp->m_GroupAccount,pNewUserInfo); + if(ret == 0){ + ChatLogInfo()<<"account:"<m_account<<",name:"<m_userName<<"right:"<m_right<<",size:"<m_size; + for(int i=0;im_size;i++){ + FriendInfo* pFriendInfo = (FriendInfo*)((char*)msg + sizeof(GetFriendInfoResp) + sizeof(FriendInfo)*i); + FriendInfo* pNewFriendInfo = (FriendInfo*)malloc(sizeof(FriendInfo)); + memmove(pNewFriendInfo,pFriendInfo,(sizeof(FriendInfo))); + //好友 map 表中插入好友数据 + ChatInfoManage::getInstance()->addFriendInfo(pNewFriendInfo); + ChatLogInfo()<<"Friend account:"<m_account<<",name:"<m_userName; + Init_Friend_Info(pNewFriendInfo); + } + return 0; +} + +//其他客户端给你发送添加好友请求 +int Widget::handleAddFriendReq(void *msg) +{ + AddFriendInfoReq* pAddFriendInfoReq = (AddFriendInfoReq*)msg; + LOGINFO("get a add friend request..\n"); + + GroupUserInfo *pUserInfo = ChatInfoManage::getInstance()->getUserInfo(pAddFriendInfoReq->m_senderAccount); + if(pUserInfo!=NULL){ + ChatLogInfo()<<"account:"<< pAddFriendInfoReq->m_senderAccount <<",m_reqInfo:"<< pAddFriendInfoReq->m_reqInfo; + //将等待添加的好友添加到 map 表中 + FriendInfo *pFriendInfo = (FriendInfo *)malloc(sizeof(FriendInfo)); + pFriendInfo->m_account = pUserInfo->m_account; + pFriendInfo->m_status = 1; //Linux命令行客户端直接同意 + strncpy(pFriendInfo->m_userName, pUserInfo->m_userName, sizeof(pUserInfo->m_userName)); + ChatInfoManage::getInstance()->addFriendInfo(pFriendInfo); + Init_Friend_Info(pFriendInfo); + + //给等待添加的好友发送添加好友的响应 + AddFriendInfoResp resp; + resp.m_friendAccount = pAddFriendInfoReq->m_friendAccount; + resp.m_senderAccount = pAddFriendInfoReq->m_senderAccount; + resp.status = 0; //同意 + writeMsg(&resp, sizeof(AddFriendInfoResp), CommandEnum_AddFriend,0,2); + } + else if(pUserInfo == NULL){ + ChatLogInfo()<<"该用户不存在"; + } +} + +int Widget::handleAddFriendResp(void *msg) +{ + //处理好友请求后对方给的响应 + AddFriendInfoResp* pResp = (AddFriendInfoResp*)msg; + GroupUserInfo* userInfo = ChatInfoManage::getInstance()->getUserInfo(pResp->m_friendAccount); + if(pResp->status == 0){ + //对方同意添加好友 + FriendInfo*friendInfo = (FriendInfo*)malloc(sizeof(FriendInfo)); + friendInfo->m_account = pResp->m_friendAccount; + strncpy(friendInfo->m_userName,userInfo->m_userName,sizeof(userInfo->m_userName)); + friendInfo->m_status = 1; //1同意 + ChatInfoManage::getInstance()->addFriendInfo(friendInfo); + Init_Friend_Info(friendInfo); + ChatLogInfo()<<"account:"<m_account<<",name:"<m_userName; + } + else { + ChatLogInfo()<<"对方拒绝了.."; + return -1; + } + return 0; +} + +void Widget::on_pushBtn_send_clicked() +{ + ChatLogInfo()<<"on_pushBtn_send_clicked"; + if(ui->textEdit->toPlainText().isEmpty()){ + ChatLogInfo()<<"Msg is null"; + return; + } + int currentRow = ui->listWidget_info->currentRow(); + if(currentRow < 0){ + ChatLogInfo()<<"未选择聊天窗口"; + return; + } + int isfind = 0; + int currentIndex = 0; + QListWidget* chatWidget = NULL; + chatWidgetInfo* chatInfo = NULL; + for(listChatWidgetInfo::iterator iter = m_chatWidgetInfoList.begin();iter!=m_chatWidgetInfoList.end();iter++,currentIndex++){ + if(currentIndex == currentRow){ + chatInfo = *iter; + isfind = 1; + } + else { + + } + } + if(isfind){ + } + else { + ChatLogInfo()<<"---------notfind----------"; + return ; + } + mapChatWidget::iterator iter = m_chatWigetMap.find(chatInfo->m_account); + if(iter!=m_chatWigetMap.end()){ + chatWidget = iter->second; + } + else { + ChatLogInfo()<<"not find.."; + return; + } + + QString str = ui->textEdit->toPlainText(); + if(str.toStdString().size() > MAX_SEND_LENGTH){ + ChatLogInfo()<<"超出最大发送大小.."; + return; + } + ui->textEdit->clear(); + QString msg; + msg.sprintf("[%d][%s]%s",m_userInfo.m_account,m_userInfo.m_userName,str.toStdString().c_str()); + chatWidget->addItem(QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") + " " + msg); + + ChatLogInfo()<<"["<m_type == TYPE_GROUP_CHAT){ + //群聊 + GroupChatReq *groupChatReq; + char *p = (char *)malloc(sizeof(GroupChatReq) + str.toStdString().size()); + groupChatReq = (GroupChatReq *)p; + groupChatReq->m_UserAccount = m_userInfo.m_account; + groupChatReq->m_type = 0; + groupChatReq->m_GroupAccount = 0; + groupChatReq->m_msgLen = str.toStdString().size(); + memmove(p + sizeof(GroupChatReq), str.toStdString().c_str(), str.toStdString().size()); + + writeMsg(p, sizeof(GroupChatReq) + str.toStdString().size(), CommandEnum_GroupChat); + if(p != NULL){ + free(p); + p = NULL; + } + } + else if(chatInfo->m_type == TYPE_PRIVATE_CHAT){ + + //私聊 + PrivateChatReq *privateChatReq; + char *p = (char *)malloc(sizeof(PrivateChatReq) + str.toStdString().size()); + privateChatReq = (PrivateChatReq *)p; + + privateChatReq->m_UserAccount = m_userInfo.m_account; + privateChatReq->m_type = 0; + privateChatReq->m_FriendAccount = chatInfo->m_account; + privateChatReq->m_msgLen = str.toStdString().size(); + memmove(p + sizeof(PrivateChatReq), str.toStdString().c_str(), str.toStdString().size()); + writeMsg(p, sizeof(PrivateChatReq) + str.toStdString().size(), CommandEnum_PrivateChat); + if(p != NULL){ + free(p); + p = NULL; + } + } +} + +int Widget::handleMsg(recvMsg *rMsg) +{ + DeMessagePacket *packet = (DeMessagePacket *)(rMsg->body); + + DeMessageHead *head = (DeMessageHead *)(rMsg->head); +// ChatLogInfo()<<"mark:"<mark<<",encoded:"<encoded<<",length:"<length<<",version:"<version; +// ChatLogInfo()<<"command:"<command<<",error:"<error<<",mode:"<mode<<",sequence:"<sequence; + +// void *reqData = NULL; +// int reqDataLen = -1; +// short ret = RET_OK; + + ChatLogInfo()<<"handleMsg:"<command<<",str:"<command); + switch (packet->command) + { + case CommandEnum_Registe: + // handleRegiste(rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_Login: + if(packet->mode == 3){ + handleLogin(rMsg->body + sizeof(DeMessagePacket)); + }else if(packet->mode == 2 && packet->error == 0){ + m_isLogin = 1; + ChatLogInfo()<<"登陆成功.."; + } + break; + case CommandEnum_Logout: + // handleLogout(this, rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_GroupChat: + handleGroupChat(rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_AddFriend: + if(packet->mode == 1){ + //其他客户端给你发送添加好友请求 + handleAddFriendReq(rMsg->body + sizeof(DeMessagePacket)); + }else if(packet->mode == 2){ + if(head->length - sizeof(DeMessagePacket) == 0) + { + //这个是发送好友请求后服务器返回的状态 + if(packet->error == 0){ + ChatLogInfo()<<"addFriend Request success.."; + } + else { + ChatLogInfo()<<"addFriend Request fail,error:"<error; + } + } + else + handleAddFriendResp(rMsg->body + sizeof(DeMessagePacket)); + } + break; + case CommandEnum_delFriend: + break; + case CommandEnum_PrivateChat: + handlePrivateChat(rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_CreateGroup: + break; + case CommandEnum_GetGroupList: + getGroupList(rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_GetGroupInfo: + getGroupInfo(rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_GetFriendInfo: + getFriendInfo(rMsg->body + sizeof(DeMessagePacket)); + break; + } + return 0; +} + +void Widget::on_pushButton_addFriend_clicked() +{ + AddFriendDialog* addFriendDlg = new AddFriendDialog(); + + addFriendDlg->show(); + if(addFriendDlg->exec() == QDialog::Accepted) + { + AddFriendInfoReq addFriendInfoReq = addFriendDlg->getAddFriendInfoReq(); + addFriendInfoReq.m_senderAccount = m_userInfo.m_account; + ChatLogInfo()<<"friend account:"<listWidget_info->currentRow(); + ui->stackedWidget_Msg->setCurrentIndex(currentRow); + ChatLogInfo()<text()<<"current Row chicked.."<close(); +} + +void Widget::on_pushBtn_hide_clicked() +{ + QWidget* pWindow = this->window(); + if(pWindow->isTopLevel()) + pWindow->showMinimized(); +} + diff --git a/client-qt/widget.h b/client-qt/widget.h new file mode 100644 index 0000000..ff8a8e5 --- /dev/null +++ b/client-qt/widget.h @@ -0,0 +1,104 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include +#include +#include "common.h" +#include "logindlg.h" +#include "addfrienddialog.h" +#include +#include + +QT_BEGIN_NAMESPACE +namespace Ui { class Widget; } +QT_END_NAMESPACE + +typedef enum{ + TYPE_GROUP_CHAT,TYPE_PRIVATE_CHAT +}EChatType; + +struct chatWidgetInfo{ + int m_account; //聊天窗口对应的聊天号 + EChatType m_type; //聊天窗口对应的类型 群聊/私聊 +}; + +typedef std::map mapChatWidget; +typedef std::list listChatWidgetInfo; + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = nullptr); + ~Widget(); +protected: + // Event handlers + virtual void mousePressEvent(QMouseEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event); + virtual void mouseDoubleClickEvent(QMouseEvent *event); //双击 +public: + QPoint mouseWindowTopLeft; //鼠标相对窗口左上角的坐标 在mousePressEvent 得到 + QPoint mouseDeskTopLeft; //鼠标相对于桌面左上角坐标 在mouseMoveEvent实时获取 + QPoint windowDeskTopLeft; //窗口左上角相对于桌面左上角坐标 在mouseMoveEvent实时计算(矢量)获得 + +private slots: + void disconnectedSlot(); + void readyReadSlot(); + void on_pushBtn_send_clicked(); +private slots: + int handleMsg(recvMsg *rMsg); + void on_pushButton_addFriend_clicked(); + + void on_listWidget_info_itemClicked(QListWidgetItem *item); + + void on_pushBtn_close_clicked(); + + void on_pushBtn_hide_clicked(); + + void on_pushBtn_max_clicked(); + +private: + void Init(); + void InitUI(); + int login(); + void Init_Group_Info(GroupChatInfo* groupInfo); + void Init_Friend_Info(FriendInfo* friendInfo); + void writeMsg(void*buf,int bufLen,int type, int error = 0,int mode = 1); +private: + void getGroupList(); + void getFriendList(); +public: + int getLoginStatus(){ + return m_isLogin; + } +#if 0 + GroupUserInfo* findUserInfo(int account); +#endif +private: + int handleRegiste(void*msg); + int handleLogin(void*msg); + int handleLogout(void*msg); + int handleGroupChat(void*msg); + int handlePrivateChat(void*msg); + int getGroupList(void*msg); + int getGroupInfo(void* msg); + int getFriendInfo(void* msg); + + + int handleAddFriendReq(void*msg); + int handleAddFriendResp(void*msg); +private: + Ui::Widget *ui; + QTcpSocket *socket; + bool socketState; + Session* m_session; + UserInfo m_userInfo; + bool m_isLogin; + bool m_isfull; + QRect m_rect; + + mapChatWidget m_chatWigetMap; //聊天列表 + listChatWidgetInfo m_chatWidgetInfoList; +}; +#endif // WIDGET_H diff --git a/client-qt/widget.ui b/client-qt/widget.ui new file mode 100644 index 0000000..3dbd6bf --- /dev/null +++ b/client-qt/widget.ui @@ -0,0 +1,644 @@ + + + Widget + + + + 0 + 0 + 947 + 670 + + + + Widget + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + + 250 + 60 + + + + + 250 + 60 + + + + background-color: rgb(247,247,247); +border-right:1px solid #D6D6D6; + + + + + 10 + 30 + 191 + 20 + + + + QLineEdit +{ + background-color: rgb(226,226,226); + border: none; /* no border for a flat push button */ +} +QLineEdit +{ + background-color: rgb(226,226,226); + border: none; /* no border for a flat push button */ +} + + + + + + + 210 + 30 + 20 + 20 + + + + + 20 + 20 + + + + + 20 + 20 + + + + 添加好友 + + + QPushButton { + border: none; /* no border for a flat push button */ + image: url(:/src/tianjia.png); + background-color: rgb(226,226,226); + min-width: 20px; + max-width: 20px; + min-height: 20px; + max-height: 20px; +} +QPushButton::hover { + background-color: rgb(209,209,209); + image: url(:/src/tianjia2.png); +} +QPushButton:pressed { + image: url(:/src/tianjia.png); +} + + + + + + + + + + + + 250 + 0 + + + + + 250 + 16777215 + + + + QListWidget +{ + background-color: rgb(226,224,223); + border-style: none; + border-right:1px solid #D6D6D6; + border-top:1px solid #D6D6D6; + border-left:1px solid #D6D6D6; + border-bottom:1px solid #D6D6D6; +} + +QScrollBar:vertical +{ + width:8px; + background:rgba(0,0,0,0%); + margin:0px,0px,0px,0px; + padding-top:9px; + padding-bottom:9px; +} +QScrollBar::handle:vertical +{ + width:8px; + background:rgba(0,0,0,25%); + border-radius:4px; + min-height:20; +} +QScrollBar::handle:vertical:hover +{ + width:8px; + background:rgba(0,0,0,50%); + border-radius:4px; + min-height:20; +} +QScrollBar::add-line:vertical +{ + height:9px;width:8px; + border-image:url(:/images/a/3.png); + subcontrol-position:bottom; +} +QScrollBar::sub-line:vertical +{ + height:9px;width:8px; + border-image:url(:/images/a/1.png); + subcontrol-position:top; +} +QScrollBar::add-line:vertical:hover +{ + height:9px;width:8px; + border-image:url(:/images/a/4.png); + subcontrol-position:bottom; +} +QScrollBar::sub-line:vertical:hover +{ + height:9px;width:8px; + border-image:url(:/images/a/2.png); + subcontrol-position:top; +} +QScrollBar::add-page:vertical,QScrollBar::sub-page:vertical +{ + background:rgba(0,0,0,10%); + border-radius:4px; +} + + + + + + + + + + 0 + + + + + + 0 + 70 + + + + + 16777215 + 70 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + + 20 + 0 + + + + + 20 + 16777215 + + + + + + + + + 0 + 65 + + + + + 16777215 + 65 + + + + + 新宋体 + 12 + + + + background-color: rgb(255, 255, 255); +border: none; /* no border for a flat push button */ + + + + + + + + + + + + + + 0 + 60 + + + + + 16777215 + 60 + + + + background-color: rgb(245,245,245); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + + 30 + 25 + + + + + 30 + 25 + + + + QPushButton { + border: none; /* no border for a flat push button */ + image: url(:/src/min.png); /* 最小化 */ + min-width: 30px; + max-width: 30px; + min-height: 25px; + max-height: 25px; +} +QPushButton::hover { + background-color: rgba(166,166,166, 50); +} + + + + + + + + + + + 30 + 25 + + + + + 30 + 25 + + + + QPushButton { + border: none; /* no border for a flat push button */ + image: url(:/src/max.png); /* 最小化 */ + min-width: 30px; + max-width: 30px; + min-height: 25px; + max-height: 25px; +} +QPushButton::hover { + background-color: rgba(166,166,166, 50); +} + + + + + + + + + + + 30 + 25 + + + + + 30 + 25 + + + + QPushButton { + border: none; /* no border for a flat push button */ + image: url(:/src/close.png); /* 最小化 */ + min-width: 30px; + max-width: 30px; + min-height: 25px; + max-height: 25px; +} +QPushButton::hover { + background-color: #f57575; +} + + + + + + + + + + + + + + + + + + 20 + 0 + + + + + 20 + 16777215 + + + + + + + + + 新宋体 + 14 + + + + 聊天信息~(^0^)/~ + + + + + + + + 10 + 0 + + + + + 10 + 16777215 + + + + + + + + + + + + + + + + + 0 + 35 + + + + + 16777215 + 35 + + + + background-color: rgb(255, 255, 255); + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + 0 + + + + + + 70 + 25 + + + + + 70 + 25 + + + + + 黑体 + 10 + + + + QPushButton{ + color: rgb(96,96,96); + border-radius: 5px; + border-style: solid; + background-color: rgb(35,130,245); + + border-right:1px solid #E5E5E5; + border-top:1px solid #E5E5E5; + border-left:1px solid #E5E5E5; + border-bottom:1px solid #E5E5E5; +} + +QPushButton:hover{ + color: rgb(255, 255, 255); + background-color: rgb(18,150,17); +} + +QPushButton:pressed { + background-color: rgb(7,193,96); +} + + + 发送 + + + + + + + + + + + 40 + 0 + + + + + 40 + 16777215 + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + + + 0 + + + + + + + + + + + + + + + + + + diff --git a/doc.md b/doc.md new file mode 100644 index 0000000..d30d2ea --- /dev/null +++ b/doc.md @@ -0,0 +1,18 @@ +## 服务器端 + +### 1、 职责 + +- 服务器端主要用于维护用户在线情况(Socket id等) +- 接受客户端发送的消息,并转发给接收方,若接收方离线则写数据库 +- 传送成功的数据不会写入数据库 + + + +## 客户端 + +### 1、 职责 + +- 发送消息 +- 被动接受消息 +- 在线时定时将信息(ip?)报告给服务器(包括启动时) +- 主动向服务器请求消息 diff --git a/server/DeThread.h b/server/DeThread.h new file mode 100644 index 0000000..bb1755e --- /dev/null +++ b/server/DeThread.h @@ -0,0 +1,47 @@ +#ifndef _DETHREAD_H_ +#define _DETHREAD_H_ +#define NON_NULL(x) ((x)?(x):"") + +#define ASSERT_MSG(COND, FMT, ARGS...)\ +{\ + if(!(COND)){\ + char msg[1024] = {0,};\ + snprintf(msg, sizeof(msg), FMT, ##ARGS);\ + throw std::logic_error(msg);\ + abort();\ + }\ +} + +/** + * @brief + * + * @param HDL 线程id + * @param STACK_KB 分配的栈大小 + * @param JOIN 线程是否和主线程分离 + * @param FUNC 线程执行函数 + * @param PARAM 传入的参数 + * @param NAME 线程的名字 + * + * @return int + */ +#define CREATE_THREAD(HDL,STACK_KB,JOIN,FUNC,PARAM,NAME)\ +{\ + char nctThdName[16] = {0,};/*max length is 16*/\ + int nctThdNameLen = strlen(NON_NULL(NAME));\ + if(nctThdNameLen){snprintf(nctThdName, sizeof(nctThdName), "%s", NON_NULL(NAME));}\ + pthread_t nctThdId = 0;\ + pthread_attr_t threadAttr;\ + pthread_attr_init(&threadAttr);\ + ASSERT_MSG(STACK_KB <= 1024 * 8, "Thread stack size[%d]KB is too large !!", STACK_KB);\ + if(STACK_KB > 0){pthread_attr_setstacksize(&threadAttr, 1024*STACK_KB);}\ + pthread_attr_setdetachstate(&threadAttr, JOIN ? PTHREAD_CREATE_JOINABLE : PTHREAD_CREATE_DETACHED);\ + pthread_create(&nctThdId, &threadAttr, FUNC, (void *)PARAM);\ + if((HDL))\ + {\ + *(pthread_t *)(HDL) = nctThdId;\ + }\ + ASSERT_MSG(nctThdId != 0, "Failed to create thread ! name: %s", nctThdName);\ + if(nctThdNameLen){pthread_setname_np(nctThdId, nctThdName);}\ + pthread_attr_destroy(&threadAttr);\ +} +#endif \ No newline at end of file diff --git a/server/MsgHandle.cpp b/server/MsgHandle.cpp new file mode 100644 index 0000000..2fee221 --- /dev/null +++ b/server/MsgHandle.cpp @@ -0,0 +1,696 @@ +#include "MsgHandle.h" +#include "common.h" + +Session::Session(int socket) +{ + m_isLogin = -1; + m_account = -1; + m_socket = socket; + m_type = RECV_HEAD; + m_head = NULL; + m_bufLen = 0; + m_readPos = 0; + m_body = NULL; + m_isFinish = false; + m_head = new char[sizeof(DeMessageHead)]; + m_bufLen = sizeof(DeMessageHead); +} + +Session::~Session(){ + if (m_head != NULL) + delete[] m_head; + if (m_body != NULL) + delete[] m_body; + if (m_socket != -1){ + close(m_socket); + m_socket = -1; + } + if(m_isLogin == 1){ + cleanSession(); + m_isLogin = -1; + } +}; + +int Session::readEvent() +{ + int ret = 0; + switch (m_type) + { + case RECV_HEAD: + ret = recvHead(); + break; + case RECV_BODY: + ret = recvBody(); + break; + default: + break; + } + if (ret == RET_AGAIN) + return readEvent(); + return ret; +} + +int Session::recvHead() +{ + if (m_head == NULL) + { + m_head = new char[sizeof(DeMessageHead)]; + assert(m_head != NULL); + m_bufLen = sizeof(DeMessageHead); + m_readPos = 0; + } + + int len = read(m_socket, m_head + m_readPos, m_bufLen - m_readPos); + if (len < 0) + return RET_ERROR; + if (len == 0) + return RET_EXIT; + m_readPos += len; + if (m_readPos == m_bufLen) + { + m_type = RECV_BODY; + int bufLen = ((DeMessageHead *)m_head)->length; + m_body = new char[bufLen]; + + assert(m_body != NULL); + m_bufLen = bufLen; + m_readPos = 0; //读取的位置置零 + return RET_AGAIN; + } + return 0; +} + +int Session::recvBody() +{ + /* 先判断读取的位置是否是 ((DeMessageHead*)m_head)->length 接收头指定的长度 */ + if (m_readPos == m_bufLen) + { + m_type = RECV_HEAD; + handleMsgBase(); + m_isFinish = true; + return RET_AGAIN; + } + /*读取指定 Body 大小的数据*/ + int len = read(m_socket, m_body + m_readPos, m_bufLen - m_readPos); + + if (len < 0) + return RET_ERROR; + + m_readPos += len; + + /* 判断读取的位置是否是 ((DeMessageHead*)m_head)->length 接收头指定的长度 */ + if (m_readPos == m_bufLen) + { + m_type = RECV_HEAD; + handleMsgBase(); + m_bufLen = 0; + m_isFinish = true; + return RET_AGAIN; + } + return RET_OK; +} + +int Session::handleMsgBase(){ + recvMsg *rMsg = new recvMsg(); + rMsg->head = m_head; + rMsg->body = m_body; + rMsg->bodyLen = m_bufLen; + handleMsg(rMsg); + m_head = NULL; + m_body = NULL; + return RET_OK; +} + +int Session::handleMsg(recvMsg *rMsg) +{ + DeMessagePacket *packet = (DeMessagePacket *)(rMsg->body); + DeMessageHead *head = (DeMessageHead *)(rMsg->head); + // LOGINFO("mark:%s,encoded:%d,length:%d,version:%d\n", head->mark, head->encoded, head->length, head->version); + // LOGINFO("command:%d,error:%d,,mode:%d,sequence:%d\n", packet->command, packet->error, packet->mode, packet->sequence); + void *reqData = NULL; + int reqDataLen = -1; + short ret = RET_OK; + LOGINFO("handleMsg command:%d\n",packet->command); + switch (packet->command) + { + case CommandEnum_Registe: + handleRegiste(this,rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_Login: + handleLogin(this, rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_Logout: + handleLogout(this, rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_GroupChat: + handleGroupChat(this, rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_AddFriend: + if(packet->mode == 1){ + handleAddFriendReq(rMsg->body + sizeof(DeMessagePacket)); + }else if(packet->mode == 2){ + handleAddFriendResp(rMsg->body + sizeof(DeMessagePacket)); + } + break; + case CommandEnum_delFriend: + break; + case CommandEnum_PrivateChat: + handlePrivateChat(rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_CreateGroup: + break; + case CommandEnum_GetGroupList: + handleGetGroupList(rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_GetGroupInfo: + handleGetGroupInfo(rMsg->body + sizeof(DeMessagePacket)); + break; + case CommandEnum_GetFriendInfo: + handleGetFriendInfo(rMsg->body + sizeof(DeMessagePacket)); + break; + } + delete rMsg; +} + +/** + * @brief + * + * @param socket + * @param buf + * @param bufLen + * @param type + * @param error 0为正常 其他为错误码 + * @param mode 消息模式 请求/响应 1/2 + */ +void Session::sendMsg(int socket,void*buf,int bufLen,int type,int error,int mode){ + DeMessageHead header; + memcpy(header.mark, "DE", sizeof(header.mark)); + header.encoded = '0'; + header.version = '0'; + header.length = sizeof(DeMessagePacket) + bufLen; + + char *p = (char *)malloc(header.length); + DeMessagePacket *pPacket = (DeMessagePacket *)p; + pPacket->mode = mode; + pPacket->sequence = getSeqNum(); + pPacket->command = type; + pPacket->error = error; + if(buf) + memcpy(p + sizeof(DeMessagePacket), buf, bufLen); + + char *sendMsg = new char[sizeof(DeMessageHead) + header.length]; + memset(sendMsg, 0, sizeof(DeMessageHead) + header.length); + memcpy(sendMsg, &header, sizeof(DeMessageHead)); + memcpy(sendMsg + sizeof(DeMessageHead), p, header.length); + free(p); + write(socket, sendMsg, sizeof(DeMessageHead) + header.length); +} + +void Session::cleanSession(){ + mapUserInfo::iterator iter = g_UserInfoMap.find(m_account); + if (iter == g_UserInfoMap.end()) + { + LOGINFO("出错了..\n"); + } + else + { + UserInfo* delUserInfo = iter->second; + g_UserInfoMap.erase(iter); + if(delUserInfo!=NULL){ + free(delUserInfo); + delUserInfo =NULL; + } + LOGINFO("会话关闭成功..\n在线用户数量:%d\n",g_UserInfoMap.size()); + } +} + +void Session::noticeUserLogin(UserInfo*userInfo) +{ + GroupUserInfo* groupUserInfo = (GroupUserInfo*)malloc(sizeof(GroupUserInfo)); + groupUserInfo->m_account = userInfo->m_account; + groupUserInfo->m_right = 0; + strncpy(groupUserInfo->m_userName,userInfo->m_userName,sizeof(userInfo->m_userName)); + LOGINFO("=======//%s\n",groupUserInfo->m_userName); + mapUserInfo::iterator iter = g_UserInfoMap.begin(); + for (; iter != g_UserInfoMap.end(); iter++) + { + if(iter->first == m_account) + { + LOGINFO("不给自己发..\n"); + continue; + } + sendMsg(iter->second->m_socket, groupUserInfo, sizeof(GroupUserInfo), CommandEnum_Login,0,3); //发送用户上线通知 + } +} + +/** + * @brief 未添加存储功能时,注册信息申请的RegistInfoReq*一直存在 + */ +int Session::handleRegiste(void*arg,void* msg){ + Session* pthis = (Session*)arg; + RegistInfoReq* registInfo = (RegistInfoReq*)malloc(sizeof(RegistInfoReq)); + memmove(registInfo,msg,sizeof(RegistInfoReq)); + LOGINFO("username:%s,password:%s\n",registInfo->m_userName,registInfo->m_password); + RegistInfoResp registInfoResp; + registInfoResp.m_account = g_idIndex++; + + g_AccountInfoMap.insert(std::make_pair(registInfoResp.m_account,registInfo)); + LOGINFO("account:%d,注册成功..\n",registInfoResp.m_account); + sendMsg(pthis->m_socket,®istInfoResp,sizeof(RegistInfoResp),CommandEnum_Registe); +} + +int Session::handleLogin(void*arg,void*msg){ + Session* pthis = (Session*)arg; + LoginInfoReq* loginInfo = (LoginInfoReq*)msg; + LOGINFO("account:%d,password:%s\n",loginInfo->m_account,loginInfo->m_password); + + mapAccountInfo::iterator iter = g_AccountInfoMap.find(loginInfo->m_account); + if (iter == g_AccountInfoMap.end()) + { + sendMsg(pthis->m_socket,NULL,0,CommandEnum_Login,RET_ERROR); + LOGINFO("请先注册..\n"); + } + else + { + mapUserInfo::iterator ite = g_UserInfoMap.find(loginInfo->m_account); + if(ite!=g_UserInfoMap.end()){ + sendMsg(pthis->m_socket,NULL,0,CommandEnum_Login,RET_ERROR); + LOGINFO("已登录,重复登录\n"); + return -1; + } + //匹配账号密码 + RegistInfoReq* pRegistInfoReq = iter->second; + if (strcmp(loginInfo->m_password, iter->second->m_password) == 0) + { + // 给当前会话保存账号信息 + pthis->m_account = loginInfo->m_account; + pthis->m_isLogin = 1; + strncpy(pthis->m_userName,pRegistInfoReq->m_userName,sizeof(pRegistInfoReq->m_userName)); + // 添加用户信息 + UserInfo* userInfo = (UserInfo*)malloc(sizeof(UserInfo)); + userInfo->m_account = loginInfo->m_account; + userInfo->m_socket = pthis->m_socket; + strncpy(userInfo->m_password,loginInfo->m_password,sizeof(loginInfo->m_password)); + strncpy(userInfo->m_userName,pRegistInfoReq->m_userName,sizeof(pRegistInfoReq->m_userName)); + + g_UserInfoMap.insert(std::make_pair(userInfo->m_account,userInfo)); + // 给用户添加一个公共群聊 (后续程序完善后会删除公共群聊) + mapGroupChatInfo::iterator iter = g_GroupCharInfoMap.find(0); + if( iter!= g_GroupCharInfoMap.end()){ + GroupChatInfo* info = iter->second; + info->m_size++; + LOGINFO("current group size:%d\n",g_GroupCharInfoMap.size()); + } + else{ + //第一次添加往群信息表中插入群信息 + GroupChatInfo *groupChatinfo = (GroupChatInfo *)malloc(sizeof(GroupChatInfo)); + groupChatinfo->m_account = 0; + groupChatinfo->m_size = 1; //服务启动后新用户登录时初始化公共聊天群 公共聊天群成员大小为1 + strncpy(groupChatinfo->m_groupName, "C/C++学习交流群", strlen("C/C++学习交流群")); + std::pair Insert_Pair = g_GroupCharInfoMap.insert(std::make_pair(groupChatinfo->m_account, groupChatinfo)); + if (Insert_Pair.second == true) + { + ChatLog << "Insert Successfully:" << g_GroupCharInfoMap.size() << endl; + } + else + { + ChatLog << "Insert fail" << endl; + } + } + //发送响应,告诉客户端你登录成功了 + sendMsg(pthis->m_socket,NULL, 0, CommandEnum_Login, RET_OK); + LOGINFO("登录成功..\n在线用户数量:%d\n",g_UserInfoMap.size()); + pthis->noticeUserLogin(userInfo); + } + else + { + sendMsg(pthis->m_socket,NULL,0,CommandEnum_Login,RET_ERROR); + LOGINFO("密码错误.. password:%s\n",iter->second->m_password); + } + } +} + +int Session::handleLogout(void*arg,void*msg){ + Session* pthis = (Session*)arg; + if (pthis->m_isLogin == 1){ + pthis->cleanSession(); + pthis->m_isLogin = -1; + } +} + +int Session::handleGroupChat(void *arg, void *msg){ + Session* pthis = (Session*)arg; + GroupChatReq* groupChatReq = (GroupChatReq*)msg; + + if(!pthis->m_isLogin) + return -1; + + LOGINFO("account:%d,msgLen:%d,group:%d,type:%d\n",groupChatReq->m_UserAccount,groupChatReq->m_msgLen,groupChatReq->m_GroupAccount,groupChatReq->m_type); + char*buf = (char*)malloc(groupChatReq->m_msgLen); + memmove(buf,(char*)msg + sizeof(GroupChatReq),groupChatReq->m_msgLen); + LOGINFO("recv msg:%s\n",buf); + if(groupChatReq->m_GroupAccount == 0){ + //广播 + mapUserInfo::iterator iter = g_UserInfoMap.begin(); + for(;iter!=g_UserInfoMap.end();iter++){ + if(iter->first == pthis->m_account) + { + LOGINFO("不给自己发..\n"); + continue; + } + sendMsg(iter->second->m_socket,msg,sizeof(GroupChatReq) + groupChatReq->m_msgLen, CommandEnum_GroupChat); + } + } +} + +int Session::handlePrivateChat(void*msg){ + PrivateChatReq* privateChatReq = (PrivateChatReq*)msg; + + if(!m_isLogin) + return -1; + LOGINFO("account:%d,msgLen:%d,friendAccount:%d,type:%d\n",privateChatReq->m_UserAccount,privateChatReq->m_msgLen,privateChatReq->m_FriendAccount,privateChatReq->m_type); + char*buf = (char*)malloc(privateChatReq->m_msgLen); + memmove(buf,(char*)msg + sizeof(PrivateChatReq),privateChatReq->m_msgLen); + LOGINFO("recv msg:%s\n",buf); + + mapUserFriendInfo::iterator iter = g_UserFriendInfoMap.find(m_account); + if (iter != g_UserFriendInfoMap.end()) + { + //用户存在好友表 + mapFriendInfo::iterator ite = iter->second.find(privateChatReq->m_FriendAccount); + if(ite!=iter->second.end()){ + //找到好友 + FriendInfo* friendInfo = ite->second; + //给好友发消息 + mapUserInfo::iterator it = g_UserInfoMap.find(friendInfo->m_account); + if(it!=g_UserInfoMap.end()){ + sendMsg(it->second->m_socket,msg,sizeof(PrivateChatReq) + privateChatReq->m_msgLen, CommandEnum_PrivateChat); + } + else{ + LOGINFO("用户不在线,请稍后发送..\n"); + } + } + else{ + LOGINFO("没有找到好友\n"); + } + } + else + { + LOGINFO("不存在好友表\n"); + } + + if(buf!=NULL) + free(buf); +} +/** + * @brief 获取群列表,这里需要修改,具体获取那个人的群聊列表 + */ +int Session::handleGetGroupList(void*msg){ + //申请一块内存用于保存 群列表大小 以及 群信息 + int size = sizeof(GetGroupListResp) + sizeof(GroupChatInfo)*g_GroupCharInfoMap.size(); + char*p = (char*)malloc(size); + GetGroupListResp* pResp = (GetGroupListResp*)p; + pResp->m_size = g_GroupCharInfoMap.size(); + mapGroupChatInfo::iterator iter = g_GroupCharInfoMap.begin(); + for (int index = 0; iter != g_GroupCharInfoMap.end(); iter++, index++){ + //获取当前群聊信息 + GroupChatInfo *curGroupChatInfo = iter->second; + //申请新的群聊信息 + GroupChatInfo *pGroupChatInfo = (GroupChatInfo *)(p + sizeof(GetGroupListResp) + sizeof(GroupChatInfo) * index); + pGroupChatInfo->m_account = curGroupChatInfo->m_account; + pGroupChatInfo->m_size = curGroupChatInfo->m_size; + memmove(pGroupChatInfo->m_groupName, curGroupChatInfo->m_groupName, sizeof(curGroupChatInfo->m_groupName)); + } + sendMsg(m_socket, p, size, CommandEnum_GetGroupList); +} + +/** + * @brief 获取群信息 + */ +int Session::handleGetGroupInfo(void *msg) +{ + GetGroupInfoReq* pReq = (GetGroupInfoReq*)msg; + if(pReq->m_GroupAccount == 0){ + // 全部用户 申请一块内存用于保存 群信息 以及 群成员信息 + int size = sizeof(GetGroupInfoResp) + sizeof(GroupUserInfo)*g_UserInfoMap.size(); + char*p = (char*)malloc(size); + GetGroupInfoResp* pResp = (GetGroupInfoResp*)p; + pResp->m_GroupAccount = pReq->m_GroupAccount; + pResp->m_size = g_UserInfoMap.size(); + strncpy(pResp->m_groupName,"C/C++学习交流群",strlen("C/C++学习交流群")); + //遍历保存所有群用户信息(仅在线用户在公共聊天群里面) + mapUserInfo::iterator iter = g_UserInfoMap.begin(); + for (int index = 0; iter != g_UserInfoMap.end(); iter++, index++){ + UserInfo* curUserInfo = iter->second; + GroupUserInfo *pUserInfo = (GroupUserInfo *)(p + sizeof(GetGroupInfoResp) + sizeof(GroupUserInfo) * index); + pUserInfo->m_account = curUserInfo->m_account; + pUserInfo->m_right = 0; + strncpy(pUserInfo->m_userName,curUserInfo->m_userName,sizeof(curUserInfo->m_userName)); + } + sendMsg(m_socket, p, size, CommandEnum_GetGroupInfo); + free(p); + p = NULL; + } +} + +int Session::handleGetFriendInfo(void* msg){ + // 全部用户 申请一块内存用于保存 群信息 以及 群成员信息 + //1.从用户好友表找到好友表 + mapUserFriendInfo::iterator iter = g_UserFriendInfoMap.find(m_account); + if(iter!=g_UserFriendInfoMap.end()){ + + int size = sizeof(GetFriendInfoResp) + sizeof(FriendInfo) * iter->second.size(); + char *p = (char *)malloc(size); + GetFriendInfoResp *pResp = (GetFriendInfoResp *)p; + pResp->m_size = iter->second.size(); + //用户存在好友表 + mapFriendInfo::iterator ite = iter->second.begin(); + for(int index = 0;ite!=iter->second.end();ite++,index++){ + FriendInfo* pFriendInfo = ite->second; + FriendInfo* pFriendInfoResp = (FriendInfo *)(p + sizeof(GetFriendInfoResp) + sizeof(FriendInfo) * index); + strncpy(pFriendInfoResp->m_userName, pFriendInfo->m_userName, sizeof(pFriendInfo->m_userName)); + pFriendInfoResp->m_account = pFriendInfo->m_account; + pFriendInfoResp->m_status = pFriendInfo->m_status; + } + sendMsg(m_socket, p, size, CommandEnum_GetFriendInfo); + } + else{ + //没有好友信息 + int size = sizeof(GetFriendInfoResp) + sizeof(FriendInfo) * 0; + char *p = (char *)malloc(size); + GetFriendInfoResp *pResp = (GetFriendInfoResp *)p; + pResp->m_size = 0; + LOGINFO("account:%d not has friends\n"); + sendMsg(m_socket, p, size, CommandEnum_GetFriendInfo); + } +} + +/** + * @brief A:发送好友请求的客户端 + * B:接收好友请求的客户端 + */ +int Session::handleAddFriendReq(void*msg){ + AddFriendInfoReq* pReq = (AddFriendInfoReq*)msg; + LOGINFO("recv addFriendReq:{\n\tfriendAccount:%d;\n\tsenderAccount:%d;\n\tmsg:%s;\n}\n",pReq->m_friendAccount,pReq->m_senderAccount,pReq->m_reqInfo); + //A.找到 B 的用户信息 + UserInfo *pUserInfo = NULL; + mapUserInfo::iterator UserInfoiter = g_UserInfoMap.find(pReq->m_friendAccount); + if (UserInfoiter != g_UserInfoMap.end()) + { + pUserInfo = UserInfoiter->second; + } + else{ + //没找到B用户信息,添加好友请求失败 + //给客户端发送请求失败的响应信息 + LOGINFO("not find account:%d\n",pReq->m_friendAccount); + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, -1); + return -1; + } + + //C 1.从用户好友表找到 A 对应的好友表 + mapUserFriendInfo::iterator iter = g_UserFriendInfoMap.find(m_account); + if(iter!=g_UserFriendInfoMap.end()){ + //A用户存在好友表 + //2.用户好友表中查找B的账号是否在表中 + mapFriendInfo::iterator ite = iter->second.find(pReq->m_friendAccount); + if(ite!=iter->second.end()){ + //找到了 + FriendInfo* pFriendInfo = ite->second; + if(pFriendInfo->m_status == 1){ + //已经是好友了,重复添加 不应该出现的情况 + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, -1); + return -1; + } + else if(pFriendInfo->m_status == -1){ + //B还未同意,暂时不给B发请求了 + //给客户端发送请求成功的信息,防止重复添加 + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, 0); + } + } + else{ + //没有好友信息,需要添加好友信息 + //将B添加到A的好友表中 + FriendInfo *pFriendInfo = (FriendInfo *)malloc(sizeof(FriendInfo)); + pFriendInfo->m_account = pUserInfo->m_account; + pFriendInfo->m_status = 0; //未同意的好友,当拒绝时删除这条信息 + strncpy(pFriendInfo->m_userName, pUserInfo->m_userName, sizeof(pUserInfo->m_userName)); + + std::pair Insert_Pair = iter->second.insert(std::make_pair(pReq->m_friendAccount, pFriendInfo)); + if (Insert_Pair.second == true) + { + ChatLog << "A friend map Insert Successfully:" << iter->second.size() << endl; + } + else + { + ChatLog << "A friend map Insert fail" << endl; + } + //给其 B 用户 转发 A 添加好友的请求 + sendMsg(pUserInfo->m_socket, msg, sizeof(AddFriendInfoReq), CommandEnum_AddFriend, 0, 1); + //给客户端发送请求成功的信息,告诉客户端请求被受理了 + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, 0); + } + } + else{ + //A用户不存在好友表 + mapFriendInfo curFriendInfoMap; + //将B添加到A的好友表中 + FriendInfo *pFriendInfo = (FriendInfo *)malloc(sizeof(FriendInfo)); + pFriendInfo->m_account = pReq->m_friendAccount; + pFriendInfo->m_status = 0; //未同意的好友,当拒绝时删除这条信息 + strncpy(pFriendInfo->m_userName, pUserInfo->m_userName, sizeof(pUserInfo->m_userName)); + std::pair Insert_Pair = curFriendInfoMap.insert(std::make_pair(pReq->m_friendAccount, pFriendInfo)); + if (Insert_Pair.second == true) + { + ChatLog << "A friend map Insert Successfully,user:"<second.size() <<",friend account:"<m_friendAccount<< endl; + } + else + { + ChatLog << "A friend map Insert fail" << endl; + } + + g_UserFriendInfoMap.insert(std::make_pair(m_account, curFriendInfoMap)); + //给其 B 用户 转发 A 添加好友的请求 + sendMsg(pUserInfo->m_socket, msg, sizeof(AddFriendInfoReq), CommandEnum_AddFriend,0,1); + //给客户端发送请求成功的信息,告诉客户端请求被受理了 + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, 0); + } +} + +/** + * @brief A:发送好友请求的客户端 + * B:接收好友请求的客户端 + */ +int Session::handleAddFriendResp(void*msg){ + AddFriendInfoResp* pResp = (AddFriendInfoResp*)msg; + LOGINFO("recv a AddFriendResp msg,status:%d\n",pResp->status); + //A.找到 A 的用户信息 + UserInfo *pUserInfo = NULL; + mapUserInfo::iterator UserInfoiter = g_UserInfoMap.find(pResp->m_senderAccount); + if (UserInfoiter != g_UserInfoMap.end()) + { + pUserInfo = UserInfoiter->second; + } + else{ + //没找到A用户信息,添加好友请求失败 + //给客户端发送响应失败的响应信息(不应该出现的情况) + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, -1); + return -1; + } + + + //C 1.从用户好友表找到 B 对应的好友表 + mapUserFriendInfo::iterator iter = g_UserFriendInfoMap.find(m_account); + if(iter!=g_UserFriendInfoMap.end()){ + //B用户存在好友表 + //2.用户好友表中查找A的账号是否在表中 + mapFriendInfo::iterator ite = iter->second.find(pResp->m_senderAccount); + if(ite!=iter->second.end()){ + LOGINFO("-----------error-----------\n"); + //找到了,这不应该出现的情况 + FriendInfo* pFriendInfo = ite->second; + if(pFriendInfo->m_status == 1){ + //已经是好友了,重复添加 不应该出现的情况 + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, -1); + return -1; + } + else if(pFriendInfo->m_status == -1){ + //B还未同意,暂时不给B发请求了 + //给客户端发送请求成功的信息 + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, 0); + } + } + else{ + //没有好友信息,需要添加好友信息 + //将B添加到A的好友表中 + FriendInfo *pFriendInfo = (FriendInfo *)malloc(sizeof(FriendInfo)); + pFriendInfo->m_account = pResp->m_senderAccount; + pFriendInfo->m_status = 1; //未同意的好友,当拒绝时删除这条信息 + strncpy(pFriendInfo->m_userName, pUserInfo->m_userName, sizeof(pUserInfo->m_userName)); + LOGINFO("[%d][%s]userName:%s,account:%d,status:%d\n",m_account,m_userName,pFriendInfo->m_userName,pFriendInfo->m_account,pFriendInfo->m_status); + + std::pair Insert_Pair = iter->second.insert(std::make_pair(pResp->m_senderAccount, pFriendInfo)); + if (Insert_Pair.second == true) + { + ChatLog << "B friend map Insert Successfully,user:" << m_account << " friend size:" << iter->second.size() << ",friend account:" << pResp->m_senderAccount << endl; + } + else + { + ChatLog << "B friend map Insert fail" << endl; + } + + //给其 A 用户 转发 B 添加好友的成功的响应 + sendMsg(pUserInfo->m_socket, pResp, sizeof(AddFriendInfoResp), CommandEnum_AddFriend); + //给客户端发送请求成功的信息,告诉客户端请求被受理了 + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, 0); + } + } + else{ + //B用户不存在好友表 + mapFriendInfo curFriendInfoMap; + //将A添加到B的好友表中 + FriendInfo *pFriendInfo = (FriendInfo *)malloc(sizeof(FriendInfo)); + pFriendInfo->m_account = pResp->m_senderAccount; + pFriendInfo->m_status = 1; //未同意的好友,当拒绝时删除这条信息 + strncpy(pFriendInfo->m_userName, pUserInfo->m_userName, sizeof(pUserInfo->m_userName)); + LOGINFO("[%d][%s]userName:%s,account:%d,status:%d\n",m_account,m_userName,pFriendInfo->m_userName,pFriendInfo->m_account,pFriendInfo->m_status); + + std::pair Insert_Pair = curFriendInfoMap.insert(std::make_pair(pResp->m_senderAccount, pFriendInfo)); + if (Insert_Pair.second == true) + { + ChatLog << "B friend map Insert Successfully,user:" << m_account << " friend size:" << iter->second.size() << ",friend account:" << pResp->m_senderAccount << endl; + } + else + { + ChatLog << "B friend map Insert fail" << endl; + } + + g_UserFriendInfoMap.insert(std::make_pair(m_account, curFriendInfoMap)); + //给其 A 用户 转发 B 添加好友的成功的响应 + sendMsg(pUserInfo->m_socket, pResp, sizeof(AddFriendInfoResp), CommandEnum_AddFriend); + //给客户端发送请求成功的信息,告诉客户端请求被受理了 + sendMsg(m_socket, NULL, 0, CommandEnum_AddFriend, 0); + } + + //将A用户的好友标志置位 + //C 1.从用户好友表找到 A 对应的好友表 + mapUserFriendInfo::iterator iter2 = g_UserFriendInfoMap.find(pResp->m_senderAccount); + if(iter2!=g_UserFriendInfoMap.end()){ + //A用户存在好友表 + //2.用户好友表中查找B的账号是否在表中 + mapFriendInfo::iterator ite2 = iter2->second.find(pResp->m_friendAccount); + if(ite2!=iter2->second.end()){ + //找到了 + FriendInfo* pFriendInfo = ite2->second; + pFriendInfo->m_status = 1; //同意 + LOGINFO("[%d]userName:%s,account:%d,status:%d\n",pResp->m_senderAccount,pFriendInfo->m_userName,pFriendInfo->m_account,pFriendInfo->m_status); + } + else{ + LOGINFO("==========出错了==========\n"); + } + } + else{ + LOGINFO("==========出错了==========\n"); + } +} + + diff --git a/server/MsgHandle.h b/server/MsgHandle.h new file mode 100644 index 0000000..a8ada68 --- /dev/null +++ b/server/MsgHandle.h @@ -0,0 +1,80 @@ +#ifndef _MSGHANDLE_H_ +#define _MSGHANDLE_H_ +#include "common.h" +#include "chatBase.h" +#include + +typedef enum +{ + RECV_HEAD = 0, + RECV_BODY +}recvType; + +//用于保存收到的MA的消息 +typedef struct _recvMsg +{ + _recvMsg() + { + head = NULL; + body = NULL; + bodyLen = 0; + } + ~_recvMsg() + { + if (head != NULL) + { + delete[] head; + head = NULL; + } + + if (body != NULL) + { + delete[] body; + body = NULL; + } + } + char *head; + char *body; + int bodyLen; +}recvMsg; + +class Session{ +public: + Session(int socket); + ~Session(); + +public: + int readEvent(); + int recvHead(); + int recvBody(); + int handleMsgBase(); + int handleMsg(recvMsg *rMsg); + static void sendMsg(int socket,void*buf,int bufLen,int type,int error = 0,int mode = 2); +public: + static int handleRegiste(void*arg,void*msg); + static int handleLogin(void*arg,void*msg); + static int handleLogout(void*arg,void*msg); + static int handleGroupChat(void*arg,void*msg); + int handlePrivateChat(void*msg); + int handleGetGroupList(void*msg); + int handleGetGroupInfo(void*msg); + int handleGetFriendInfo(void* msg); + int handleAddFriendReq(void*msg); + int handleAddFriendResp(void*msg); +private: + void cleanSession(); + void noticeUserLogin(UserInfo*userInfo); +private: + int m_socket; + int m_account; //会话账号 + char m_userName[64]; //用户名 + int m_isLogin; + recvType m_type; //接收消息类型 + char *m_head; //接收到的头信息 + int m_bufLen; //需要接收消息的长度 + int m_readPos; //当前读取到的长度 + char *m_body; //接收到的body + bool m_isFinish; //接收消息,用来判断是否接收完全 + // mapFriendInfo m_friendInfoMap; +}; +#endif \ No newline at end of file diff --git a/server/chatBase.h b/server/chatBase.h new file mode 100644 index 0000000..3b1fb11 --- /dev/null +++ b/server/chatBase.h @@ -0,0 +1,124 @@ +#ifndef _CHATBASE_H_ +#define _CHATBASE_H_ +#include "common.h" +#include +#include +using namespace std; +static int g_idIndex = 10000; +/** + * @brief 注册用户信息 + */ +struct RegistInfoReq{ + char m_userName[32]; + char m_password[32]; +}; + +struct RegistInfoResp{ + int m_account; +}; + +/** + * @brief 登录用户信息 + */ +struct UserInfo{ + char m_userName[32]; + char m_password[32]; + int m_account; //账号 + int m_socket; //句柄 +}; + +struct LoginInfoReq{ + int m_account; //账号 + char m_password[32]; +}; + +struct GroupChatInfo +{ + char m_groupName[32]; //群名称 + int m_account; //群账号 + int m_size; //群大小 +}; + +struct GetGroupListResp +{ + int m_size; //群数量大小 +}; + +struct GroupChatReq +{ + int m_UserAccount; //发送的账号 + int m_msgLen; + int m_type; //数据类型 0:文本,1:图片 ... + int m_GroupAccount; //发送群号 0:广播 +}; + +struct PrivateChatReq +{ + int m_UserAccount; //发送的账号 + int m_msgLen; + int m_type; //数据类型 0:文本,1:图片 ... + int m_FriendAccount; //发送好友账号 +}; + +struct GetGroupInfoReq +{ + int m_GroupAccount; //群号 0:广播 +}; + +struct GetGroupInfoResp +{ + char m_groupName[32]; //群名称 + int m_GroupAccount; //群号 0:广播 + int m_size; //群成员大小 +}; + +struct GroupUserInfo{ + char m_userName[32]; + int m_account; //账号 + int m_right; //权限 0:群成员 1:群管 2:群主 +}; + +/* 好友请求接口封装 */ +struct GetFriendInfoResp +{ + int m_size; //群成员大小 +}; + +struct AddFriendInfoReq +{ + int m_friendAccount; //好友账号 + int m_senderAccount; //发送端账号 + char m_reqInfo[64]; //请求信息 例如我是xxx +}; + +struct AddFriendInfoResp +{ + int m_friendAccount; //好友账号 + int m_senderAccount; //发送端账号 + int status; //同意0,不同意-1 +}; + +struct FriendInfo{ + char m_userName[32];//好友用户名 + int m_account; //账号 + int m_status; //是否添加成功 0:等待添加 1:同意 +}; + +//好友信息表,属于Session会话对象,即每个客户端一个好友信息表 +typedef std::map mapFriendInfo; //好友信息表 +typedef std::map mapUserFriendInfo; //用户好友信息表 + +//account,other +typedef std::map mapGroupChatInfo; //群信息表 +typedef std::map mapAccountInfo; //注册用户表 +typedef std::map mapUserInfo; //在线用户表 + + +static mapGroupChatInfo g_GroupCharInfoMap; //群信息表 +static mapAccountInfo g_AccountInfoMap; //注册账户信息表 +static mapUserInfo g_UserInfoMap; //在线用户信息表 +static mapUserFriendInfo g_UserFriendInfoMap; //用户好友信息表 + +static pthread_mutex_t _mxMessage; + +#endif diff --git a/server/chatTask.cpp b/server/chatTask.cpp new file mode 100644 index 0000000..c40a96d --- /dev/null +++ b/server/chatTask.cpp @@ -0,0 +1,61 @@ +#include "chatTask.h" + +void *taskThread(void *arg){ + printf("-------------------- new connect --------------------\n"); + // pthread_mutex_lock(&_mxMessage); //lock the mutex + // pthread_mutex_unlock(&_mxMessage); //unlock the mutex + int clientFd = *((int *)arg); + char recvMsg[1024*2]; + int recvLen; + int head_len = sizeof(DeMessageHead); + + free(arg); + arg = NULL; + + Session session(clientFd); + while (1) + { + if(session.readEvent() == RET_EXIT) + { + close(clientFd); + return NULL; + } +#if 0 + memset(recvMsg,'\0',sizeof(recvMsg)); + recvLen = read(clientFd, recvMsg, sizeof(DeMessageHead)); + if (recvLen <= 0) + { //下线 + printf("offline\n"); + close(clientFd); + return NULL; + } + printf("readLen:%d,HeadLen:%d\n",recvLen,sizeof(DeMessageHead)); + memmove((void*)&headTmp,recvMsg,sizeof(DeMessageHead)); + printf("mark:%s,encoded:%d,length:%d,version:%d\n",headTmp.mark,headTmp.encoded,headTmp.length,headTmp.version); + + memset(recvMsg,'\0',sizeof(recvMsg)); + recvLen = read(clientFd, recvMsg, sizeof(DeMessagePacket)); + printf("readLen:%d,PacketLen:%d\n",recvLen,sizeof(DeMessagePacket)); + if (recvLen <= 0) + { //下线 + printf("offline\n"); + close(clientFd); + return NULL; + } + memmove((void*)&packetTmp,recvMsg,sizeof(DeMessagePacket)); + printf("command:%d,error:%d,,mode:%d,sequence:%d\n",packetTmp.command,packetTmp.error,packetTmp.mode,packetTmp.sequence); + + memset(recvMsg,'\0',sizeof(recvMsg)); + recvLen = read(clientFd, recvMsg, headTmp.length - sizeof(DeMessagePacket)); + printf("readLen:%d,HeadLen:%d\n",recvLen,sizeof(DeMessageHead)); + if (recvLen <= 0) + { //下线 + printf("offline\n"); + close(clientFd); + return NULL; + } + printf("msg:%s\n",recvMsg); +#endif + } + return NULL; +} \ No newline at end of file diff --git a/server/chatTask.h b/server/chatTask.h new file mode 100644 index 0000000..018945e --- /dev/null +++ b/server/chatTask.h @@ -0,0 +1,8 @@ +#ifndef _CHATTASK_H_ +#define _CHATTASK_H_ +#include "common.h" + +void * taskThread(void *arg); + + +#endif \ No newline at end of file diff --git a/server/common.cpp b/server/common.cpp new file mode 100644 index 0000000..db23e7a --- /dev/null +++ b/server/common.cpp @@ -0,0 +1,20 @@ +#include"common.h" +int getSeqNum() +{ + static int num = 0; + if (num++ >= 0xEFFFFFFF - 1) + { + num = 0; + } + return num; +} + +int getAccountNum() +{ + static int account = 10000; + if (account++ >= 0xEFFFFFFF - 1) + { + account = 10000; + } + return account; +} \ No newline at end of file diff --git a/server/common.h b/server/common.h new file mode 100644 index 0000000..b9fe871 --- /dev/null +++ b/server/common.h @@ -0,0 +1,84 @@ +#ifndef _COMMON_H_ +#define _COMMON_H_ +#include "DeThread.h" +#include "chatTask.h" +#include "chatBase.h" +#include "MsgHandle.h" +//线程相关 +#include +//网络相关 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +//c++ +#include +#include + +#define RET_OK 0 +#define RET_ERROR -1 +#define RET_AGAIN -2 //重新读取 +#define RET_EXIT -3 //客户端退出 + + +#ifndef FILENAME +#define FILENAME (__FILE__) +#endif + +#ifndef FILEFUNCTION +#define FILEFUNCTION (__FUNCTION__) +#endif + +#ifndef FILELINE +#define FILELINE (__LINE__) +#endif + +#define ChatLog std::cout<<"[ "<>" format, FILENAME,FILELINE, FILEFUNCTION ,##__VA_ARGS__); \ + } + +//De 协议包头 +struct DeMessageHead{ + char mark[2]; // "DE" 认证deroy的协议 + char version; + char encoded; //0 不加密,1 加密 + int length; +}; + +struct DeMessagePacket +{ + /* data */ + int mode; //1 请求,2 应答,3 消息通知 + int error; //0 成功,非0,对应的错误码 + + int sequence; //序列号 + int command; //命令号 +}; + +//命令枚举 +enum{ + CommandEnum_Registe, + CommandEnum_Login, + CommandEnum_Logout, + CommandEnum_GroupChat, + CommandEnum_AddFriend, + CommandEnum_delFriend, + CommandEnum_PrivateChat, + CommandEnum_CreateGroup, + CommandEnum_GetGroupList, + CommandEnum_GetGroupInfo, + CommandEnum_GetFriendInfo, +}; + +int getAccountNum(); +int getSeqNum(); +#endif \ No newline at end of file diff --git a/server/main.cpp b/server/main.cpp new file mode 100644 index 0000000..ce7021d --- /dev/null +++ b/server/main.cpp @@ -0,0 +1,81 @@ +#include "common.h" + +using namespace std; +int main(int argc,char* argv[]) +{ + int default_port = 8000; + int optch = 0; + while ((optch = getopt(argc, argv, "s:p:")) != -1) + { + switch (optch) + { + case 'p': + default_port = atoi(optarg); + LOGINFO("port: %s\n", optarg); + break; + case '?': + LOGINFO("Unknown option: %c\n", (char)optopt); + break; + default: + break; + } + } + pthread_mutex_init(&_mxMessage, NULL); + // pthread_mutex_lock(&_mxMessage); //lock the mutex + + // pthread_mutex_unlock(&_mxMessage); //unlock the mutex + /*声明服务器地址和客户链接地址*/ + struct sockaddr_in server_addr, client_addr; + socklen_t client_len; + + /*声明服务器监听套接字和客户端链接套接字*/ + int listen_fd,connect_fd; + + /*(1) 初始化监听套接字listenfd*/ + listen_fd = socket(AF_INET, SOCK_STREAM, 0); + if (listen_fd == -1) + { + perror("Socket Error:"); + return 0; + } + + /*(2) 设置服务器sockaddr_in结构*/ + bzero(&server_addr, sizeof(server_addr)); + server_addr.sin_family = AF_INET; + server_addr.sin_addr.s_addr = htonl(INADDR_ANY); //任意地址 + server_addr.sin_port = htons(default_port); + + // 设置允许socket立即重用 + setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, (const char*)&listen_fd, sizeof(listen_fd)); + + /*(3) 绑定套接字和端口*/ + if (bind(listen_fd, (struct sockaddr *)&server_addr, sizeof(server_addr)) == -1) + { + perror("Bind error:"); + return 0; + } + + /*(4) 监听客户请求*/ + if (listen(listen_fd, 4) == -1) + { + perror("Listen error:"); + return 0; + } + /*(5) 接受客户请求*/ + for (;;) + { + client_len = sizeof(client_addr); + connect_fd = accept(listen_fd, (struct sockaddr *)&client_addr, &client_len); + if (connect_fd < 0) + { + perror("accept error"); + return 0; + } + LOGINFO("Connect from %s:%u...\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port)); + int* argv = (int *)malloc(sizeof(int)); + *argv = connect_fd; + CREATE_THREAD(NULL,1024*4,true,taskThread,(void*)argv,NULL); + } + close(listen_fd); + return 0; +} \ No newline at end of file diff --git a/server/makefile b/server/makefile new file mode 100644 index 0000000..462acc4 --- /dev/null +++ b/server/makefile @@ -0,0 +1,12 @@ +TARGET=server +SRC = $(wildcard *.cpp *.c) +OBJ = $(patsubst %.cpp *.c,%.o,$(SRC)) +DEFS = +CFLAGS = -g +CC =g++ +LIBS = -lpthread +$(TARGET):$(OBJ) + $(CC) $(CFLAGS) $(DEFS) -o $@ $^ $(LIBS) +.PHONY: +clean: + rm -rf *.o $(TARGET) \ No newline at end of file diff --git a/server/server b/server/server new file mode 100644 index 0000000..0b2f830 Binary files /dev/null and b/server/server differ diff --git a/src/addFriend.png b/src/addFriend.png new file mode 100644 index 0000000..5b73249 Binary files /dev/null and b/src/addFriend.png differ diff --git a/src/chatroom.jpg b/src/chatroom.jpg new file mode 100644 index 0000000..15822ec Binary files /dev/null and b/src/chatroom.jpg differ diff --git a/src/groupChat.png b/src/groupChat.png new file mode 100644 index 0000000..0a8f6fb Binary files /dev/null and b/src/groupChat.png differ diff --git a/src/login.png b/src/login.png new file mode 100644 index 0000000..3cc9caa Binary files /dev/null and b/src/login.png differ diff --git a/src/privatechat.png b/src/privatechat.png new file mode 100644 index 0000000..9792b36 Binary files /dev/null and b/src/privatechat.png differ diff --git a/src/regeist.png b/src/regeist.png new file mode 100644 index 0000000..ef6535a Binary files /dev/null and b/src/regeist.png differ