// 플레이어가 범위내를 벚어났을 때 알리기. public void ResponseRemoveNearPlayer(CGameUser user, CGameUser user2) { CPacket response = CPacket.create((short)PROTOCOL.REMOVE_NEAR_PLAYER_RES); PushPlayerrData(user2, response); user.send(response); }
public static void Exit_Room(CGameUser user) { if (user.myRoom != null) { ExitUserRoom(user); } }
public static void remove_user(CGameUser user) { lock (userlist) { userlist.Add(user); } }
// 내 케릭 가져다주기. public void ResponseGetMyPlayer(CGameUser user) { CPacket response = CPacket.create((short)PROTOCOL.GET_MY_PLAYER_RES); PushPlayerrData(user, response); user.send(response); }
// 유저 패킷 패키징. public void PushPlayerrData(CGameUser user, CPacket response) { response.push(user.player.UserId); response.push(user.player.MoveSpeed); response.push(user.player.NearRange); response.push(user.player.CurrentPosX); response.push(user.player.CurrentPosY); }
// 클라이언트가 접속 완료 하였을 때 호출됩니다. // n개의 워커 스레드에서 호출될 수 있으므로 공유 자원 접근시 동기화 처리를 해줘야 합니다. static void on_session_created(CUserToken token) { CGameUser user = new CGameUser(token); lock (userlist) { userlist.Add(user); } }
/// <summary> /// 클라이언트가 접속 완료 하였을 때 호출됩니다. /// n개의 워커 스레드에서 호출될 수 있으므로 공유 자원 접근시 동기화 처리를 해줘야 합니다. /// </summary> /// <returns></returns> static void OnSessionCreated(CUserToken _token) { CGameUser _user = new CGameUser(_token); lock (listGameUser) { listGameUser.Add(_user); } }
public void SendChatMessage(CGameUser owner, string text) { foreach (var user in userList) { CPacket response = CPacket.create((short)PROTOCOL.CHAT_MSG_ACK); response.push(owner.player.UserId); response.push(text); user.send(response); } }
public static void sendAllClient(CGameUser user, CPacket msg) { foreach (CGameUser gameUser in userlist) { if (user != gameUser) { gameUser.send(msg); } } }
public void DisconnectedUser(CGameUser user) { userList.Remove(user); foreach (var otherUser in userList) { CPacket response = CPacket.create((short)PROTOCOL.DISCONECTED_PLAYER_RES); response.push(user.player.UserId); otherUser.send(response); } }
public static void RemoveUser(CGameUser user) { if (user.myRoom != null) { ExitUserRoom(user); } lock (listGameUser) { listGameUser.Remove(user); } }
public void BroadCast(CPacket _packet, CGameUser _senderClient) { foreach (CGameUser _client in listGameUser) { if (_client.token != _senderClient.token) { _client.token.SendCode(_packet); } } //this.token.send(msg); }
// 서버 접속. public void UserEntedServer(CGameUser user) { // 서버에 유저 추가. userList.Add(user); CPacket response = CPacket.create((short)PROTOCOL.ENTER_GAME_ROOM_RES); response.push(user.player.UserId); // 서버의 모든 유저에게 나 왔다고 알림. ResponsePacketUsers(userList, response); }
public CPlayer(CGameUser user, int userId) { this.owner = user; UserId = userId; Random random = new Random(); CurrentPosX = 0; CurrentPosY = 0; }
public void RequestPlayerMove(CGameUser user) { var nearUsers = userList; foreach (var userData in nearUsers) { CPacket response = CPacket.create((short)PROTOCOL.PLAYER_MOVE_RES); response.push(user.player.UserId); response.push(user.player.CurrentPosX); response.push(user.player.CurrentPosY); userData.send(response); } }
public bool UserInsert(CGameUser _user) { if (playerCount < playerMax) { listGameUser.Add(_user); _user.m_SN = RoomuserSn; ++RoomuserSn; ++playerCount; return(true); } else { return(false); } }
// 플레이어 이동. public void RequestPlayerMove(CGameUser user) { // 이동한 플레이어에게 서버에 이동한거 등록했다고 답장 CPacket response = CPacket.create((short)PROTOCOL.PLAYER_MOVE_RES); PushPlayerrData(user, response); user.send(response); // 이동한 녀석의 좌표를 다른 플레이어들에게 보내기 foreach (var userData in user.player.listNearbyUser) { PushPlayerrData(user, response); userData.send(response); } }
static void ExitUserRoom(CGameUser _user) { CPacket _response2 = CPacket.Create((short)LOGIN_PROTO.ROOM_EXIT_OTHER); _response2.WriteInt(_user.m_SN); _user.myRoom.BroadCast(_response2, _user); _user.myRoom.listGameUser.Remove(_user); --_user.myRoom.playerCount; if (_user.myRoom.playerCount <= 0) { Console.WriteLine(string.Format("delRoom {0}", _user.myRoom.name)); RoomRemove(_user.myRoom); } }
public void ResponsePlayers(CGameUser user) { CPacket response = CPacket.create((short)PROTOCOL.PLAYERS_RES); response.push(userList.Count); for (int i = 0; i < userList.Count; ++i) { response.push(userList[i].player.UserId); response.push(userList[i].player.CurrentPosX); response.push(userList[i].player.CurrentPosY); } user.send(response); }
public void AddNewPlayerRes(CGameUser newUser) { foreach (var user in userList) { if (user.player.UserId == newUser.player.UserId) { continue; } CPacket response = CPacket.create((short)PROTOCOL.ADD_NEW_PLAYER_RES); response.push(newUser.player.UserId); response.push(newUser.player.CurrentPosX); response.push(newUser.player.CurrentPosY); user.send(response); } }
public static List <CGameUser> GetNearbyUsers(CGameUser targetPlayer, List <CGameUser> listUSer) { int range = 5; List <CGameUser> listNearUsers = new List <CGameUser>(); for (int i = 0; i < listUSer.Count; ++i) { if ((targetPlayer.player.CurrentPosX + range > listUSer[i].player.CurrentPosX && targetPlayer.player.CurrentPosX - range < listUSer[i].player.CurrentPosX) && (targetPlayer.player.CurrentPosY + range > listUSer[i].player.CurrentPosY && targetPlayer.player.CurrentPosY - range < listUSer[i].player.CurrentPosY)) { listNearUsers.Add(listUSer[i]); } } return(listNearUsers); }
public void UserEntedServer(CGameUser user) { // 대기 리스트에 중복 추가 되지 않도록 체크. if (this.userList.Contains(user)) { return; } // 서버에 유저 추가. userList.Add(user); CPacket response = CPacket.create((short)PROTOCOL.ENTER_GAME_ROOM_RES); response.push(user.player.UserId); user.send(response); AddNewPlayerRes(user); }
public static bool RoomConnect(CGameUser _user, int _roomNum) { Console.WriteLine("Program RoomConnect _user:{0} _roomNum:{1}", _user, _roomNum); if (listRoom.Count == 0) { return(false); } bool _connect; lock (listRoom) { _connect = listRoom[_roomNum].UserInsert(_user); } if (_connect) { _user.SetRoom(listRoom[_roomNum]); } return(_connect); }
public static void RoomCreate(CGameUser _user, string _roomName) { Console.WriteLine("Program RoomCreate _user:{0} _name:{1}", _user, _roomName); CRoom _room = new CRoom(); _room.name = _roomName; _room.UserInsert(_user); _user.SetRoom(_room); lock (listRoom) { listRoom.Add(_room); //Room number 받아오는 부분에 버그가 있음... //1 -> 2 후에... //1 or 2제거된후에.... //받아오면~~~~~ 2 //2 2 번이된다 오류임....~~~ //_room.number = listRoom.Count(); _room.number = roomIdentity; roomIdentity++; } }
// 범위내 케릭터 삭제. public void RemoveNearPlayer(CGameUser user) { listNearbyUser.Remove(user); }
// 범위내 케릭터 추가. public void AddNearPlayer(CGameUser user) { listNearbyUser.Add(user); }
public CPlayer(CGameUser user, int userId) { owner = user; UserId = userId; }