Пример #1
0
 void userSendingLoop(object userObject)
 {
     clsUser user = userObject as clsUser;
 }
Пример #2
0
        void sendNewCoordinates(String gameName,clsUser user)
        {
            messageUsersFromServer mufs = new messageUsersFromServer();
            lock (games) {
                mufs.users=new userInfo[games[gameName].Users.Count];
                int i=0;
                foreach (var userName in games[gameName].Users.Keys) {
                    userInfo ui = new userInfo();
                    ui.color = games[gameName].Users[userName].Color;
                    ui.name = userName;
                    ui.x = games[gameName].Users[userName].X;
                    ui.y = games[gameName].Users[userName].Y;

                    mufs.users[i] = ui;
                    i++;
                }
                foreach (var userName in games[gameName].Users.Keys) {
                    if (games[gameName].Users[userName].SendClient != null && games[gameName].Users[userName].SendClient.Connected) {
                        mufs.sendMessage(games[gameName].Users[userName].SendClient.GetStream());
                    }
                }
            }
        }
Пример #3
0
        void userListenLoop(clsUser user)
        {
            netMessage message = new netMessage();
            while (true)
            {
                try {
                    message = message.readMessage(user.ListenClient.GetStream());
                } catch (Exception ex) {
                    return;
                }
                switch (message.code)
                {
                    case netMessageType.userToServer:
                        lock (games)
                        {
                            user.X = (message as messageUserToServer).x;
                            user.Y = (message as messageUserToServer).y;
                            sendNewCoordinates(user.Game.Map.name,user);
                        }

                        break;
                }
            }
        }
Пример #4
0
 clsUser newUser(newUserRequest num, NetworkStream stream)
 {
     newUserResponse nur = new newUserResponse();
     if (users.Keys.Contains(num.name)) {
         nur.okey = false;
         nur.reason = "Игрок с таким именем уже играет на сервере.";
         nur.sendMessage(stream);
         stream.Close();
         return null;
     } else {
         clsUser user = new clsUser();
         user.Color = num.color;
         user.Name = num.name;
         user.Game = games[num.mapName];
         lock(games){
             games[num.mapName].Users.Add(user.Name,user);
             users.Add(user.Name, user);
         }
         nur.okey = true;
         nur.sendMessage(stream);
         return user;
     }
 }