📄 main.h
字号:
/*
取之于斯,用之于斯。
我自己的学习成长,有一大部分要归功于在互联网上接触到的一些开源的代码和开源项目。作者的精湛技艺,尤其是他们博大的胸怀,让我敬仰不已。
因此我也将自己写的一些代码及工具,只要是比较完整的,不涉及到工作中保密信息的,整理出来。放到网上,希望能对其他人有用。
你可以自由的拷贝,分发,使用这些代码,最好是能提到它的出处,我保留除此之外的所有权利。由于是非商业性的软件及代码,在使用过程中造成的所有损失,我不承担任何责任。 :)
我的邮件:pankkk@hotmail.com
我的名字:潘凯
欢迎和我交流技术方面的问题。
我已经发布的一些代码及工具。这些代码及工具我一般发布在vchelp及vccode的论坛上,这两个地方是我常去的地方,只是近来都是潜水,很少发言。:)
1、一个从codeproject下载文章及源码的工具,可以将上面所有的文章及源码都下载到本机,并保留原来的分类信息,去掉页面上的广告。发布日期2003/1
这个软件是用MFC做的。现在可能已经不能用了,因为当时不用登录也可以下载源码,现在必须要是会员,而且要登录后才能下载。而且网站的组织结构也变了。有兴趣的朋友可以自己试着改源码。
2、一个上网计时的小软件。发布时期2003/11
这个软件主要也是自用,当时家里办了ADSL上网,一个月60小时。当时下了一些计时软件,感觉不好用,功能太多,就自己写了一个。界面比较简陋,但也够用了。
3、一个点对点的局域网聊天软件,有QQ的Emotion功能,可以一对多的传文件。发布日期2004/12,发布版本1.13。
界面部分用WTL做的,聊天用UDP协议,传文件是TCP协议。由于不需要服务器,很多功能实现起来还是很麻烦的。
*/
#ifndef __MAIN_H__
#define __MAIN_H__
#include "stdafx.h"
#include "def.h"
#include "maindlg.h"
//PK 2004-08-31
//PK start receive thread
void start_receive(void *);
class CSender
{ //PK 2004/09/01 - 10/25
public:
struct _user {
_user() : is_online(false){}
_user(string u, string m) : user_name(u), machine_name(m), is_online(false){}
string user_name;
string machine_name;
_my_time last_online;
bool is_online;
};
typedef map<u_long, _user> users_type; //PK the key is address
//PK
public:
static bool start();
static bool close();
//PK the receiver thread, receive message and parse it
static unsigned __stdcall thread_receiver(void * argu);
//PK send msg
private:
static bool _broadcast_message(CPChar buf, int len);
static bool _p2p_message(CPChar buf, int len, u_long address);
static bool _send_message_to_all(CPChar buf, int len);
//PK broadcast the login and logout message
public:
static bool login(); //PK broatcast i'm login
static bool logout(); //PK broatcast i'm logout
static bool online(u_long addr); //PK notice someone i'm online
static bool online(); //PK notice everyone i'm online
//PK send a message
static bool said_to_all(CRStr data);
static bool whisper(CRStr data, u_long addr);
//PK rename
public:
static bool rename(const string& username);
static bool name_conflict(u_long address);
static bool is_name_conflict(const string & username);
public: //PK update user and task state
static void update_users();
static void update_tasks();
public: //PK name
static void set_myname(CRStr name){m_myname = name;};
static string get_myname(){return m_myname;}
static string get_user_name(u_long addr);
static string get_full_name(u_long addr);
private:
static string _get_peer_name(u_long addr);
public: //PK file transmit
static bool send_a_file(_task_send_file * task);
static bool confirm_recv_a_file(_task_recv_file * task);
static bool reject_a_file(_task_recv_file * task);
static unsigned __stdcall listen_file_send_thread(void * para);
static unsigned __stdcall recv_file_thread(void * para);
static unsigned __stdcall send_file_thread(void * para);
private:
static bool _complete_recv_file(_task_recv_file * task, error_no err);
public: //PK tasks
static _task_send_file * add_a_send_file_task(CRStr fname, addresses_type & users);
static _task_recv_file * add_a_recv_file_task(u_long id, CRStr fname, DWORD file_size, u_long addr);
static bool is_task_exist(u_long task_id);
private:
static bool _erase_a_task(tasks_type & tasks, _task * task);
static _task_recv_file * _find_a_recv_task(u_long addr);
static bool _erase_a_send_user(_task_send_file * task, u_long addr);
static bool _task_is_canceled(u_long task_id, u_long addr);
public: //PK other
static void trim_string(string & str);
static bool is_emotion_command(CRStr command, int & index, u_long & addr);
static bool emotion(int emotion_index, u_long addr = 0);
static void modify_blacklist(u_long addr);
private:
static int write_msg_head_to_buf(flag_type flag, char * buf, char ** pos);
static void _a_user_online(CRStr username, u_long addr);
static bool _is_newest_version(version_type ver);
static bool _is_user_online(u_long addr);
static string _get_file_name(CRStr path);
static u_long _get_user_addr(CRStr name);
private: //PK the command msg handler
static bool on_login(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_logout(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_online(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_say(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_whisper(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_rename(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_name_conflict(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_recv_file(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_confirm_recv_file(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_reject_file(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_task_cancel(_msg_head * msg_head, CPChar msg_body, u_long addr);
static bool on_emotion(_msg_head * msg_head, CPChar msg_body, u_long addr);
private:
static SOCKET m_sock_recv;
static SOCKET m_sock_send;
static SOCKADDR_IN m_addr_brat;
static SOCKADDR_IN m_addr_recv;
static users_type m_users;
static users_type m_blacklist;
static SOCKADDR_IN m_addr_p2p;
static string m_myname;
static u_long m_myaddr;
static CMainDlg * m_pwindow; //PK main window
static u_long m_conflict_addr; //PK 有名字冲突的地址,对于此地址发送过来的信息不再判断是否和自己重名
static tasks_type m_send_file_tasks;
static tasks_type m_recv_file_tasks;
public:
static fstream m_history;
#ifdef _DEBUG
static fstream m_log;
#endif
static CLock m_locker;
};
#endif //__MAIN_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -