// Path: src/main/java/com/simsilica/net/ChatSession.java
// public interface ChatSession {
// 
//     /**
//      *  Sends a new message to the chat.
//      */
//     @Asynchronous
//     public void sendMessage( String message );
// 
//     /**
//      *  Returns the list of players currently in the chat.
//      */
//     public List<String> getPlayerNames();        
// }
// 
// Path: src/main/java/com/simsilica/net/ChatSessionListener.java
// public interface ChatSessionListener {
//     
//     /**
//      *  Called when a new player has joined the chat.
//      */
//     @Asynchronous   
//     public void playerJoined( int clientId, String playerName );
//  
//     /**
//      *  Called when a player has sent a message to the chat.
//      */
//     @Asynchronous   
//     public void newMessage( int clientId, String playerName, String message );
//     
//     /**
//      *  Called when an existing player has left the chat.
//      */   
//     @Asynchronous   
//     public void playerLeft( int clientId, String playerName );
//     
// }


import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.slf4j.*;
import com.jme3.network.MessageConnection;
import com.jme3.network.service.AbstractClientService;
import com.jme3.network.service.ClientServiceManager;
import com.jme3.network.service.rmi.RmiClientService;
import com.simsilica.net.ChatSession;
import com.simsilica.net.ChatSessionListener;

/*
 * $Id$
 * 
 * Copyright (c) 2016, Simsilica, LLC
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions 
 * are met:
 * 
 * 1. Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright 
 *    notice, this list of conditions and the following disclaimer in 
 *    the documentation and/or other materials provided with the 
 *    distribution.
 * 
 * 3. Neither the name of the copyright holder nor the names of its 
 *    contributors may be used to endorse or promote products derived 
 *    from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.simsilica.net.client;





/**
 *  Client-side service providing access to the chat server.
 *  Register this with the SpiderMonkey Client's services to
 *  get chat service features.
 *
 *  @author    Paul Speed
 */
public class ChatClientService extends AbstractClientService 
                                  implements ChatSession {

    static Logger log = LoggerFactory.getLogger(ChatClientService.class);
    
    private RmiClientService rmiService;
    private int channel;
    private ChatSession delegate;
    
    private String playerName;

    private ChatSessionCallback sessionCallback = new ChatSessionCallback();
    private List<ChatSessionListener> listeners = new CopyOnWriteArrayList<>();  
 
    /**
     *  Creates a new chat service that will use the default reliable
     *  channel for communication.
     */   
    public ChatClientService() {
        this(MessageConnection.CHANNEL_DEFAULT_RELIABLE);
    }
 
    /**
     *  Creates a new chat service that will use the specified channel
     *  for any reliable communication.
     */   
    public ChatClientService( int channel ) {
        this.channel = channel;
    }

    @Override
    public void sendMessage( String message ) {
        getDelegate().sendMessage(message);
    }

    @Override

// Path: src/main/java/com/simsilica/net/ChatSession.java
// public interface ChatSession {
// 
//     /**
//      *  Sends a new message to the chat.
//      */
//     @Asynchronous
//     public void sendMessage( String message );
// 
//     /**
//      *  Returns the list of players currently in the chat.
//      */
//     public List<String> getPlayerNames();        
// }
// 
// Path: src/main/java/com/simsilica/net/ChatSessionListener.java
// public interface ChatSessionListener {
//     
//     /**
//      *  Called when a new player has joined the chat.
//      */
//     @Asynchronous   
//     public void playerJoined( int clientId, String playerName );
//  
//     /**
//      *  Called when a player has sent a message to the chat.
//      */
//     @Asynchronous   
//     public void newMessage( int clientId, String playerName, String message );
//     
//     /**
//      *  Called when an existing player has left the chat.
//      */   
//     @Asynchronous   
//     public void playerLeft( int clientId, String playerName );
//     
// }


// Path: src/main/java/com/simsilica/net/client/ChatClientService.java
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import org.slf4j.*;
import com.jme3.network.MessageConnection;
import com.jme3.network.service.AbstractClientService;
import com.jme3.network.service.ClientServiceManager;
import com.jme3.network.service.rmi.RmiClientService;
import com.simsilica.net.ChatSession;
import com.simsilica.net.ChatSessionListener;

/*
 * $Id$
 * 
 * Copyright (c) 2016, Simsilica, LLC
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions 
 * are met:
 * 
 * 1. Redistributions of source code must retain the above copyright 
 *    notice, this list of conditions and the following disclaimer.
 * 
 * 2. Redistributions in binary form must reproduce the above copyright 
 *    notice, this list of conditions and the following disclaimer in 
 *    the documentation and/or other materials provided with the 
 *    distribution.
 * 
 * 3. Neither the name of the copyright holder nor the names of its 
 *    contributors may be used to endorse or promote products derived 
 *    from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 
 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package com.simsilica.net.client;





/**
 *  Client-side service providing access to the chat server.
 *  Register this with the SpiderMonkey Client's services to
 *  get chat service features.
 *
 *  @author    Paul Speed
 */
public class ChatClientService extends AbstractClientService 
                                  implements ChatSession {

    static Logger log = LoggerFactory.getLogger(ChatClientService.class);
    
    private RmiClientService rmiService;
    private int channel;
    private ChatSession delegate;
    
    private String playerName;

    private ChatSessionCallback sessionCallback = new ChatSessionCallback();
    private List<ChatSessionListener> listeners = new CopyOnWriteArrayList<>();  
 
    /**
     *  Creates a new chat service that will use the default reliable
     *  channel for communication.
     */   
    public ChatClientService() {
        this(MessageConnection.CHANNEL_DEFAULT_RELIABLE);
    }
 
    /**
     *  Creates a new chat service that will use the specified channel
     *  for any reliable communication.
     */   
    public ChatClientService( int channel ) {
        this.channel = channel;
    }

    @Override
    public void sendMessage( String message ) {
        getDelegate().sendMessage(message);
    }

    @Override

    public List<String> getPlayerNames() {
