public FormServer(UnityCommon.Server s, int portnum) { string server_name = string.Format("{0}-{1}", s, portnum); Log.logger = log4net.LogManager.GetLogger(server_name); log4net.Config.XmlConfigurator.Configure(); InitializeComponent(); switch (s) { case UnityCommon.Server.Login: svr = new User.LoginServer(this, s, portnum); break; case UnityCommon.Server.Lobby: svr = new User.LobbyServer(this, s, portnum); break; case UnityCommon.Server.Room: svr = new User.RoomServer(this, s, portnum); break; case UnityCommon.Server.Master: svr = new Master.MasterServer(this, s, portnum); break; } Text = string.Format("Simple Server : {0}", server_name); }
public BaseServer(FormServer f, UnityCommon.Server s, int portnum) { this.form = f; this.type = s; this.name = string.Format("{0}-{1}", s, portnum); listenAddr.m_ip = Server.Properties.Settings.Default.ListenIp; listenAddr.m_port = (ushort)portnum; }
static void Main(string[] args) { UnityCommon.Server launchMode = UnityCommon.Server.Login; int portnum = 0; if (args.Length >= 1) { switch (args[0]) { case "Login": launchMode = UnityCommon.Server.Login; break; case "Lobby": launchMode = UnityCommon.Server.Lobby; break; case "Room": launchMode = UnityCommon.Server.Room; break; case "Master": launchMode = UnityCommon.Server.Master; break; } } // 포트 설정 if (args.Length == 2) { portnum = int.Parse(args[1]); } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new FormServer(launchMode, portnum)); }
void Start() { this.m_Core = new CoreClientNet(); m_Core.Attach(proxy, stub); // 서버가 보낸 로그인인증 결과패킷을 처리합니다 stub.reponse_Login = (ZNet.RemoteID remote, ZNet.CPackOption pkOption, bool bResult) => { printf("로그인 인증 결과" + bResult); return(true); }; // 서버로부터 받은 메세지 stub.Chat = (ZNet.RemoteID remote, ZNet.CPackOption pkOption, string txt) => { printf(txt); return(true); }; // 서버이동 시도에 대한 실패 이벤트 m_Core.move_fail_handler = () => { printf("서버이동 처리가 실패하였습니다."); }; // 서버에 입장된 시점 m_Core.server_join_handler = (ZNet.ConnectionInfo info) => { if (info.moved) { // 서버이동이 성공한 시점 : 위치를 목표했던 서버로 설정 server_now = server_tag; printf("서버이동성공 [{0}:{1}] {2}", info.addr.m_ip, info.addr.m_port, server_now); } else { // 최초 입장의 성공시점 : 위치를 로그인 서버로 설정 server_now = UnityCommon.Server.Login; printf("서버입장성공 {0}", server_now); // 최초 로그인 DB인증 시도 요청 proxy.request_Login(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Basic, "철수", "abcd"); } }; // 서버에 퇴장된 시점 m_Core.server_leave_handler = (ZNet.ConnectionInfo info) => { if (info.moved) { printf("서버이동을 위해 퇴장, 이동할서버 [{0}:{1}]", info.addr.m_ip, info.addr.m_port); } else { printf("서버퇴장성공"); } // 어떤 서버에서 퇴장하든 재접속시 최초접속과 구분하기 위하여 로그인 서버로 세팅해둡니다 server_now = UnityCommon.Server.Login; }; // 서버에 연결된 시점 m_Core.server_connect_result_handler = (bool isConnectSuccess) => { if (isConnectSuccess) { printf("Connected!"); } else { printf("Connect Fail!"); } }; m_Core.message_handler = (ZNet.ResultInfo result) => { string str_msg = "Msg : "; str_msg += result.msg; printf(str_msg); }; printf("프로그램 시작"); // 최초 로그인 시도 m_Core.Connect( "127.0.0.1", 20000 /*tcp port*/, 0,/*protocol version*/ 0 /*udp disable=0*/, true /*mobile*/, false/*RecoveryUse*/ ); }
void OnGUI() { #if UNITY_ANDROID || UNITY_IPHONE GUI.skin.label.fontSize = 30; GUI.skin.button.fontSize = 30; #endif // Received text. GUILayout.BeginVertical(); currentScrollPos = GUILayout.BeginScrollView( currentScrollPos, GUILayout.MaxWidth(Screen.width), GUILayout.MinWidth(Screen.width), GUILayout.MaxHeight(Screen.height - 100), GUILayout.MinHeight(Screen.height - 100) ); foreach (string text in this.received_texts) { GUILayout.BeginHorizontal(); GUI.skin.label.wordWrap = true; GUILayout.Label(text); GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); GUILayout.EndVertical(); // Input. GUILayout.BeginHorizontal(); this.input_text = GUILayout.TextField( this.input_text, GUILayout.MaxWidth(Screen.width - 100), GUILayout.MinWidth(Screen.width - 100), GUILayout.MaxHeight(50), GUILayout.MinHeight(50) ); int screenW = Screen.width / 2 / 10; int screenH = Screen.height / 2 / 10; if (GUI.Button(new Rect(Screen.width / 2 - screenW - screenW, screenH * 8, screenW, screenH), "Send")) { if (this.server_now != UnityCommon.Server.None) // 서버에 연결되있을때만 패킷을 보내기 위해 { // 서버로 채팅 메세지 보내기 proxy.Chat(RemoteID.Remote_Server, CPackOption.Basic, this.input_text); this.input_text = ""; } } if (GUI.Button(new Rect(Screen.width / 2 - screenW - screenW - screenW, screenH * 9, screenW, screenH), "goLogin")) { if (this.server_now != UnityCommon.Server.None) // 서버에 연결되있을때만 패킷을 보내기 위해 { this.server_tag = UnityCommon.Server.Login; this.proxy.server_move(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Basic, (int)this.server_tag); } } if (GUI.Button(new Rect(Screen.width / 2 - screenW - screenW, screenH * 9, screenW, screenH), "goLobby")) { if (this.server_now != UnityCommon.Server.None) // 서버에 연결되있을때만 패킷을 보내기 위해 { this.server_tag = UnityCommon.Server.Lobby; this.proxy.server_move(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Basic, (int)this.server_tag); } } if (GUI.Button(new Rect(Screen.width / 2 - screenW, screenH * 9, screenW, screenH), "goRoom")) { if (this.server_now != UnityCommon.Server.None) // 서버에 연결되있을때만 패킷을 보내기 위해 { this.server_tag = UnityCommon.Server.Room; this.proxy.server_move(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Basic, (int)this.server_tag); } } GUILayout.EndHorizontal(); }
public CClient() { m_Core = new ZNet.CoreClientNet(); proxy = new Rmi.Proxy(); stub = new Rmi.Stub(); m_Core.Attach(proxy, stub); // 서버가 보낸 로그인인증 결과패킷을 처리합니다 stub.reponse_Login = (ZNet.RemoteID remote, ZNet.CPackOption pkOption, bool bResult) => { Console.WriteLine("로그인 인증 결과" + bResult); return(true); }; // 서버로부터 받은 메세지 stub.Chat = (ZNet.RemoteID remote, ZNet.CPackOption pkOption, string txt) => { Console.WriteLine(txt); return(true); }; // 서버이동 시도에 대한 실패 이벤트 m_Core.move_fail_handler = () => { Console.WriteLine("서버이동 처리가 실패하였습니다."); }; // 서버로의 입장이 성공한 이벤트 처리 m_Core.server_join_handler = (ZNet.ConnectionInfo info) => { if (info.moved) { // 서버이동이 성공한 시점 : 위치를 목표했던 서버로 설정 server_now = server_tag; Console.WriteLine("서버이동성공 [{0}:{1}] {2}", info.addr.m_ip, info.addr.m_port, server_now); } else { // 최초 입장의 성공시점 : 위치를 로그인 서버로 설정 server_now = UnityCommon.Server.Login; Console.WriteLine("서버입장성공 {0}", server_now); // 최초 로그인 DB인증 시도 요청 proxy.request_Login(ZNet.RemoteID.Remote_Server, ZNet.CPackOption.Basic, "철수", "abcd"); } }; // 서버로의 퇴장이 처리된 이벤트 처리 m_Core.server_leave_handler = (ZNet.ConnectionInfo info) => { if (info.moved) { Console.WriteLine("서버이동을 위해 퇴장, 이동할서버 [{0}:{1}]", info.addr.m_ip, info.addr.m_port); } else { Console.WriteLine("서버퇴장성공"); } // 어떤 서버에서 퇴장하든 재접속시 최초접속과 구분하기 위하여 로그인 서버로 세팅해둡니다 server_now = UnityCommon.Server.Login; }; // 예외 상황에 대한 정보 출력 이벤트 m_Core.message_handler = (ZNet.ResultInfo result) => { string str_msg = "Msg : "; str_msg += result.msg; Console.WriteLine(str_msg); }; }