Returned directory
My plan for this project is as follows:
Playcardclient and playcardserver represent the client and server respectively. Generally, the server uses the console to display information. For a newbie two years ago, I used winform to make it clearer, I don't want to change the new version, because the logic on the server side is very simple-only responsible for communication and database operations.
Commonclasslibrary is a class library. Both the server and client depend on this class library (add references to this class library ). This class library stores custom communication protocols, custom channel of TCP socket, and entity classes to be used by both the client and server,
The testproject project is used to conduct some component research experiments, such as licensing procedures and card placement controls. I didn't set up a unit test project. That's not a good habit, but I didn't understand the nunit technology two years ago.
For Database Planning, in this project, my requirements for databases are:
Verifies login and obtains user information after login.
After the Board is over, change the user score field in the database
* Other data is stored in the memory of the server.
Therefore, my database is designed as follows:
Each field involves many business logic:
Userid is the login name (Primary Key), and username is the display nickname.
Islogin indicates whether the user has logged on. 1 indicates yes, 0 indicates no, this field is changed to 1 after logging on, and 0 after leaving the hall, this prevents the simultaneous login of multiple user names.
Imageindex indicates the user's profile picture. It is an integer that corresponds to the image name of the image library on the client.
Score: record the user's score. This field is changed after each round.
Port. This field is used to record the user's port. In other words, I can't help designing this field to restrict user cheating and log on to two accounts on the same machine at the same time. But at that time, I only had one development machine, so I could not simulate four different users. I didn't want to install a virtual machine, so I added the port field, when adding each user, specify a different port number for them. In this way, log on to four users on one machine at the same time, and the program can be considered as a user on different machines.
In the original plan, user registration was performed on the web interface, but I did not do this website later. So I manually added five users as follows (see the following SQL capture record ):
Correspondingly, there are only three static methods for database operations on the server, which are located in the DB class, respectively:
1) Login
This method is called for verification when a user logs on. Note: If the islogin field is 1 before login, the login will fail.
2) updatestatus
If the login succeeds, change the islogin field from 0 to 1. When an exception is thrown offline, change the islogin field from 1 to 0.
3) updatescore
After the Board is over, change the score based on the userid.
Well, the preparation is basically complete. Next we will start our first step to establish a communication mechanism in the game hall. This involves multiple technologies such as multithreading, TCP socket communication, asynchronous mechanism, and serialization.