Source code: marauroa/net/MessageS2CServerInfo.java
1 /* $Id: MessageS2CServerInfo.java,v 1.1 2003/12/08 15:38:54 arianne_rpg Exp $ */
2 /***************************************************************************
3 * (C) Copyright 2003 - Marauroa *
4 ***************************************************************************
5 ***************************************************************************
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 ***************************************************************************/
13 package marauroa.net;
14
15 import java.net.InetSocketAddress;
16 import java.io.*;
17
18 /** The CharacterListMessage is sent from server to client to inform client about
19 * any relevant info the server has to transmit. They are in the form of
20 * <attribute>=<value> */
21 public class MessageS2CServerInfo extends Message
22 {
23 private String[] contents;
24
25 /** Constructor for allowing creation of an empty message */
26 public MessageS2CServerInfo()
27 {
28 super(null);
29
30 type=TYPE_S2C_SERVERINFO;
31 }
32
33 /** Constructor with a TCP/IP source/destination of the message and the name
34 * of the choosen character.
35 * @param source The TCP/IP address associated to this message
36 * @param contents the list of strings to describe the server.
37 * @see marauroa.net.MessageS2CCharacters
38 */
39 public MessageS2CServerInfo(InetSocketAddress source,String[] contents)
40 {
41 super(source);
42
43 type=TYPE_S2C_SERVERINFO;
44 this.contents=contents;
45 }
46
47 /** This method returns the list of string that describe the server
48 * @return the list of strings to describe the server */
49 public String[] getContents()
50 {
51 return contents;
52 }
53
54 /** This method returns a String that represent the object
55 * @return a string representing the object.*/
56 public String toString()
57 {
58 StringBuffer text=new StringBuffer(" ");
59 for(int i=0;i<contents.length;++i)
60 {
61 text.append("["+contents[i]+"],");
62 }
63
64 return "Message (S2C Server Info) from ("+source.toString()+") CONTENTS: ("+text.substring(0,text.length()-1)+")";
65 }
66
67 public void writeObject(marauroa.net.OutputSerializer out) throws IOException
68 {
69 super.writeObject(out);
70 out.write(contents);
71 }
72
73 public void readObject(marauroa.net.InputSerializer in) throws IOException, java.lang.ClassNotFoundException
74 {
75 super.readObject(in);
76 contents=in.readStringArray();
77
78 if(type!=TYPE_S2C_SERVERINFO)
79 {
80 throw new java.lang.ClassNotFoundException();
81 }
82 }
83 };
84